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 17 matching lines...) Expand all Loading... |
28 #include "cc/test/render_pass_test_utils.h" | 28 #include "cc/test/render_pass_test_utils.h" |
29 #include "cc/test/surface_aggregator_test_helpers.h" | 29 #include "cc/test/surface_aggregator_test_helpers.h" |
30 #include "cc/test/test_shared_bitmap_manager.h" | 30 #include "cc/test/test_shared_bitmap_manager.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "third_party/skia/include/core/SkColor.h" | 33 #include "third_party/skia/include/core/SkColor.h" |
34 | 34 |
35 namespace cc { | 35 namespace cc { |
36 namespace { | 36 namespace { |
37 | 37 |
38 static constexpr uint32_t kArbitraryClientId = 0; | 38 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); |
39 | 39 |
40 SurfaceId InvalidSurfaceId() { | 40 SurfaceId InvalidSurfaceId() { |
41 static SurfaceId invalid(kArbitraryClientId, 0xdeadbeef, 0); | 41 static SurfaceId invalid(kArbitraryFrameSinkId, 0xdeadbeef, 0); |
42 return invalid; | 42 return invalid; |
43 } | 43 } |
44 | 44 |
45 gfx::Size SurfaceSize() { | 45 gfx::Size SurfaceSize() { |
46 static gfx::Size size(100, 100); | 46 static gfx::Size size(100, 100); |
47 return size; | 47 return size; |
48 } | 48 } |
49 | 49 |
50 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 50 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
51 public: | 51 public: |
(...skipping 20 matching lines...) Expand all Loading... |
72 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} | 72 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} |
73 | 73 |
74 protected: | 74 protected: |
75 SurfaceManager manager_; | 75 SurfaceManager manager_; |
76 EmptySurfaceFactoryClient empty_client_; | 76 EmptySurfaceFactoryClient empty_client_; |
77 SurfaceFactory factory_; | 77 SurfaceFactory factory_; |
78 SurfaceAggregator aggregator_; | 78 SurfaceAggregator aggregator_; |
79 }; | 79 }; |
80 | 80 |
81 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { | 81 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { |
82 SurfaceId one_id(kArbitraryClientId, 7, 0); | 82 SurfaceId one_id(kArbitraryFrameSinkId, 7, 0); |
83 factory_.Create(one_id); | 83 factory_.Create(one_id); |
84 | 84 |
85 CompositorFrame frame = aggregator_.Aggregate(one_id); | 85 CompositorFrame frame = aggregator_.Aggregate(one_id); |
86 EXPECT_FALSE(frame.delegated_frame_data); | 86 EXPECT_FALSE(frame.delegated_frame_data); |
87 | 87 |
88 factory_.Destroy(one_id); | 88 factory_.Destroy(one_id); |
89 } | 89 } |
90 | 90 |
91 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { | 91 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { |
92 public: | 92 public: |
93 explicit SurfaceAggregatorValidSurfaceTest(bool use_damage_rect) | 93 explicit SurfaceAggregatorValidSurfaceTest(bool use_damage_rect) |
94 : SurfaceAggregatorTest(use_damage_rect), | 94 : SurfaceAggregatorTest(use_damage_rect), |
95 allocator_(1u), | 95 allocator_(FrameSinkId(1, 1)), |
96 child_allocator_(2u) {} | 96 child_allocator_(FrameSinkId(2, 2)) {} |
97 SurfaceAggregatorValidSurfaceTest() | 97 SurfaceAggregatorValidSurfaceTest() |
98 : SurfaceAggregatorValidSurfaceTest(false) {} | 98 : SurfaceAggregatorValidSurfaceTest(false) {} |
99 | 99 |
100 void SetUp() override { | 100 void SetUp() override { |
101 SurfaceAggregatorTest::SetUp(); | 101 SurfaceAggregatorTest::SetUp(); |
102 root_surface_id_ = allocator_.GenerateId(); | 102 root_surface_id_ = allocator_.GenerateId(); |
103 factory_.Create(root_surface_id_); | 103 factory_.Create(root_surface_id_); |
104 root_surface_ = manager_.GetSurfaceForId(root_surface_id_); | 104 root_surface_ = manager_.GetSurfaceForId(root_surface_id_); |
105 } | 105 } |
106 | 106 |
(...skipping 1798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1905 frame_data->render_pass_list.push_back(std::move(pass)); | 1905 frame_data->render_pass_list.push_back(std::move(pass)); |
1906 CompositorFrame frame; | 1906 CompositorFrame frame; |
1907 frame.delegated_frame_data = std::move(frame_data); | 1907 frame.delegated_frame_data = std::move(frame_data); |
1908 factory->SubmitCompositorFrame(surface_id, std::move(frame), | 1908 factory->SubmitCompositorFrame(surface_id, std::move(frame), |
1909 SurfaceFactory::DrawCallback()); | 1909 SurfaceFactory::DrawCallback()); |
1910 } | 1910 } |
1911 | 1911 |
1912 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { | 1912 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { |
1913 ResourceTrackingSurfaceFactoryClient client; | 1913 ResourceTrackingSurfaceFactoryClient client; |
1914 SurfaceFactory factory(&manager_, &client); | 1914 SurfaceFactory factory(&manager_, &client); |
1915 SurfaceId surface_id(kArbitraryClientId, 7u, 0); | 1915 SurfaceId surface_id(kArbitraryFrameSinkId, 7u, 0); |
1916 factory.Create(surface_id); | 1916 factory.Create(surface_id); |
1917 | 1917 |
1918 ResourceId ids[] = {11, 12, 13}; | 1918 ResourceId ids[] = {11, 12, 13}; |
1919 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1919 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
1920 &factory, surface_id); | 1920 &factory, surface_id); |
1921 | 1921 |
1922 CompositorFrame frame = aggregator_->Aggregate(surface_id); | 1922 CompositorFrame frame = aggregator_->Aggregate(surface_id); |
1923 | 1923 |
1924 // Nothing should be available to be returned yet. | 1924 // Nothing should be available to be returned yet. |
1925 EXPECT_TRUE(client.returned_resources().empty()); | 1925 EXPECT_TRUE(client.returned_resources().empty()); |
1926 | 1926 |
1927 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, | 1927 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, |
1928 surface_id); | 1928 surface_id); |
1929 | 1929 |
1930 frame = aggregator_->Aggregate(surface_id); | 1930 frame = aggregator_->Aggregate(surface_id); |
1931 | 1931 |
1932 ASSERT_EQ(3u, client.returned_resources().size()); | 1932 ASSERT_EQ(3u, client.returned_resources().size()); |
1933 ResourceId returned_ids[3]; | 1933 ResourceId returned_ids[3]; |
1934 for (size_t i = 0; i < 3; ++i) { | 1934 for (size_t i = 0; i < 3; ++i) { |
1935 returned_ids[i] = client.returned_resources()[i].id; | 1935 returned_ids[i] = client.returned_resources()[i].id; |
1936 } | 1936 } |
1937 EXPECT_THAT(returned_ids, | 1937 EXPECT_THAT(returned_ids, |
1938 testing::WhenSorted(testing::ElementsAreArray(ids))); | 1938 testing::WhenSorted(testing::ElementsAreArray(ids))); |
1939 factory.Destroy(surface_id); | 1939 factory.Destroy(surface_id); |
1940 } | 1940 } |
1941 | 1941 |
1942 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { | 1942 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { |
1943 ResourceTrackingSurfaceFactoryClient client; | 1943 ResourceTrackingSurfaceFactoryClient client; |
1944 SurfaceFactory factory(&manager_, &client); | 1944 SurfaceFactory factory(&manager_, &client); |
1945 SurfaceId surface_id(kArbitraryClientId, 7u, 0); | 1945 SurfaceId surface_id(kArbitraryFrameSinkId, 7u, 0); |
1946 factory.Create(surface_id); | 1946 factory.Create(surface_id); |
1947 | 1947 |
1948 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 1948 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
1949 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 1949 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
1950 pass->id = RenderPassId(1, 1); | 1950 pass->id = RenderPassId(1, 1); |
1951 TransferableResource resource; | 1951 TransferableResource resource; |
1952 resource.id = 11; | 1952 resource.id = 11; |
1953 // ResourceProvider is software but resource is not, so it should be | 1953 // ResourceProvider is software but resource is not, so it should be |
1954 // ignored. | 1954 // ignored. |
1955 resource.is_software = false; | 1955 resource.is_software = false; |
(...skipping 13 matching lines...) Expand all Loading... |
1969 surface_id); | 1969 surface_id); |
1970 ASSERT_EQ(1u, client.returned_resources().size()); | 1970 ASSERT_EQ(1u, client.returned_resources().size()); |
1971 EXPECT_EQ(11u, client.returned_resources()[0].id); | 1971 EXPECT_EQ(11u, client.returned_resources()[0].id); |
1972 | 1972 |
1973 factory.Destroy(surface_id); | 1973 factory.Destroy(surface_id); |
1974 } | 1974 } |
1975 | 1975 |
1976 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { | 1976 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { |
1977 ResourceTrackingSurfaceFactoryClient client; | 1977 ResourceTrackingSurfaceFactoryClient client; |
1978 SurfaceFactory factory(&manager_, &client); | 1978 SurfaceFactory factory(&manager_, &client); |
1979 SurfaceId surface1_id(kArbitraryClientId, 7u, 0); | 1979 SurfaceId surface1_id(kArbitraryFrameSinkId, 7u, 0); |
1980 factory.Create(surface1_id); | 1980 factory.Create(surface1_id); |
1981 | 1981 |
1982 SurfaceId surface2_id(kArbitraryClientId, 8u, 0); | 1982 SurfaceId surface2_id(kArbitraryFrameSinkId, 8u, 0); |
1983 factory.Create(surface2_id); | 1983 factory.Create(surface2_id); |
1984 | 1984 |
1985 ResourceId ids[] = {11, 12, 13}; | 1985 ResourceId ids[] = {11, 12, 13}; |
1986 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1986 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
1987 &factory, surface1_id); | 1987 &factory, surface1_id); |
1988 ResourceId ids2[] = {14, 15, 16}; | 1988 ResourceId ids2[] = {14, 15, 16}; |
1989 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), | 1989 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), |
1990 &factory, surface2_id); | 1990 &factory, surface2_id); |
1991 | 1991 |
1992 CompositorFrame frame = aggregator_->Aggregate(surface1_id); | 1992 CompositorFrame frame = aggregator_->Aggregate(surface1_id); |
(...skipping 17 matching lines...) Expand all Loading... |
2010 EXPECT_EQ(3u, resource_provider_->num_resources()); | 2010 EXPECT_EQ(3u, resource_provider_->num_resources()); |
2011 factory.Destroy(surface1_id); | 2011 factory.Destroy(surface1_id); |
2012 factory.Destroy(surface2_id); | 2012 factory.Destroy(surface2_id); |
2013 } | 2013 } |
2014 | 2014 |
2015 // Ensure that aggregator completely ignores Surfaces that reference invalid | 2015 // Ensure that aggregator completely ignores Surfaces that reference invalid |
2016 // resources. | 2016 // resources. |
2017 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { | 2017 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { |
2018 ResourceTrackingSurfaceFactoryClient client; | 2018 ResourceTrackingSurfaceFactoryClient client; |
2019 SurfaceFactory factory(&manager_, &client); | 2019 SurfaceFactory factory(&manager_, &client); |
2020 SurfaceId root_surface_id(kArbitraryClientId, 7u, 0); | 2020 SurfaceId root_surface_id(kArbitraryFrameSinkId, 7u, 0); |
2021 factory.Create(root_surface_id); | 2021 factory.Create(root_surface_id); |
2022 SurfaceId middle_surface_id(kArbitraryClientId, 8u, 0); | 2022 SurfaceId middle_surface_id(kArbitraryFrameSinkId, 8u, 0); |
2023 factory.Create(middle_surface_id); | 2023 factory.Create(middle_surface_id); |
2024 SurfaceId child_surface_id(kArbitraryClientId, 9u, 0); | 2024 SurfaceId child_surface_id(kArbitraryFrameSinkId, 9u, 0); |
2025 factory.Create(child_surface_id); | 2025 factory.Create(child_surface_id); |
2026 | 2026 |
2027 ResourceId ids[] = {14, 15, 16}; | 2027 ResourceId ids[] = {14, 15, 16}; |
2028 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2028 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
2029 &factory, child_surface_id); | 2029 &factory, child_surface_id); |
2030 | 2030 |
2031 ResourceId ids2[] = {17, 18, 19}; | 2031 ResourceId ids2[] = {17, 18, 19}; |
2032 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, | 2032 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, |
2033 child_surface_id, &factory, | 2033 child_surface_id, &factory, |
2034 middle_surface_id); | 2034 middle_surface_id); |
(...skipping 23 matching lines...) Expand all Loading... |
2058 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); | 2058 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); |
2059 | 2059 |
2060 factory.Destroy(root_surface_id); | 2060 factory.Destroy(root_surface_id); |
2061 factory.Destroy(child_surface_id); | 2061 factory.Destroy(child_surface_id); |
2062 factory.Destroy(middle_surface_id); | 2062 factory.Destroy(middle_surface_id); |
2063 } | 2063 } |
2064 | 2064 |
2065 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { | 2065 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { |
2066 ResourceTrackingSurfaceFactoryClient client; | 2066 ResourceTrackingSurfaceFactoryClient client; |
2067 SurfaceFactory factory(&manager_, &client); | 2067 SurfaceFactory factory(&manager_, &client); |
2068 SurfaceId surface1_id(kArbitraryClientId, 7u, 0); | 2068 SurfaceId surface1_id(kArbitraryFrameSinkId, 7u, 0); |
2069 factory.Create(surface1_id); | 2069 factory.Create(surface1_id); |
2070 | 2070 |
2071 SurfaceId surface2_id(kArbitraryClientId, 8u, 0); | 2071 SurfaceId surface2_id(kArbitraryFrameSinkId, 8u, 0); |
2072 factory.Create(surface2_id); | 2072 factory.Create(surface2_id); |
2073 | 2073 |
2074 ResourceId ids[] = {11, 12, 13}; | 2074 ResourceId ids[] = {11, 12, 13}; |
2075 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2075 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
2076 &factory, surface1_id); | 2076 &factory, surface1_id); |
2077 | 2077 |
2078 CompositorFrame frame = aggregator_->Aggregate(surface1_id); | 2078 CompositorFrame frame = aggregator_->Aggregate(surface1_id); |
2079 | 2079 |
2080 RenderPass* render_pass = | 2080 RenderPass* render_pass = |
2081 frame.delegated_frame_data->render_pass_list.back().get(); | 2081 frame.delegated_frame_data->render_pass_list.back().get(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2124 // Output is insecure, so texture should be drawn. | 2124 // Output is insecure, so texture should be drawn. |
2125 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); | 2125 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); |
2126 | 2126 |
2127 factory.Destroy(surface1_id); | 2127 factory.Destroy(surface1_id); |
2128 factory.Destroy(surface2_id); | 2128 factory.Destroy(surface2_id); |
2129 } | 2129 } |
2130 | 2130 |
2131 } // namespace | 2131 } // namespace |
2132 } // namespace cc | 2132 } // namespace cc |
2133 | 2133 |
OLD | NEW |