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