| 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 19 matching lines...) Expand all Loading... |
| 30 #include "cc/test/render_pass_test_utils.h" | 30 #include "cc/test/render_pass_test_utils.h" |
| 31 #include "cc/test/surface_aggregator_test_helpers.h" | 31 #include "cc/test/surface_aggregator_test_helpers.h" |
| 32 #include "cc/test/test_shared_bitmap_manager.h" | 32 #include "cc/test/test_shared_bitmap_manager.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "third_party/skia/include/core/SkColor.h" | 35 #include "third_party/skia/include/core/SkColor.h" |
| 36 | 36 |
| 37 namespace cc { | 37 namespace cc { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 static constexpr uint32_t kArbitraryClientId = 0; |
| 41 |
| 40 SurfaceId InvalidSurfaceId() { | 42 SurfaceId InvalidSurfaceId() { |
| 41 static SurfaceId invalid(0, 0xdeadbeef, 0); | 43 static SurfaceId invalid(kArbitraryClientId, 0xdeadbeef, 0); |
| 42 return invalid; | 44 return invalid; |
| 43 } | 45 } |
| 44 | 46 |
| 45 gfx::Size SurfaceSize() { | 47 gfx::Size SurfaceSize() { |
| 46 static gfx::Size size(100, 100); | 48 static gfx::Size size(100, 100); |
| 47 return size; | 49 return size; |
| 48 } | 50 } |
| 49 | 51 |
| 50 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 52 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
| 51 public: | 53 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 72 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} | 74 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} |
| 73 | 75 |
| 74 protected: | 76 protected: |
| 75 SurfaceManager manager_; | 77 SurfaceManager manager_; |
| 76 EmptySurfaceFactoryClient empty_client_; | 78 EmptySurfaceFactoryClient empty_client_; |
| 77 SurfaceFactory factory_; | 79 SurfaceFactory factory_; |
| 78 SurfaceAggregator aggregator_; | 80 SurfaceAggregator aggregator_; |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { | 83 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { |
| 82 SurfaceId one_id(0, 7, 0); | 84 SurfaceId one_id(kArbitraryClientId, 7, 0); |
| 83 factory_.Create(one_id); | 85 factory_.Create(one_id); |
| 84 | 86 |
| 85 CompositorFrame frame = aggregator_.Aggregate(one_id); | 87 CompositorFrame frame = aggregator_.Aggregate(one_id); |
| 86 EXPECT_FALSE(frame.delegated_frame_data); | 88 EXPECT_FALSE(frame.delegated_frame_data); |
| 87 | 89 |
| 88 factory_.Destroy(one_id); | 90 factory_.Destroy(one_id); |
| 89 } | 91 } |
| 90 | 92 |
| 91 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { | 93 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { |
| 92 public: | 94 public: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 133 |
| 132 EXPECT_EQ(expected_surface_count, | 134 EXPECT_EQ(expected_surface_count, |
| 133 aggregator_.previous_contained_surfaces().size()); | 135 aggregator_.previous_contained_surfaces().size()); |
| 134 for (size_t i = 0; i < expected_surface_count; i++) { | 136 for (size_t i = 0; i < expected_surface_count; i++) { |
| 135 EXPECT_TRUE( | 137 EXPECT_TRUE( |
| 136 aggregator_.previous_contained_surfaces().find(surface_ids[i]) != | 138 aggregator_.previous_contained_surfaces().find(surface_ids[i]) != |
| 137 aggregator_.previous_contained_surfaces().end()); | 139 aggregator_.previous_contained_surfaces().end()); |
| 138 } | 140 } |
| 139 } | 141 } |
| 140 | 142 |
| 141 void SubmitPassListAsFrame(SurfaceId surface_id, RenderPassList* pass_list) { | 143 void SubmitPassListAsFrame(const SurfaceId& surface_id, |
| 144 RenderPassList* pass_list) { |
| 142 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 145 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 143 pass_list->swap(frame_data->render_pass_list); | 146 pass_list->swap(frame_data->render_pass_list); |
| 144 | 147 |
| 145 CompositorFrame frame; | 148 CompositorFrame frame; |
| 146 frame.delegated_frame_data = std::move(frame_data); | 149 frame.delegated_frame_data = std::move(frame_data); |
| 147 | 150 |
| 148 factory_.SubmitCompositorFrame(surface_id, std::move(frame), | 151 factory_.SubmitCompositorFrame(surface_id, std::move(frame), |
| 149 SurfaceFactory::DrawCallback()); | 152 SurfaceFactory::DrawCallback()); |
| 150 } | 153 } |
| 151 | 154 |
| 152 void SubmitCompositorFrame(test::Pass* passes, | 155 void SubmitCompositorFrame(test::Pass* passes, |
| 153 size_t pass_count, | 156 size_t pass_count, |
| 154 SurfaceId surface_id) { | 157 const SurfaceId& surface_id) { |
| 155 RenderPassList pass_list; | 158 RenderPassList pass_list; |
| 156 AddPasses(&pass_list, gfx::Rect(SurfaceSize()), passes, pass_count); | 159 AddPasses(&pass_list, gfx::Rect(SurfaceSize()), passes, pass_count); |
| 157 SubmitPassListAsFrame(surface_id, &pass_list); | 160 SubmitPassListAsFrame(surface_id, &pass_list); |
| 158 } | 161 } |
| 159 | 162 |
| 160 void QueuePassAsFrame(std::unique_ptr<RenderPass> pass, | 163 void QueuePassAsFrame(std::unique_ptr<RenderPass> pass, |
| 161 SurfaceId surface_id) { | 164 const SurfaceId& surface_id) { |
| 162 std::unique_ptr<DelegatedFrameData> delegated_frame_data( | 165 std::unique_ptr<DelegatedFrameData> delegated_frame_data( |
| 163 new DelegatedFrameData); | 166 new DelegatedFrameData); |
| 164 delegated_frame_data->render_pass_list.push_back(std::move(pass)); | 167 delegated_frame_data->render_pass_list.push_back(std::move(pass)); |
| 165 | 168 |
| 166 CompositorFrame child_frame; | 169 CompositorFrame child_frame; |
| 167 child_frame.delegated_frame_data = std::move(delegated_frame_data); | 170 child_frame.delegated_frame_data = std::move(delegated_frame_data); |
| 168 | 171 |
| 169 factory_.SubmitCompositorFrame(surface_id, std::move(child_frame), | 172 factory_.SubmitCompositorFrame(surface_id, std::move(child_frame), |
| 170 SurfaceFactory::DrawCallback()); | 173 SurfaceFactory::DrawCallback()); |
| 171 } | 174 } |
| (...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 frame_data->render_pass_list.push_back(std::move(pass)); | 1913 frame_data->render_pass_list.push_back(std::move(pass)); |
| 1911 CompositorFrame frame; | 1914 CompositorFrame frame; |
| 1912 frame.delegated_frame_data = std::move(frame_data); | 1915 frame.delegated_frame_data = std::move(frame_data); |
| 1913 factory->SubmitCompositorFrame(surface_id, std::move(frame), | 1916 factory->SubmitCompositorFrame(surface_id, std::move(frame), |
| 1914 SurfaceFactory::DrawCallback()); | 1917 SurfaceFactory::DrawCallback()); |
| 1915 } | 1918 } |
| 1916 | 1919 |
| 1917 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { | 1920 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { |
| 1918 ResourceTrackingSurfaceFactoryClient client; | 1921 ResourceTrackingSurfaceFactoryClient client; |
| 1919 SurfaceFactory factory(&manager_, &client); | 1922 SurfaceFactory factory(&manager_, &client); |
| 1920 SurfaceId surface_id(0, 7u, 0); | 1923 SurfaceId surface_id(kArbitraryClientId, 7u, 0); |
| 1921 factory.Create(surface_id); | 1924 factory.Create(surface_id); |
| 1922 | 1925 |
| 1923 ResourceId ids[] = {11, 12, 13}; | 1926 ResourceId ids[] = {11, 12, 13}; |
| 1924 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1927 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 1925 &factory, surface_id); | 1928 &factory, surface_id); |
| 1926 | 1929 |
| 1927 CompositorFrame frame = aggregator_->Aggregate(surface_id); | 1930 CompositorFrame frame = aggregator_->Aggregate(surface_id); |
| 1928 | 1931 |
| 1929 // Nothing should be available to be returned yet. | 1932 // Nothing should be available to be returned yet. |
| 1930 EXPECT_TRUE(client.returned_resources().empty()); | 1933 EXPECT_TRUE(client.returned_resources().empty()); |
| 1931 | 1934 |
| 1932 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, | 1935 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, |
| 1933 surface_id); | 1936 surface_id); |
| 1934 | 1937 |
| 1935 frame = aggregator_->Aggregate(surface_id); | 1938 frame = aggregator_->Aggregate(surface_id); |
| 1936 | 1939 |
| 1937 ASSERT_EQ(3u, client.returned_resources().size()); | 1940 ASSERT_EQ(3u, client.returned_resources().size()); |
| 1938 ResourceId returned_ids[3]; | 1941 ResourceId returned_ids[3]; |
| 1939 for (size_t i = 0; i < 3; ++i) { | 1942 for (size_t i = 0; i < 3; ++i) { |
| 1940 returned_ids[i] = client.returned_resources()[i].id; | 1943 returned_ids[i] = client.returned_resources()[i].id; |
| 1941 } | 1944 } |
| 1942 EXPECT_THAT(returned_ids, | 1945 EXPECT_THAT(returned_ids, |
| 1943 testing::WhenSorted(testing::ElementsAreArray(ids))); | 1946 testing::WhenSorted(testing::ElementsAreArray(ids))); |
| 1944 factory.Destroy(surface_id); | 1947 factory.Destroy(surface_id); |
| 1945 } | 1948 } |
| 1946 | 1949 |
| 1947 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { | 1950 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { |
| 1948 ResourceTrackingSurfaceFactoryClient client; | 1951 ResourceTrackingSurfaceFactoryClient client; |
| 1949 SurfaceFactory factory(&manager_, &client); | 1952 SurfaceFactory factory(&manager_, &client); |
| 1950 SurfaceId surface_id(0, 7u, 0); | 1953 SurfaceId surface_id(kArbitraryClientId, 7u, 0); |
| 1951 factory.Create(surface_id); | 1954 factory.Create(surface_id); |
| 1952 | 1955 |
| 1953 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 1956 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 1954 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 1957 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 1955 pass->id = RenderPassId(1, 1); | 1958 pass->id = RenderPassId(1, 1); |
| 1956 TransferableResource resource; | 1959 TransferableResource resource; |
| 1957 resource.id = 11; | 1960 resource.id = 11; |
| 1958 // ResourceProvider is software but resource is not, so it should be | 1961 // ResourceProvider is software but resource is not, so it should be |
| 1959 // ignored. | 1962 // ignored. |
| 1960 resource.is_software = false; | 1963 resource.is_software = false; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1974 surface_id); | 1977 surface_id); |
| 1975 ASSERT_EQ(1u, client.returned_resources().size()); | 1978 ASSERT_EQ(1u, client.returned_resources().size()); |
| 1976 EXPECT_EQ(11u, client.returned_resources()[0].id); | 1979 EXPECT_EQ(11u, client.returned_resources()[0].id); |
| 1977 | 1980 |
| 1978 factory.Destroy(surface_id); | 1981 factory.Destroy(surface_id); |
| 1979 } | 1982 } |
| 1980 | 1983 |
| 1981 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { | 1984 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { |
| 1982 ResourceTrackingSurfaceFactoryClient client; | 1985 ResourceTrackingSurfaceFactoryClient client; |
| 1983 SurfaceFactory factory(&manager_, &client); | 1986 SurfaceFactory factory(&manager_, &client); |
| 1984 SurfaceId surface1_id(0, 7u, 0); | 1987 SurfaceId surface1_id(kArbitraryClientId, 7u, 0); |
| 1985 factory.Create(surface1_id); | 1988 factory.Create(surface1_id); |
| 1986 | 1989 |
| 1987 SurfaceId surface2_id(0, 8u, 0); | 1990 SurfaceId surface2_id(kArbitraryClientId, 8u, 0); |
| 1988 factory.Create(surface2_id); | 1991 factory.Create(surface2_id); |
| 1989 | 1992 |
| 1990 ResourceId ids[] = {11, 12, 13}; | 1993 ResourceId ids[] = {11, 12, 13}; |
| 1991 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1994 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 1992 &factory, surface1_id); | 1995 &factory, surface1_id); |
| 1993 ResourceId ids2[] = {14, 15, 16}; | 1996 ResourceId ids2[] = {14, 15, 16}; |
| 1994 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), | 1997 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), |
| 1995 &factory, surface2_id); | 1998 &factory, surface2_id); |
| 1996 | 1999 |
| 1997 CompositorFrame frame = aggregator_->Aggregate(surface1_id); | 2000 CompositorFrame frame = aggregator_->Aggregate(surface1_id); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2015 EXPECT_EQ(3u, resource_provider_->num_resources()); | 2018 EXPECT_EQ(3u, resource_provider_->num_resources()); |
| 2016 factory.Destroy(surface1_id); | 2019 factory.Destroy(surface1_id); |
| 2017 factory.Destroy(surface2_id); | 2020 factory.Destroy(surface2_id); |
| 2018 } | 2021 } |
| 2019 | 2022 |
| 2020 // Ensure that aggregator completely ignores Surfaces that reference invalid | 2023 // Ensure that aggregator completely ignores Surfaces that reference invalid |
| 2021 // resources. | 2024 // resources. |
| 2022 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { | 2025 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { |
| 2023 ResourceTrackingSurfaceFactoryClient client; | 2026 ResourceTrackingSurfaceFactoryClient client; |
| 2024 SurfaceFactory factory(&manager_, &client); | 2027 SurfaceFactory factory(&manager_, &client); |
| 2025 SurfaceId root_surface_id(0, 7u, 0); | 2028 SurfaceId root_surface_id(kArbitraryClientId, 7u, 0); |
| 2026 factory.Create(root_surface_id); | 2029 factory.Create(root_surface_id); |
| 2027 SurfaceId middle_surface_id(0, 8u, 0); | 2030 SurfaceId middle_surface_id(kArbitraryClientId, 8u, 0); |
| 2028 factory.Create(middle_surface_id); | 2031 factory.Create(middle_surface_id); |
| 2029 SurfaceId child_surface_id(0, 9u, 0); | 2032 SurfaceId child_surface_id(kArbitraryClientId, 9u, 0); |
| 2030 factory.Create(child_surface_id); | 2033 factory.Create(child_surface_id); |
| 2031 | 2034 |
| 2032 ResourceId ids[] = {14, 15, 16}; | 2035 ResourceId ids[] = {14, 15, 16}; |
| 2033 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2036 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2034 &factory, child_surface_id); | 2037 &factory, child_surface_id); |
| 2035 | 2038 |
| 2036 ResourceId ids2[] = {17, 18, 19}; | 2039 ResourceId ids2[] = {17, 18, 19}; |
| 2037 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, | 2040 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, |
| 2038 child_surface_id, &factory, | 2041 child_surface_id, &factory, |
| 2039 middle_surface_id); | 2042 middle_surface_id); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2063 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); | 2066 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); |
| 2064 | 2067 |
| 2065 factory.Destroy(root_surface_id); | 2068 factory.Destroy(root_surface_id); |
| 2066 factory.Destroy(child_surface_id); | 2069 factory.Destroy(child_surface_id); |
| 2067 factory.Destroy(middle_surface_id); | 2070 factory.Destroy(middle_surface_id); |
| 2068 } | 2071 } |
| 2069 | 2072 |
| 2070 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { | 2073 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { |
| 2071 ResourceTrackingSurfaceFactoryClient client; | 2074 ResourceTrackingSurfaceFactoryClient client; |
| 2072 SurfaceFactory factory(&manager_, &client); | 2075 SurfaceFactory factory(&manager_, &client); |
| 2073 SurfaceId surface1_id(0, 7u, 0); | 2076 SurfaceId surface1_id(kArbitraryClientId, 7u, 0); |
| 2074 factory.Create(surface1_id); | 2077 factory.Create(surface1_id); |
| 2075 | 2078 |
| 2076 SurfaceId surface2_id(0, 8u, 0); | 2079 SurfaceId surface2_id(kArbitraryClientId, 8u, 0); |
| 2077 factory.Create(surface2_id); | 2080 factory.Create(surface2_id); |
| 2078 | 2081 |
| 2079 ResourceId ids[] = {11, 12, 13}; | 2082 ResourceId ids[] = {11, 12, 13}; |
| 2080 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2083 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2081 &factory, surface1_id); | 2084 &factory, surface1_id); |
| 2082 | 2085 |
| 2083 CompositorFrame frame = aggregator_->Aggregate(surface1_id); | 2086 CompositorFrame frame = aggregator_->Aggregate(surface1_id); |
| 2084 | 2087 |
| 2085 RenderPass* render_pass = | 2088 RenderPass* render_pass = |
| 2086 frame.delegated_frame_data->render_pass_list.back().get(); | 2089 frame.delegated_frame_data->render_pass_list.back().get(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 // Output is insecure, so texture should be drawn. | 2132 // Output is insecure, so texture should be drawn. |
| 2130 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); | 2133 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); |
| 2131 | 2134 |
| 2132 factory.Destroy(surface1_id); | 2135 factory.Destroy(surface1_id); |
| 2133 factory.Destroy(surface2_id); | 2136 factory.Destroy(surface2_id); |
| 2134 } | 2137 } |
| 2135 | 2138 |
| 2136 } // namespace | 2139 } // namespace |
| 2137 } // namespace cc | 2140 } // namespace cc |
| 2138 | 2141 |
| OLD | NEW |