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

Side by Side Diff: cc/trees/layer_tree_host_unittest_context.cc

Issue 18191020: UI Resource Manager (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 4 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
OLDNEW
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/layers/content_layer.h" 8 #include "cc/layers/content_layer.h"
9 #include "cc/layers/heads_up_display_layer.h" 9 #include "cc/layers/heads_up_display_layer.h"
10 #include "cc/layers/io_surface_layer.h" 10 #include "cc/layers/io_surface_layer.h"
11 #include "cc/layers/layer_impl.h" 11 #include "cc/layers/layer_impl.h"
12 #include "cc/layers/picture_layer.h" 12 #include "cc/layers/picture_layer.h"
13 #include "cc/layers/scrollbar_layer.h" 13 #include "cc/layers/scrollbar_layer.h"
14 #include "cc/layers/texture_layer.h" 14 #include "cc/layers/texture_layer.h"
15 #include "cc/layers/texture_layer_impl.h" 15 #include "cc/layers/texture_layer_impl.h"
16 #include "cc/layers/video_layer.h" 16 #include "cc/layers/video_layer.h"
17 #include "cc/layers/video_layer_impl.h" 17 #include "cc/layers/video_layer_impl.h"
18 #include "cc/output/filter_operations.h" 18 #include "cc/output/filter_operations.h"
19 #include "cc/test/fake_content_layer.h" 19 #include "cc/test/fake_content_layer.h"
20 #include "cc/test/fake_content_layer_client.h" 20 #include "cc/test/fake_content_layer_client.h"
21 #include "cc/test/fake_content_layer_impl.h" 21 #include "cc/test/fake_content_layer_impl.h"
22 #include "cc/test/fake_context_provider.h" 22 #include "cc/test/fake_context_provider.h"
23 #include "cc/test/fake_delegated_renderer_layer.h" 23 #include "cc/test/fake_delegated_renderer_layer.h"
24 #include "cc/test/fake_delegated_renderer_layer_impl.h" 24 #include "cc/test/fake_delegated_renderer_layer_impl.h"
25 #include "cc/test/fake_layer_tree_host_client.h" 25 #include "cc/test/fake_layer_tree_host_client.h"
26 #include "cc/test/fake_output_surface.h" 26 #include "cc/test/fake_output_surface.h"
27 #include "cc/test/fake_scoped_ui_resource.h"
27 #include "cc/test/fake_scrollbar.h" 28 #include "cc/test/fake_scrollbar.h"
28 #include "cc/test/fake_scrollbar_layer.h" 29 #include "cc/test/fake_scrollbar_layer.h"
29 #include "cc/test/fake_video_frame_provider.h" 30 #include "cc/test/fake_video_frame_provider.h"
30 #include "cc/test/layer_tree_test.h" 31 #include "cc/test/layer_tree_test.h"
31 #include "cc/test/render_pass_test_common.h" 32 #include "cc/test/render_pass_test_common.h"
32 #include "cc/test/test_web_graphics_context_3d.h" 33 #include "cc/test/test_web_graphics_context_3d.h"
33 #include "cc/trees/layer_tree_host_impl.h" 34 #include "cc/trees/layer_tree_host_impl.h"
34 #include "cc/trees/layer_tree_impl.h" 35 #include "cc/trees/layer_tree_impl.h"
35 #include "cc/trees/single_thread_proxy.h" 36 #include "cc/trees/single_thread_proxy.h"
36 #include "gpu/GLES2/gl2extchromium.h" 37 #include "gpu/GLES2/gl2extchromium.h"
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 layer_tree_host()->root_layer()->AddChild(scroll_layer); 1495 layer_tree_host()->root_layer()->AddChild(scroll_layer);
1495 PostSetNeedsCommitToMainThread(); 1496 PostSetNeedsCommitToMainThread();
1496 } 1497 }
1497 1498
1498 virtual void AfterTest() OVERRIDE {} 1499 virtual void AfterTest() OVERRIDE {}
1499 1500
1500 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1501 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1501 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1502 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1502 1503
1503 ++commits_; 1504 ++commits_;
1504 size_t upload_count = scrollbar_layer_->last_update_full_upload_size() +
1505 scrollbar_layer_->last_update_partial_upload_size();
1506 switch (commits_) { 1505 switch (commits_) {
1507 case 1: 1506 case 1:
1508 // First (regular) update, we should upload 2 resources (thumb, and 1507 // First (regular) update, we should upload 2 resources (thumb, and
1509 // backtrack). 1508 // backtrack).
1510 EXPECT_EQ(1, scrollbar_layer_->update_count()); 1509 EXPECT_EQ(1, scrollbar_layer_->update_count());
1511 EXPECT_EQ(2u, upload_count);
1512 LoseContext(); 1510 LoseContext();
1513 break; 1511 break;
1514 case 2: 1512 case 2:
1515 // Second update, after the lost context, we should still upload 2 1513 // Second update, after the lost context, we should still upload 2
1516 // resources even if the contents haven't changed. 1514 // resources even if the contents haven't changed.
1517 EXPECT_EQ(2, scrollbar_layer_->update_count()); 1515 EXPECT_EQ(2, scrollbar_layer_->update_count());
1518 EXPECT_EQ(2u, upload_count);
1519 EndTest(); 1516 EndTest();
1520 break; 1517 break;
1521 default: 1518 default:
1522 NOTREACHED(); 1519 NOTREACHED();
1523 } 1520 }
1524 } 1521 }
1525 1522
1526 private: 1523 private:
1527 int commits_; 1524 int commits_;
1528 scoped_refptr<FakeScrollbarLayer> scrollbar_layer_; 1525 scoped_refptr<FakeScrollbarLayer> scrollbar_layer_;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 this, 1592 this,
1596 settings, 1593 settings,
1597 impl_thread ? impl_thread->message_loop_proxy() : NULL); 1594 impl_thread ? impl_thread->message_loop_proxy() : NULL);
1598 EXPECT_FALSE(layer_tree_host); 1595 EXPECT_FALSE(layer_tree_host);
1599 } 1596 }
1600 }; 1597 };
1601 1598
1602 SINGLE_AND_MULTI_THREAD_TEST_F( 1599 SINGLE_AND_MULTI_THREAD_TEST_F(
1603 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface); 1600 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface);
1604 1601
1602 class UIResourceLostTest : public LayerTreeHostContextTest {
1603 public:
1604 UIResourceLostTest() : time_step_(0) {
1605 ui_resource_ = FakeScopedUIResource::Create();
1606 }
1607 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
1608 virtual void AfterTest() OVERRIDE {}
1609
1610 protected:
1611 int time_step_;
1612 scoped_refptr<FakeScopedUIResource> ui_resource_;
1613 };
1614
1615 // Losing context after an UI resource has been created.
1616 class UIResourceLostAfterCommit : public UIResourceLostTest {
1617 public:
1618 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1619 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1620 switch (time_step_) {
1621 case 0:
1622 ui_resource_->CreateResource(layer_tree_host());
1623 // Expects a valid UIResourceId.
1624 EXPECT_NE(0, ui_resource_->id());
1625 PostSetNeedsCommitToMainThread();
1626 break;
1627 case 1:
1628 // The resource should have been created on LTHI after the commit.
1629 if (!layer_tree_host()->settings().impl_side_painting)
1630 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1631 PostSetNeedsCommitToMainThread();
1632 break;
1633 case 2:
1634 LoseContext();
1635 // Resource Id on the impl-side should no longer be valid after
1636 // context is lost.
1637 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1638 break;
1639 case 3:
1640 // The resources should have been recreated. The bitmap callback should
1641 // have been called once with the resource_lost flag set to true.
1642 EXPECT_EQ(1, ui_resource_->lost_resource_count);
1643 // Resource Id on the impl-side have been recreated as well. Note
1644 // that the same UIResourceId persists after the context lost.
1645 if (!layer_tree_host()->settings().impl_side_painting)
1646 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1647 PostSetNeedsCommitToMainThread();
1648 break;
1649 case 4:
1650 // Release resource before ending test.
1651 ui_resource_->ReleaseResource(layer_tree_host());
1652 EndTest();
1653 break;
1654 }
1655 }
1656
1657 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1658 LayerTreeHostContextTest::DidActivateTreeOnThread(impl);
1659 switch (time_step_) {
1660 case 1:
1661 if (layer_tree_host()->settings().impl_side_painting)
1662 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1663 break;
1664 case 3:
1665 if (layer_tree_host()->settings().impl_side_painting)
1666 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1667 break;
1668 }
1669 ++time_step_;
1670 }
1671 };
1672
1673 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostAfterCommit);
1674
1675 // Losing context before UI resource requests can be commited. Three sequences
1676 // of creation/deletion are considered:
1677 // 1. Create one resource -> Context Lost => Expect the resource to have been
1678 // created.
1679 // 2. Delete an exisiting resource (test_id0_) -> create a second resource
1680 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and
1681 // test_id1_ to have been created.
1682 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect
1683 // the resource to not exist in the manager.
1684 class UIResourceLostBeforeCommit : public UIResourceLostTest {
1685 public:
1686 UIResourceLostBeforeCommit()
1687 : test_id0_(0),
1688 test_id1_(0) {}
1689
1690 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1691 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1692 switch (time_step_) {
1693 case 0:
1694 // Sequence 1:
1695 ui_resource_->CreateResource(layer_tree_host());
1696 LoseContext();
1697 // Resource Id on the impl-side should no longer be valid after
1698 // context is lost.
1699 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1700 break;
1701 case 1:
1702 // The resources should have been recreated.
1703 EXPECT_EQ(1, ui_resource_->resource_create_count);
1704 // No "resource lost" callback was called since the context lost
1705 // happened before commit.
1706 EXPECT_EQ(0, ui_resource_->lost_resource_count);
1707 // Resource Id on the impl-side have been recreated as well. Note
1708 // that the same UIResourceId persists after the context lost.
1709 if (!layer_tree_host()->settings().impl_side_painting)
1710 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1711 ui_resource_->ResetCounters();
1712 PostSetNeedsCommitToMainThread();
1713 break;
1714 case 2:
1715 // Sequence 2:
1716 // Currently one resource has been created.
1717 test_id0_ = ui_resource_->id();
1718 // Delete this resource.
1719 ui_resource_->DeleteResource(layer_tree_host());
1720 // Create another resource.
1721 ui_resource_->CreateResource(layer_tree_host());
1722 test_id1_ = ui_resource_->id();
1723 // Sanity check that two resource creations return different ids.
1724 EXPECT_NE(test_id0_, test_id1_);
1725 // Lose the context before commit.
1726 LoseContext();
1727 break;
1728 case 3:
1729 if (!layer_tree_host()->settings().impl_side_painting) {
1730 // The previous resource should have been deleted.
1731 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_));
1732 // The second resource should have been created.
1733 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_));
1734 }
1735
1736 // The second resource called the resource callback once. Since the
1737 // context lost happened before commit, the callback was not a "resource
1738 // lost" call.
1739 EXPECT_EQ(1, ui_resource_->resource_create_count);
1740 EXPECT_EQ(0, ui_resource_->lost_resource_count);
1741 // Clear the manager of resources.
1742 ui_resource_->DeleteResource(layer_tree_host());
1743 ui_resource_->ResetCounters();
1744 PostSetNeedsCommitToMainThread();
1745 break;
1746 case 4:
1747 // Sequence 3:
1748 ui_resource_->CreateResource(layer_tree_host());
1749 test_id0_ = ui_resource_->id();
1750 // Sanity check the UIResourceId should not be 0.
1751 EXPECT_NE(0, test_id0_);
1752
1753 ui_resource_->DeleteResource(layer_tree_host());
1754 LoseContext();
1755 break;
1756 case 5:
1757 // Expect the resource callback to have been called once.
1758 EXPECT_EQ(1, ui_resource_->resource_create_count);
1759 // No "resource lost" callbacks.
1760 EXPECT_EQ(0, ui_resource_->lost_resource_count);
1761 if (!layer_tree_host()->settings().impl_side_painting) {
1762 // The UI resource id should not be valid
1763 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_));
1764 }
1765 PostSetNeedsCommitToMainThread();
1766 break;
1767 case 6:
1768 EndTest();
1769 break;
1770 }
1771 }
1772
1773 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1774 LayerTreeHostContextTest::DidActivateTreeOnThread(impl);
1775 switch (time_step_) {
1776 case 1:
1777 if (layer_tree_host()->settings().impl_side_painting)
1778 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1779 break;
1780 case 3:
1781 if (layer_tree_host()->settings().impl_side_painting) {
1782 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_));
1783 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_));
1784 }
1785 break;
1786 case 5:
1787 if (layer_tree_host()->settings().impl_side_painting)
1788 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_));
1789 break;
1790 }
1791 ++time_step_;
1792 }
1793
1794 private:
1795 UIResourceId test_id0_;
1796 UIResourceId test_id1_;
1797 };
1798
1799 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit);
1800
1801 // Losing UI resource before the pending trees is activated but after the
1802 // commit. Impl-side-painting only.
1803 class UIResourceLostBeforeActivateTree : public UIResourceLostTest {
1804 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1805 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1806 switch (time_step_) {
1807 case 0:
1808 ui_resource_->CreateResource(layer_tree_host());
1809 PostSetNeedsCommitToMainThread();
1810 break;
1811 case 2:
1812 PostSetNeedsCommitToMainThread();
1813 break;
1814 case 3:
1815 ui_resource_->DeleteResource(layer_tree_host());
1816 PostSetNeedsCommitToMainThread();
1817 break;
1818 case 4:
1819 PostSetNeedsCommitToMainThread();
1820 break;
1821 case 5:
1822 EndTest();
1823 break;
1824 }
1825 }
1826
1827 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1828 switch (time_step_) {
1829 case 0:
1830 break;
1831 case 1:
1832 // The resource creation callback has been called.
1833 EXPECT_EQ(1, ui_resource_->resource_create_count);
1834 // The resource is not yet lost (sanity check).
1835 EXPECT_EQ(0, ui_resource_->lost_resource_count);
1836 // The resource should not have been created yet on the impl-side.
1837 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1838 LoseContext();
1839 break;
1840 case 3:
1841 LoseContext();
1842 break;
1843 }
1844 }
1845
1846 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1847 LayerTreeHostContextTest::DidActivateTreeOnThread(impl);
1848 switch (time_step_) {
1849 case 1:
1850 // The pending requests on the impl-side should have been removed, and
1851 // so the resource should still not have been created.
1852 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1853 break;
1854 case 2:
1855 // The resource should have been created.
1856 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1857 // The "lost resource" callback has been called once.
1858 EXPECT_EQ(1, ui_resource_->lost_resource_count);
1859 break;
1860 case 3:
1861 // The resource is deleted and should not be in the manager.
1862 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id()));
1863 break;
1864 }
1865 ++time_step_;
1866 }
1867 };
1868
1869 TEST_F(UIResourceLostBeforeActivateTree,
1870 RunMultiThread_DirectRenderer_ImplSidePaint) {
1871 RunTest(true, false, true);
1872 }
1873
1874 TEST_F(UIResourceLostBeforeActivateTree,
1875 RunMultiThread_DelegatingRenderer_ImplSidePaint) {
1876 RunTest(true, true, true);
1877 }
1878
1605 } // namespace 1879 } // namespace
1606 } // namespace cc 1880 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698