| 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 21 matching lines...) Expand all Loading... |
| 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 FrameSinkId kArbitraryFrameSinkId(1, 1); | 38 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); |
| 39 static constexpr FrameSinkId kArbitraryChildFrameSinkId(2, 2); | 39 static constexpr FrameSinkId kArbitraryChildFrameSinkId(2, 2); |
| 40 | 40 |
| 41 SurfaceId InvalidSurfaceId() { | 41 SurfaceId InvalidSurfaceId() { |
| 42 static SurfaceId invalid(kArbitraryFrameSinkId, LocalFrameId(0xdeadbeef, 0)); | 42 static SurfaceId invalid(kArbitraryFrameSinkId, |
| 43 LocalFrameId(0xdeadbeef, base::UnguessableToken())); |
| 43 return invalid; | 44 return invalid; |
| 44 } | 45 } |
| 45 | 46 |
| 46 gfx::Size SurfaceSize() { | 47 gfx::Size SurfaceSize() { |
| 47 static gfx::Size size(100, 100); | 48 static gfx::Size size(100, 100); |
| 48 return size; | 49 return size; |
| 49 } | 50 } |
| 50 | 51 |
| 51 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 52 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
| 52 public: | 53 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 73 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} | 74 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} |
| 74 | 75 |
| 75 protected: | 76 protected: |
| 76 SurfaceManager manager_; | 77 SurfaceManager manager_; |
| 77 EmptySurfaceFactoryClient empty_client_; | 78 EmptySurfaceFactoryClient empty_client_; |
| 78 SurfaceFactory factory_; | 79 SurfaceFactory factory_; |
| 79 SurfaceAggregator aggregator_; | 80 SurfaceAggregator aggregator_; |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { | 83 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { |
| 83 LocalFrameId local_frame_id(7, 0); | 84 LocalFrameId local_frame_id(7, base::UnguessableToken::Create()); |
| 84 SurfaceId one_id(kArbitraryFrameSinkId, local_frame_id); | 85 SurfaceId one_id(kArbitraryFrameSinkId, local_frame_id); |
| 85 factory_.Create(local_frame_id); | 86 factory_.Create(local_frame_id); |
| 86 | 87 |
| 87 CompositorFrame frame = aggregator_.Aggregate(one_id); | 88 CompositorFrame frame = aggregator_.Aggregate(one_id); |
| 88 EXPECT_FALSE(frame.delegated_frame_data); | 89 EXPECT_FALSE(frame.delegated_frame_data); |
| 89 | 90 |
| 90 factory_.Destroy(local_frame_id); | 91 factory_.Destroy(local_frame_id); |
| 91 } | 92 } |
| 92 | 93 |
| 93 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { | 94 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { |
| (...skipping 1886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1980 frame_data->render_pass_list.push_back(std::move(pass)); | 1981 frame_data->render_pass_list.push_back(std::move(pass)); |
| 1981 CompositorFrame frame; | 1982 CompositorFrame frame; |
| 1982 frame.delegated_frame_data = std::move(frame_data); | 1983 frame.delegated_frame_data = std::move(frame_data); |
| 1983 factory->SubmitCompositorFrame(surface_id.local_frame_id(), std::move(frame), | 1984 factory->SubmitCompositorFrame(surface_id.local_frame_id(), std::move(frame), |
| 1984 SurfaceFactory::DrawCallback()); | 1985 SurfaceFactory::DrawCallback()); |
| 1985 } | 1986 } |
| 1986 | 1987 |
| 1987 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { | 1988 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { |
| 1988 ResourceTrackingSurfaceFactoryClient client; | 1989 ResourceTrackingSurfaceFactoryClient client; |
| 1989 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); | 1990 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); |
| 1990 LocalFrameId local_frame_id(7u, 0); | 1991 LocalFrameId local_frame_id(7u, base::UnguessableToken::Create()); |
| 1991 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); | 1992 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); |
| 1992 factory.Create(local_frame_id); | 1993 factory.Create(local_frame_id); |
| 1993 | 1994 |
| 1994 ResourceId ids[] = {11, 12, 13}; | 1995 ResourceId ids[] = {11, 12, 13}; |
| 1995 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1996 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 1996 &factory, surface_id); | 1997 &factory, surface_id); |
| 1997 | 1998 |
| 1998 CompositorFrame frame = aggregator_->Aggregate(surface_id); | 1999 CompositorFrame frame = aggregator_->Aggregate(surface_id); |
| 1999 | 2000 |
| 2000 // Nothing should be available to be returned yet. | 2001 // Nothing should be available to be returned yet. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2011 returned_ids[i] = client.returned_resources()[i].id; | 2012 returned_ids[i] = client.returned_resources()[i].id; |
| 2012 } | 2013 } |
| 2013 EXPECT_THAT(returned_ids, | 2014 EXPECT_THAT(returned_ids, |
| 2014 testing::WhenSorted(testing::ElementsAreArray(ids))); | 2015 testing::WhenSorted(testing::ElementsAreArray(ids))); |
| 2015 factory.Destroy(local_frame_id); | 2016 factory.Destroy(local_frame_id); |
| 2016 } | 2017 } |
| 2017 | 2018 |
| 2018 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { | 2019 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { |
| 2019 ResourceTrackingSurfaceFactoryClient client; | 2020 ResourceTrackingSurfaceFactoryClient client; |
| 2020 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); | 2021 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); |
| 2021 LocalFrameId local_frame_id(7u, 0); | 2022 LocalFrameId local_frame_id(7u, base::UnguessableToken::Create()); |
| 2022 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); | 2023 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); |
| 2023 factory.Create(local_frame_id); | 2024 factory.Create(local_frame_id); |
| 2024 | 2025 |
| 2025 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 2026 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 2026 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 2027 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 2027 pass->id = RenderPassId(1, 1); | 2028 pass->id = RenderPassId(1, 1); |
| 2028 TransferableResource resource; | 2029 TransferableResource resource; |
| 2029 resource.id = 11; | 2030 resource.id = 11; |
| 2030 // ResourceProvider is software but resource is not, so it should be | 2031 // ResourceProvider is software but resource is not, so it should be |
| 2031 // ignored. | 2032 // ignored. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2046 surface_id); | 2047 surface_id); |
| 2047 ASSERT_EQ(1u, client.returned_resources().size()); | 2048 ASSERT_EQ(1u, client.returned_resources().size()); |
| 2048 EXPECT_EQ(11u, client.returned_resources()[0].id); | 2049 EXPECT_EQ(11u, client.returned_resources()[0].id); |
| 2049 | 2050 |
| 2050 factory.Destroy(local_frame_id); | 2051 factory.Destroy(local_frame_id); |
| 2051 } | 2052 } |
| 2052 | 2053 |
| 2053 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { | 2054 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { |
| 2054 ResourceTrackingSurfaceFactoryClient client; | 2055 ResourceTrackingSurfaceFactoryClient client; |
| 2055 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); | 2056 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); |
| 2056 LocalFrameId local_frame1_id(7u, 0); | 2057 LocalFrameId local_frame1_id(7u, base::UnguessableToken::Create()); |
| 2057 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id); | 2058 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id); |
| 2058 factory.Create(local_frame1_id); | 2059 factory.Create(local_frame1_id); |
| 2059 | 2060 |
| 2060 LocalFrameId local_frame2_id(8u, 0); | 2061 LocalFrameId local_frame2_id(8u, base::UnguessableToken::Create()); |
| 2061 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id); | 2062 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id); |
| 2062 factory.Create(local_frame2_id); | 2063 factory.Create(local_frame2_id); |
| 2063 | 2064 |
| 2064 ResourceId ids[] = {11, 12, 13}; | 2065 ResourceId ids[] = {11, 12, 13}; |
| 2065 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2066 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2066 &factory, surface1_id); | 2067 &factory, surface1_id); |
| 2067 ResourceId ids2[] = {14, 15, 16}; | 2068 ResourceId ids2[] = {14, 15, 16}; |
| 2068 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), | 2069 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), |
| 2069 &factory, surface2_id); | 2070 &factory, surface2_id); |
| 2070 | 2071 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2089 EXPECT_EQ(3u, resource_provider_->num_resources()); | 2090 EXPECT_EQ(3u, resource_provider_->num_resources()); |
| 2090 factory.Destroy(local_frame1_id); | 2091 factory.Destroy(local_frame1_id); |
| 2091 factory.Destroy(local_frame2_id); | 2092 factory.Destroy(local_frame2_id); |
| 2092 } | 2093 } |
| 2093 | 2094 |
| 2094 // Ensure that aggregator completely ignores Surfaces that reference invalid | 2095 // Ensure that aggregator completely ignores Surfaces that reference invalid |
| 2095 // resources. | 2096 // resources. |
| 2096 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { | 2097 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { |
| 2097 ResourceTrackingSurfaceFactoryClient client; | 2098 ResourceTrackingSurfaceFactoryClient client; |
| 2098 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); | 2099 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); |
| 2099 LocalFrameId root_local_frame_id(7u, 0); | 2100 LocalFrameId root_local_frame_id(7u, base::UnguessableToken::Create()); |
| 2100 SurfaceId root_surface_id(kArbitraryFrameSinkId, root_local_frame_id); | 2101 SurfaceId root_surface_id(kArbitraryFrameSinkId, root_local_frame_id); |
| 2101 factory.Create(root_local_frame_id); | 2102 factory.Create(root_local_frame_id); |
| 2102 LocalFrameId middle_local_frame_id(8u, 0); | 2103 LocalFrameId middle_local_frame_id(8u, base::UnguessableToken::Create()); |
| 2103 SurfaceId middle_surface_id(kArbitraryFrameSinkId, middle_local_frame_id); | 2104 SurfaceId middle_surface_id(kArbitraryFrameSinkId, middle_local_frame_id); |
| 2104 factory.Create(middle_local_frame_id); | 2105 factory.Create(middle_local_frame_id); |
| 2105 LocalFrameId child_local_frame_id(9u, 0); | 2106 LocalFrameId child_local_frame_id(9u, base::UnguessableToken::Create()); |
| 2106 SurfaceId child_surface_id(kArbitraryFrameSinkId, child_local_frame_id); | 2107 SurfaceId child_surface_id(kArbitraryFrameSinkId, child_local_frame_id); |
| 2107 factory.Create(child_local_frame_id); | 2108 factory.Create(child_local_frame_id); |
| 2108 | 2109 |
| 2109 ResourceId ids[] = {14, 15, 16}; | 2110 ResourceId ids[] = {14, 15, 16}; |
| 2110 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2111 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2111 &factory, child_surface_id); | 2112 &factory, child_surface_id); |
| 2112 | 2113 |
| 2113 ResourceId ids2[] = {17, 18, 19}; | 2114 ResourceId ids2[] = {17, 18, 19}; |
| 2114 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, | 2115 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, |
| 2115 child_surface_id, &factory, | 2116 child_surface_id, &factory, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2140 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); | 2141 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); |
| 2141 | 2142 |
| 2142 factory.Destroy(root_local_frame_id); | 2143 factory.Destroy(root_local_frame_id); |
| 2143 factory.Destroy(child_local_frame_id); | 2144 factory.Destroy(child_local_frame_id); |
| 2144 factory.Destroy(middle_local_frame_id); | 2145 factory.Destroy(middle_local_frame_id); |
| 2145 } | 2146 } |
| 2146 | 2147 |
| 2147 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { | 2148 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { |
| 2148 ResourceTrackingSurfaceFactoryClient client; | 2149 ResourceTrackingSurfaceFactoryClient client; |
| 2149 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); | 2150 SurfaceFactory factory(kArbitraryFrameSinkId, &manager_, &client); |
| 2150 LocalFrameId local_frame1_id(7u, 0); | 2151 LocalFrameId local_frame1_id(7u, base::UnguessableToken::Create()); |
| 2151 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id); | 2152 SurfaceId surface1_id(kArbitraryFrameSinkId, local_frame1_id); |
| 2152 factory.Create(local_frame1_id); | 2153 factory.Create(local_frame1_id); |
| 2153 | 2154 |
| 2154 LocalFrameId local_frame2_id(8u, 0); | 2155 LocalFrameId local_frame2_id(8u, base::UnguessableToken::Create()); |
| 2155 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id); | 2156 SurfaceId surface2_id(kArbitraryFrameSinkId, local_frame2_id); |
| 2156 factory.Create(local_frame2_id); | 2157 factory.Create(local_frame2_id); |
| 2157 | 2158 |
| 2158 ResourceId ids[] = {11, 12, 13}; | 2159 ResourceId ids[] = {11, 12, 13}; |
| 2159 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2160 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2160 &factory, surface1_id); | 2161 &factory, surface1_id); |
| 2161 | 2162 |
| 2162 CompositorFrame frame = aggregator_->Aggregate(surface1_id); | 2163 CompositorFrame frame = aggregator_->Aggregate(surface1_id); |
| 2163 | 2164 |
| 2164 RenderPass* render_pass = | 2165 RenderPass* render_pass = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2208 // Output is insecure, so texture should be drawn. | 2209 // Output is insecure, so texture should be drawn. |
| 2209 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); | 2210 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); |
| 2210 | 2211 |
| 2211 factory.Destroy(local_frame1_id); | 2212 factory.Destroy(local_frame1_id); |
| 2212 factory.Destroy(local_frame2_id); | 2213 factory.Destroy(local_frame2_id); |
| 2213 } | 2214 } |
| 2214 | 2215 |
| 2215 } // namespace | 2216 } // namespace |
| 2216 } // namespace cc | 2217 } // namespace cc |
| 2217 | 2218 |
| OLD | NEW |