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 18 matching lines...) Expand all Loading... |
29 #include "cc/test/test_shared_bitmap_manager.h" | 29 #include "cc/test/test_shared_bitmap_manager.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "third_party/skia/include/core/SkColor.h" | 32 #include "third_party/skia/include/core/SkColor.h" |
33 | 33 |
34 namespace cc { | 34 namespace cc { |
35 namespace { | 35 namespace { |
36 | 36 |
37 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); | 37 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); |
38 static constexpr FrameSinkId kArbitraryChildFrameSinkId(2, 2); | 38 static constexpr FrameSinkId kArbitraryChildFrameSinkId(2, 2); |
| 39 static const base::UnguessableToken kArbitraryToken = |
| 40 base::UnguessableToken::Create(); |
39 | 41 |
40 SurfaceId InvalidSurfaceId() { | 42 SurfaceId InvalidSurfaceId() { |
41 static SurfaceId invalid(kArbitraryFrameSinkId, LocalFrameId(0xdeadbeef, 0)); | 43 static SurfaceId invalid(kArbitraryFrameSinkId, |
| 44 LocalFrameId(0xdeadbeef, kArbitraryToken)); |
42 return invalid; | 45 return invalid; |
43 } | 46 } |
44 | 47 |
45 gfx::Size SurfaceSize() { | 48 gfx::Size SurfaceSize() { |
46 static gfx::Size size(100, 100); | 49 static gfx::Size size(100, 100); |
47 return size; | 50 return size; |
48 } | 51 } |
49 | 52 |
50 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 53 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
51 public: | 54 public: |
(...skipping 20 matching lines...) Expand all Loading... |
72 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} | 75 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} |
73 | 76 |
74 protected: | 77 protected: |
75 SurfaceManager manager_; | 78 SurfaceManager manager_; |
76 EmptySurfaceFactoryClient empty_client_; | 79 EmptySurfaceFactoryClient empty_client_; |
77 SurfaceFactory factory_; | 80 SurfaceFactory factory_; |
78 SurfaceAggregator aggregator_; | 81 SurfaceAggregator aggregator_; |
79 }; | 82 }; |
80 | 83 |
81 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { | 84 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { |
82 LocalFrameId local_frame_id(7, 0); | 85 LocalFrameId local_frame_id(7, base::UnguessableToken::Create()); |
83 SurfaceId one_id(kArbitraryFrameSinkId, local_frame_id); | 86 SurfaceId one_id(kArbitraryFrameSinkId, local_frame_id); |
84 factory_.Create(local_frame_id); | 87 factory_.Create(local_frame_id); |
85 | 88 |
86 CompositorFrame frame = aggregator_.Aggregate(one_id); | 89 CompositorFrame frame = aggregator_.Aggregate(one_id); |
87 EXPECT_TRUE(frame.render_pass_list.empty()); | 90 EXPECT_TRUE(frame.render_pass_list.empty()); |
88 | 91 |
89 factory_.Destroy(local_frame_id); | 92 factory_.Destroy(local_frame_id); |
90 } | 93 } |
91 | 94 |
92 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { | 95 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { |
(...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1786 nearest_neighbor, secure_output_only); | 1789 nearest_neighbor, secure_output_only); |
1787 } | 1790 } |
1788 frame.render_pass_list.push_back(std::move(pass)); | 1791 frame.render_pass_list.push_back(std::move(pass)); |
1789 factory->SubmitCompositorFrame(surface_id.local_frame_id(), std::move(frame), | 1792 factory->SubmitCompositorFrame(surface_id.local_frame_id(), std::move(frame), |
1790 SurfaceFactory::DrawCallback()); | 1793 SurfaceFactory::DrawCallback()); |
1791 } | 1794 } |
1792 | 1795 |
1793 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { | 1796 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { |
1794 ResourceTrackingSurfaceFactoryClient client; | 1797 ResourceTrackingSurfaceFactoryClient client; |
1795 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); | 1798 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); |
1796 LocalFrameId local_frame_id(7u, 0); | 1799 LocalFrameId local_frame_id(7u, base::UnguessableToken::Create()); |
1797 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); | 1800 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); |
1798 factory.Create(local_frame_id); | 1801 factory.Create(local_frame_id); |
1799 | 1802 |
1800 ResourceId ids[] = {11, 12, 13}; | 1803 ResourceId ids[] = {11, 12, 13}; |
1801 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1804 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
1802 &factory, surface_id); | 1805 &factory, surface_id); |
1803 | 1806 |
1804 CompositorFrame frame = aggregator_->Aggregate(surface_id); | 1807 CompositorFrame frame = aggregator_->Aggregate(surface_id); |
1805 | 1808 |
1806 // Nothing should be available to be returned yet. | 1809 // Nothing should be available to be returned yet. |
(...skipping 10 matching lines...) Expand all Loading... |
1817 returned_ids[i] = client.returned_resources()[i].id; | 1820 returned_ids[i] = client.returned_resources()[i].id; |
1818 } | 1821 } |
1819 EXPECT_THAT(returned_ids, | 1822 EXPECT_THAT(returned_ids, |
1820 testing::WhenSorted(testing::ElementsAreArray(ids))); | 1823 testing::WhenSorted(testing::ElementsAreArray(ids))); |
1821 factory.Destroy(local_frame_id); | 1824 factory.Destroy(local_frame_id); |
1822 } | 1825 } |
1823 | 1826 |
1824 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { | 1827 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { |
1825 ResourceTrackingSurfaceFactoryClient client; | 1828 ResourceTrackingSurfaceFactoryClient client; |
1826 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); | 1829 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); |
1827 LocalFrameId local_frame_id(7u, 0); | 1830 LocalFrameId local_frame_id(7u, base::UnguessableToken::Create()); |
1828 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); | 1831 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); |
1829 factory.Create(local_frame_id); | 1832 factory.Create(local_frame_id); |
1830 | 1833 |
1831 CompositorFrame frame; | 1834 CompositorFrame frame; |
1832 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 1835 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
1833 pass->id = RenderPassId(1, 1); | 1836 pass->id = RenderPassId(1, 1); |
1834 TransferableResource resource; | 1837 TransferableResource resource; |
1835 resource.id = 11; | 1838 resource.id = 11; |
1836 // ResourceProvider is software but resource is not, so it should be | 1839 // ResourceProvider is software but resource is not, so it should be |
1837 // ignored. | 1840 // ignored. |
(...skipping 12 matching lines...) Expand all Loading... |
1850 surface_id); | 1853 surface_id); |
1851 ASSERT_EQ(1u, client.returned_resources().size()); | 1854 ASSERT_EQ(1u, client.returned_resources().size()); |
1852 EXPECT_EQ(11u, client.returned_resources()[0].id); | 1855 EXPECT_EQ(11u, client.returned_resources()[0].id); |
1853 | 1856 |
1854 factory.Destroy(local_frame_id); | 1857 factory.Destroy(local_frame_id); |
1855 } | 1858 } |
1856 | 1859 |
1857 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { | 1860 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { |
1858 ResourceTrackingSurfaceFactoryClient client; | 1861 ResourceTrackingSurfaceFactoryClient client; |
1859 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); | 1862 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); |
1860 LocalFrameId local_frame1_id(7u, 0); | 1863 LocalFrameId local_frame1_id(7u, base::UnguessableToken::Create()); |
1861 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id); | 1864 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id); |
1862 factory.Create(local_frame1_id); | 1865 factory.Create(local_frame1_id); |
1863 | 1866 |
1864 LocalFrameId local_frame2_id(8u, 0); | 1867 LocalFrameId local_frame2_id(8u, base::UnguessableToken::Create()); |
1865 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id); | 1868 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id); |
1866 factory.Create(local_frame2_id); | 1869 factory.Create(local_frame2_id); |
1867 | 1870 |
1868 ResourceId ids[] = {11, 12, 13}; | 1871 ResourceId ids[] = {11, 12, 13}; |
1869 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1872 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
1870 &factory, surface1_id); | 1873 &factory, surface1_id); |
1871 ResourceId ids2[] = {14, 15, 16}; | 1874 ResourceId ids2[] = {14, 15, 16}; |
1872 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), | 1875 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), |
1873 &factory, surface2_id); | 1876 &factory, surface2_id); |
1874 | 1877 |
(...skipping 18 matching lines...) Expand all Loading... |
1893 EXPECT_EQ(3u, resource_provider_->num_resources()); | 1896 EXPECT_EQ(3u, resource_provider_->num_resources()); |
1894 factory.Destroy(local_frame1_id); | 1897 factory.Destroy(local_frame1_id); |
1895 factory.Destroy(local_frame2_id); | 1898 factory.Destroy(local_frame2_id); |
1896 } | 1899 } |
1897 | 1900 |
1898 // Ensure that aggregator completely ignores Surfaces that reference invalid | 1901 // Ensure that aggregator completely ignores Surfaces that reference invalid |
1899 // resources. | 1902 // resources. |
1900 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { | 1903 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { |
1901 ResourceTrackingSurfaceFactoryClient client; | 1904 ResourceTrackingSurfaceFactoryClient client; |
1902 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); | 1905 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); |
1903 LocalFrameId root_local_frame_id(7u, 1); | 1906 LocalFrameId root_local_frame_id(7u, kArbitraryToken); |
1904 SurfaceId root_surface_id(kArbitraryFrameSinkId, root_local_frame_id); | 1907 SurfaceId root_surface_id(kArbitraryFrameSinkId, root_local_frame_id); |
1905 factory.Create(root_local_frame_id); | 1908 factory.Create(root_local_frame_id); |
1906 LocalFrameId middle_local_frame_id(8u, 1); | 1909 LocalFrameId middle_local_frame_id(8u, kArbitraryToken); |
1907 SurfaceId middle_surface_id(kArbitraryFrameSinkId, middle_local_frame_id); | 1910 SurfaceId middle_surface_id(kArbitraryFrameSinkId, middle_local_frame_id); |
1908 factory.Create(middle_local_frame_id); | 1911 factory.Create(middle_local_frame_id); |
1909 LocalFrameId child_local_frame_id(9u, 1); | 1912 LocalFrameId child_local_frame_id(9u, kArbitraryToken); |
1910 SurfaceId child_surface_id(kArbitraryFrameSinkId, child_local_frame_id); | 1913 SurfaceId child_surface_id(kArbitraryFrameSinkId, child_local_frame_id); |
1911 factory.Create(child_local_frame_id); | 1914 factory.Create(child_local_frame_id); |
1912 | 1915 |
1913 ResourceId ids[] = {14, 15, 16}; | 1916 ResourceId ids[] = {14, 15, 16}; |
1914 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1917 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
1915 &factory, child_surface_id); | 1918 &factory, child_surface_id); |
1916 | 1919 |
1917 ResourceId ids2[] = {17, 18, 19}; | 1920 ResourceId ids2[] = {17, 18, 19}; |
1918 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, | 1921 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, |
1919 child_surface_id, &factory, | 1922 child_surface_id, &factory, |
(...skipping 23 matching lines...) Expand all Loading... |
1943 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); | 1946 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); |
1944 | 1947 |
1945 factory.Destroy(root_local_frame_id); | 1948 factory.Destroy(root_local_frame_id); |
1946 factory.Destroy(child_local_frame_id); | 1949 factory.Destroy(child_local_frame_id); |
1947 factory.Destroy(middle_local_frame_id); | 1950 factory.Destroy(middle_local_frame_id); |
1948 } | 1951 } |
1949 | 1952 |
1950 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { | 1953 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { |
1951 ResourceTrackingSurfaceFactoryClient client; | 1954 ResourceTrackingSurfaceFactoryClient client; |
1952 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); | 1955 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); |
1953 LocalFrameId local_frame1_id(7u, 0); | 1956 LocalFrameId local_frame1_id(7u, base::UnguessableToken::Create()); |
1954 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id); | 1957 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id); |
1955 factory.Create(local_frame1_id); | 1958 factory.Create(local_frame1_id); |
1956 | 1959 |
1957 LocalFrameId local_frame2_id(8u, 0); | 1960 LocalFrameId local_frame2_id(8u, base::UnguessableToken::Create()); |
1958 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id); | 1961 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id); |
1959 factory.Create(local_frame2_id); | 1962 factory.Create(local_frame2_id); |
1960 | 1963 |
1961 ResourceId ids[] = {11, 12, 13}; | 1964 ResourceId ids[] = {11, 12, 13}; |
1962 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1965 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
1963 &factory, surface1_id); | 1966 &factory, surface1_id); |
1964 | 1967 |
1965 CompositorFrame frame = aggregator_->Aggregate(surface1_id); | 1968 CompositorFrame frame = aggregator_->Aggregate(surface1_id); |
1966 | 1969 |
1967 RenderPass* render_pass = frame.render_pass_list.back().get(); | 1970 RenderPass* render_pass = frame.render_pass_list.back().get(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 // Output is insecure, so texture should be drawn. | 2012 // Output is insecure, so texture should be drawn. |
2010 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); | 2013 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); |
2011 | 2014 |
2012 factory.Destroy(local_frame1_id); | 2015 factory.Destroy(local_frame1_id); |
2013 factory.Destroy(local_frame2_id); | 2016 factory.Destroy(local_frame2_id); |
2014 } | 2017 } |
2015 | 2018 |
2016 } // namespace | 2019 } // namespace |
2017 } // namespace cc | 2020 } // namespace cc |
2018 | 2021 |
OLD | NEW |