| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/surfaces/surface_aggregator.h" | 5 #include "cc/surfaces/surface_aggregator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 namespace cc { | 37 namespace cc { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 SurfaceId InvalidSurfaceId() { | 40 SurfaceId InvalidSurfaceId() { |
| 41 static SurfaceId invalid; | 41 static SurfaceId invalid; |
| 42 invalid.id = static_cast<uint64_t>(-1); | 42 invalid.id = static_cast<uint64_t>(-1); |
| 43 return invalid; | 43 return invalid; |
| 44 } | 44 } |
| 45 | 45 |
| 46 gfx::Size SurfaceSize() { | 46 gfx::Size SurfaceSize() { |
| 47 static gfx::Size size(5, 5); | 47 static gfx::Size size(100, 100); |
| 48 return size; | 48 return size; |
| 49 } | 49 } |
| 50 | 50 |
| 51 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 51 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
| 52 public: | 52 public: |
| 53 void ReturnResources(const ReturnedResourceArray& resources) override {} | 53 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| 54 | 54 |
| 55 void WillDrawSurface(SurfaceId id, const gfx::Rect& damage_rect) override { | 55 void WillDrawSurface(SurfaceId id, const gfx::Rect& damage_rect) override { |
| 56 last_surface_id_ = id; | 56 last_surface_id_ = id; |
| 57 last_damage_rect_ = damage_rect; | 57 last_damage_rect_ = damage_rect; |
| (...skipping 1568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 ASSERT_TRUE(aggregated_frame); | 1626 ASSERT_TRUE(aggregated_frame); |
| 1627 ASSERT_TRUE(aggregated_frame->delegated_frame_data); | 1627 ASSERT_TRUE(aggregated_frame->delegated_frame_data); |
| 1628 | 1628 |
| 1629 DelegatedFrameData* frame_data = aggregated_frame->delegated_frame_data.get(); | 1629 DelegatedFrameData* frame_data = aggregated_frame->delegated_frame_data.get(); |
| 1630 | 1630 |
| 1631 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list; | 1631 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list; |
| 1632 | 1632 |
| 1633 ASSERT_EQ(3u, aggregated_pass_list.size()); | 1633 ASSERT_EQ(3u, aggregated_pass_list.size()); |
| 1634 | 1634 |
| 1635 // Damage rect for first aggregation should contain entire root surface. | 1635 // Damage rect for first aggregation should contain entire root surface. |
| 1636 EXPECT_EQ(gfx::Rect(0, 0, 15, 15), aggregated_pass_list[2]->damage_rect); | 1636 EXPECT_EQ(gfx::Rect(SurfaceSize()), aggregated_pass_list[2]->damage_rect); |
| 1637 EXPECT_EQ(1u, aggregated_pass_list[0]->quad_list.size()); | 1637 EXPECT_EQ(1u, aggregated_pass_list[0]->quad_list.size()); |
| 1638 EXPECT_EQ(1u, aggregated_pass_list[1]->quad_list.size()); | 1638 EXPECT_EQ(1u, aggregated_pass_list[1]->quad_list.size()); |
| 1639 EXPECT_EQ(1u, aggregated_pass_list[2]->quad_list.size()); | 1639 EXPECT_EQ(1u, aggregated_pass_list[2]->quad_list.size()); |
| 1640 | 1640 |
| 1641 // Create a root surface with a smaller damage rect. | 1641 // Create a root surface with a smaller damage rect. |
| 1642 { | 1642 { |
| 1643 test::Quad root_quads[] = {test::Quad::SurfaceQuad(child_surface_id, 1.f)}; | 1643 test::Quad root_quads[] = {test::Quad::SurfaceQuad(child_surface_id, 1.f)}; |
| 1644 | 1644 |
| 1645 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; | 1645 test::Pass root_passes[] = {test::Pass(root_quads, arraysize(root_quads))}; |
| 1646 | 1646 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1675 EXPECT_EQ(0u, aggregated_pass_list[0]->quad_list.size()); | 1675 EXPECT_EQ(0u, aggregated_pass_list[0]->quad_list.size()); |
| 1676 EXPECT_EQ(1u, aggregated_pass_list[1]->quad_list.size()); | 1676 EXPECT_EQ(1u, aggregated_pass_list[1]->quad_list.size()); |
| 1677 EXPECT_EQ(gfx::Rect(0, 0, 2, 2), | 1677 EXPECT_EQ(gfx::Rect(0, 0, 2, 2), |
| 1678 aggregated_pass_list[1]->quad_list.back()->visible_rect); | 1678 aggregated_pass_list[1]->quad_list.back()->visible_rect); |
| 1679 EXPECT_EQ(1u, aggregated_pass_list[2]->quad_list.size()); | 1679 EXPECT_EQ(1u, aggregated_pass_list[2]->quad_list.size()); |
| 1680 } | 1680 } |
| 1681 | 1681 |
| 1682 // New child frame has same content and no damage, but has a | 1682 // New child frame has same content and no damage, but has a |
| 1683 // CopyOutputRequest. | 1683 // CopyOutputRequest. |
| 1684 { | 1684 { |
| 1685 RenderPassId child_pass_id = RenderPassId(1, 1); | 1685 RenderPassId child_pass_ids[] = {RenderPassId(1, 1), RenderPassId(1, 2)}; |
| 1686 test::Quad child_quads1[] = {test::Quad::RenderPassQuad(child_pass_id)}; | 1686 test::Quad child_quads1[] = {test::Quad::SolidColorQuad(1)}; |
| 1687 test::Quad child_quads2[] = {test::Quad::RenderPassQuad(child_pass_id)}; | 1687 test::Quad child_quads2[] = {test::Quad::RenderPassQuad(child_pass_ids[0])}; |
| 1688 test::Pass child_passes[] = { | 1688 test::Pass child_passes[] = { |
| 1689 test::Pass(child_quads1, arraysize(child_quads1), child_pass_id), | 1689 test::Pass(child_quads1, arraysize(child_quads1), child_pass_ids[0]), |
| 1690 test::Pass(child_quads2, arraysize(child_quads2), child_pass_id)}; | 1690 test::Pass(child_quads2, arraysize(child_quads2), child_pass_ids[1])}; |
| 1691 | 1691 |
| 1692 RenderPassList child_pass_list; | 1692 RenderPassList child_pass_list; |
| 1693 AddPasses(&child_pass_list, gfx::Rect(SurfaceSize()), child_passes, | 1693 AddPasses(&child_pass_list, gfx::Rect(SurfaceSize()), child_passes, |
| 1694 arraysize(child_passes)); | 1694 arraysize(child_passes)); |
| 1695 | 1695 |
| 1696 child_pass_list[0]->quad_list.ElementAt(0)->visible_rect = | 1696 child_pass_list[0]->quad_list.ElementAt(0)->visible_rect = |
| 1697 gfx::Rect(1, 1, 2, 2); | 1697 gfx::Rect(1, 1, 2, 2); |
| 1698 SharedQuadState* child_sqs = | 1698 SharedQuadState* child_sqs = |
| 1699 child_pass_list[0]->shared_quad_state_list.ElementAt(0u); | 1699 child_pass_list[0]->shared_quad_state_list.ElementAt(0u); |
| 1700 child_sqs->quad_to_target_transform.Translate(1, 1); | 1700 child_sqs->quad_to_target_transform.Translate(1, 1); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1719 ASSERT_TRUE(aggregated_frame->delegated_frame_data); | 1719 ASSERT_TRUE(aggregated_frame->delegated_frame_data); |
| 1720 | 1720 |
| 1721 DelegatedFrameData* frame_data = | 1721 DelegatedFrameData* frame_data = |
| 1722 aggregated_frame->delegated_frame_data.get(); | 1722 aggregated_frame->delegated_frame_data.get(); |
| 1723 | 1723 |
| 1724 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list; | 1724 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list; |
| 1725 | 1725 |
| 1726 // Output frame should have no damage, but all quads included. | 1726 // Output frame should have no damage, but all quads included. |
| 1727 ASSERT_EQ(3u, aggregated_pass_list.size()); | 1727 ASSERT_EQ(3u, aggregated_pass_list.size()); |
| 1728 | 1728 |
| 1729 EXPECT_TRUE(aggregated_pass_list[1]->damage_rect.IsEmpty()); | 1729 EXPECT_EQ(gfx::Rect(SurfaceSize()), aggregated_pass_list[0]->damage_rect); |
| 1730 EXPECT_EQ(gfx::Rect(SurfaceSize()), aggregated_pass_list[1]->damage_rect); |
| 1731 EXPECT_TRUE(aggregated_pass_list[2]->damage_rect.IsEmpty()); |
| 1730 ASSERT_EQ(1u, aggregated_pass_list[0]->quad_list.size()); | 1732 ASSERT_EQ(1u, aggregated_pass_list[0]->quad_list.size()); |
| 1731 ASSERT_EQ(1u, aggregated_pass_list[1]->quad_list.size()); | 1733 ASSERT_EQ(1u, aggregated_pass_list[1]->quad_list.size()); |
| 1732 EXPECT_EQ(gfx::Rect(1, 1, 2, 2), | 1734 EXPECT_EQ(gfx::Rect(1, 1, 2, 2), |
| 1733 aggregated_pass_list[0]->quad_list.ElementAt(0)->visible_rect); | 1735 aggregated_pass_list[0]->quad_list.ElementAt(0)->visible_rect); |
| 1734 EXPECT_EQ(gfx::Rect(0, 0, 2, 2), | 1736 EXPECT_EQ(gfx::Rect(0, 0, 2, 2), |
| 1735 aggregated_pass_list[1]->quad_list.ElementAt(0)->visible_rect); | 1737 aggregated_pass_list[1]->quad_list.ElementAt(0)->visible_rect); |
| 1736 ASSERT_EQ(1u, aggregated_pass_list[2]->quad_list.size()); | 1738 ASSERT_EQ(1u, aggregated_pass_list[2]->quad_list.size()); |
| 1737 } | 1739 } |
| 1738 | 1740 |
| 1739 { | 1741 { |
| 1740 std::unique_ptr<CompositorFrame> aggregated_frame = | 1742 std::unique_ptr<CompositorFrame> aggregated_frame = |
| 1741 aggregator_.Aggregate(root_surface_id_); | 1743 aggregator_.Aggregate(root_surface_id_); |
| 1742 | 1744 |
| 1743 ASSERT_TRUE(aggregated_frame); | 1745 ASSERT_TRUE(aggregated_frame); |
| 1744 ASSERT_TRUE(aggregated_frame->delegated_frame_data); | 1746 ASSERT_TRUE(aggregated_frame->delegated_frame_data); |
| 1745 | 1747 |
| 1746 DelegatedFrameData* frame_data = | 1748 DelegatedFrameData* frame_data = |
| 1747 aggregated_frame->delegated_frame_data.get(); | 1749 aggregated_frame->delegated_frame_data.get(); |
| 1748 | 1750 |
| 1749 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list; | 1751 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list; |
| 1750 // There were no changes since last aggregation, so output should be empty | 1752 // There were no changes since last aggregation, so output should be empty |
| 1751 // and have no damage. | 1753 // and have no damage. |
| 1752 ASSERT_EQ(1u, aggregated_pass_list.size()); | 1754 ASSERT_EQ(1u, aggregated_pass_list.size()); |
| 1753 EXPECT_TRUE(aggregated_pass_list[0]->damage_rect.IsEmpty()); | 1755 EXPECT_TRUE(aggregated_pass_list[0]->damage_rect.IsEmpty()); |
| 1754 ASSERT_EQ(0u, aggregated_pass_list[0]->quad_list.size()); | 1756 ASSERT_EQ(0u, aggregated_pass_list[0]->quad_list.size()); |
| 1755 } | 1757 } |
| 1756 | 1758 |
| 1759 // Root surface has smaller damage rect, but filter on render pass means all |
| 1760 // of it should be aggregated. |
| 1761 { |
| 1762 RenderPassId root_pass_ids[] = {RenderPassId(1, 1), RenderPassId(1, 2)}; |
| 1763 test::Quad root_quads1[] = {test::Quad::SurfaceQuad(child_surface_id, 1.f)}; |
| 1764 test::Quad root_quads2[] = {test::Quad::RenderPassQuad(root_pass_ids[0])}; |
| 1765 test::Pass root_passes[] = { |
| 1766 test::Pass(root_quads1, arraysize(root_quads1), root_pass_ids[0]), |
| 1767 test::Pass(root_quads2, arraysize(root_quads2), root_pass_ids[1])}; |
| 1768 |
| 1769 RenderPassList root_pass_list; |
| 1770 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes, |
| 1771 arraysize(root_passes)); |
| 1772 |
| 1773 RenderPass* pass = root_pass_list[0].get(); |
| 1774 pass->shared_quad_state_list.front()->quad_to_target_transform.Translate( |
| 1775 10, 10); |
| 1776 RenderPass* root_pass = root_pass_list[1].get(); |
| 1777 RenderPassDrawQuad* quad = |
| 1778 static_cast<RenderPassDrawQuad*>(root_pass->quad_list.front()); |
| 1779 quad->filters.Append(FilterOperation::CreateBlurFilter(2)); |
| 1780 root_pass->damage_rect = gfx::Rect(10, 10, 2, 2); |
| 1781 SubmitPassListAsFrame(root_surface_id_, &root_pass_list); |
| 1782 } |
| 1783 |
| 1784 { |
| 1785 std::unique_ptr<CompositorFrame> aggregated_frame = |
| 1786 aggregator_.Aggregate(root_surface_id_); |
| 1787 |
| 1788 ASSERT_TRUE(aggregated_frame); |
| 1789 ASSERT_TRUE(aggregated_frame->delegated_frame_data); |
| 1790 |
| 1791 DelegatedFrameData* frame_data = |
| 1792 aggregated_frame->delegated_frame_data.get(); |
| 1793 |
| 1794 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list; |
| 1795 |
| 1796 ASSERT_EQ(3u, aggregated_pass_list.size()); |
| 1797 |
| 1798 EXPECT_EQ(gfx::Rect(SurfaceSize()), aggregated_pass_list[0]->damage_rect); |
| 1799 EXPECT_EQ(gfx::Rect(SurfaceSize()), aggregated_pass_list[1]->damage_rect); |
| 1800 EXPECT_EQ(gfx::Rect(10, 10, 2, 2), aggregated_pass_list[2]->damage_rect); |
| 1801 EXPECT_EQ(1u, aggregated_pass_list[0]->quad_list.size()); |
| 1802 EXPECT_EQ(1u, aggregated_pass_list[1]->quad_list.size()); |
| 1803 // First render pass draw quad is outside damage rect, so shouldn't be |
| 1804 // drawn. |
| 1805 EXPECT_EQ(0u, aggregated_pass_list[2]->quad_list.size()); |
| 1806 } |
| 1807 |
| 1808 // Root surface has smaller damage rect. Background filter on render pass |
| 1809 // means Surface |
| 1810 // quad under it should be aggregated. |
| 1811 { |
| 1812 RenderPassId root_pass_ids[] = {RenderPassId(1, 1), RenderPassId(1, 2)}; |
| 1813 test::Quad root_quads1[] = { |
| 1814 test::Quad::SolidColorQuad(1), |
| 1815 }; |
| 1816 test::Quad root_quads2[] = {test::Quad::RenderPassQuad(root_pass_ids[0]), |
| 1817 test::Quad::SurfaceQuad(child_surface_id, 1.f)}; |
| 1818 test::Pass root_passes[] = { |
| 1819 test::Pass(root_quads1, arraysize(root_quads1), root_pass_ids[0]), |
| 1820 test::Pass(root_quads2, arraysize(root_quads2), root_pass_ids[1])}; |
| 1821 |
| 1822 RenderPassList root_pass_list; |
| 1823 AddPasses(&root_pass_list, gfx::Rect(SurfaceSize()), root_passes, |
| 1824 arraysize(root_passes)); |
| 1825 |
| 1826 RenderPass* root_pass = root_pass_list[1].get(); |
| 1827 root_pass->shared_quad_state_list.ElementAt(1) |
| 1828 ->quad_to_target_transform.Translate(10, 10); |
| 1829 RenderPassDrawQuad* quad = |
| 1830 static_cast<RenderPassDrawQuad*>(root_pass->quad_list.front()); |
| 1831 quad->background_filters.Append(FilterOperation::CreateBlurFilter(2)); |
| 1832 root_pass->damage_rect = gfx::Rect(10, 10, 2, 2); |
| 1833 SubmitPassListAsFrame(root_surface_id_, &root_pass_list); |
| 1834 } |
| 1835 |
| 1836 { |
| 1837 std::unique_ptr<CompositorFrame> aggregated_frame = |
| 1838 aggregator_.Aggregate(root_surface_id_); |
| 1839 |
| 1840 ASSERT_TRUE(aggregated_frame); |
| 1841 ASSERT_TRUE(aggregated_frame->delegated_frame_data); |
| 1842 |
| 1843 DelegatedFrameData* frame_data = |
| 1844 aggregated_frame->delegated_frame_data.get(); |
| 1845 |
| 1846 const RenderPassList& aggregated_pass_list = frame_data->render_pass_list; |
| 1847 |
| 1848 ASSERT_EQ(3u, aggregated_pass_list.size()); |
| 1849 |
| 1850 // Pass 0 is solid color quad from root, but outside damage rect. |
| 1851 EXPECT_EQ(gfx::Rect(10, 10, 2, 2), aggregated_pass_list[0]->damage_rect); |
| 1852 EXPECT_EQ(0u, aggregated_pass_list[0]->quad_list.size()); |
| 1853 EXPECT_EQ(gfx::Rect(SurfaceSize()), aggregated_pass_list[1]->damage_rect); |
| 1854 EXPECT_EQ(1u, aggregated_pass_list[1]->quad_list.size()); |
| 1855 |
| 1856 // First render pass draw quad is outside damage rect, so shouldn't be |
| 1857 // drawn. SurfaceDrawQuad is after background filter, so corresponding |
| 1858 // RenderPassDrawQuad should be drawn. |
| 1859 EXPECT_EQ(gfx::Rect(10, 10, 2, 2), aggregated_pass_list[2]->damage_rect); |
| 1860 EXPECT_EQ(1u, aggregated_pass_list[2]->quad_list.size()); |
| 1861 } |
| 1862 |
| 1757 factory_.Destroy(child_surface_id); | 1863 factory_.Destroy(child_surface_id); |
| 1758 } | 1864 } |
| 1759 | 1865 |
| 1760 class SurfaceAggregatorWithResourcesTest : public testing::Test { | 1866 class SurfaceAggregatorWithResourcesTest : public testing::Test { |
| 1761 public: | 1867 public: |
| 1762 void SetUp() override { | 1868 void SetUp() override { |
| 1763 output_surface_ = FakeOutputSurface::CreateSoftware( | 1869 output_surface_ = FakeOutputSurface::CreateSoftware( |
| 1764 base::WrapUnique(new SoftwareOutputDevice)); | 1870 base::WrapUnique(new SoftwareOutputDevice)); |
| 1765 output_surface_->BindToClient(&output_surface_client_); | 1871 output_surface_->BindToClient(&output_surface_client_); |
| 1766 shared_bitmap_manager_.reset(new TestSharedBitmapManager); | 1872 shared_bitmap_manager_.reset(new TestSharedBitmapManager); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2000 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); | 2106 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); |
| 2001 | 2107 |
| 2002 factory.Destroy(root_surface_id); | 2108 factory.Destroy(root_surface_id); |
| 2003 factory.Destroy(child_surface_id); | 2109 factory.Destroy(child_surface_id); |
| 2004 factory.Destroy(middle_surface_id); | 2110 factory.Destroy(middle_surface_id); |
| 2005 } | 2111 } |
| 2006 | 2112 |
| 2007 } // namespace | 2113 } // namespace |
| 2008 } // namespace cc | 2114 } // namespace cc |
| 2009 | 2115 |
| OLD | NEW |