| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} | 62 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} |
| 63 | 63 |
| 64 gfx::Rect last_damage_rect_; | 64 gfx::Rect last_damage_rect_; |
| 65 SurfaceId last_surface_id_; | 65 SurfaceId last_surface_id_; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 class SurfaceAggregatorTest : public testing::Test { | 68 class SurfaceAggregatorTest : public testing::Test { |
| 69 public: | 69 public: |
| 70 explicit SurfaceAggregatorTest(bool use_damage_rect) | 70 explicit SurfaceAggregatorTest(bool use_damage_rect) |
| 71 : factory_(&manager_, &empty_client_), | 71 : factory_(kArbitraryClientId, &manager_, &empty_client_), |
| 72 aggregator_(&manager_, NULL, use_damage_rect) {} | 72 aggregator_(&manager_, NULL, use_damage_rect) {} |
| 73 | 73 |
| 74 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} | 74 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} |
| 75 | 75 |
| 76 protected: | 76 protected: |
| 77 SurfaceManager manager_; | 77 SurfaceManager manager_; |
| 78 EmptySurfaceFactoryClient empty_client_; | 78 EmptySurfaceFactoryClient empty_client_; |
| 79 SurfaceFactory factory_; | 79 SurfaceFactory factory_; |
| 80 SurfaceAggregator aggregator_; | 80 SurfaceAggregator aggregator_; |
| 81 }; | 81 }; |
| (...skipping 1830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1912 } | 1912 } |
| 1913 frame_data->render_pass_list.push_back(std::move(pass)); | 1913 frame_data->render_pass_list.push_back(std::move(pass)); |
| 1914 CompositorFrame frame; | 1914 CompositorFrame frame; |
| 1915 frame.delegated_frame_data = std::move(frame_data); | 1915 frame.delegated_frame_data = std::move(frame_data); |
| 1916 factory->SubmitCompositorFrame(surface_id, std::move(frame), | 1916 factory->SubmitCompositorFrame(surface_id, std::move(frame), |
| 1917 SurfaceFactory::DrawCallback()); | 1917 SurfaceFactory::DrawCallback()); |
| 1918 } | 1918 } |
| 1919 | 1919 |
| 1920 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { | 1920 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { |
| 1921 ResourceTrackingSurfaceFactoryClient client; | 1921 ResourceTrackingSurfaceFactoryClient client; |
| 1922 SurfaceFactory factory(&manager_, &client); | 1922 SurfaceFactory factory(kArbitraryClientId, &manager_, &client); |
| 1923 SurfaceId surface_id(kArbitraryClientId, 7u, 0); | 1923 SurfaceId surface_id(kArbitraryClientId, 7u, 0); |
| 1924 factory.Create(surface_id); | 1924 factory.Create(surface_id); |
| 1925 | 1925 |
| 1926 ResourceId ids[] = {11, 12, 13}; | 1926 ResourceId ids[] = {11, 12, 13}; |
| 1927 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1927 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 1928 &factory, surface_id); | 1928 &factory, surface_id); |
| 1929 | 1929 |
| 1930 CompositorFrame frame = aggregator_->Aggregate(surface_id); | 1930 CompositorFrame frame = aggregator_->Aggregate(surface_id); |
| 1931 | 1931 |
| 1932 // Nothing should be available to be returned yet. | 1932 // Nothing should be available to be returned yet. |
| 1933 EXPECT_TRUE(client.returned_resources().empty()); | 1933 EXPECT_TRUE(client.returned_resources().empty()); |
| 1934 | 1934 |
| 1935 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, | 1935 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, |
| 1936 surface_id); | 1936 surface_id); |
| 1937 | 1937 |
| 1938 frame = aggregator_->Aggregate(surface_id); | 1938 frame = aggregator_->Aggregate(surface_id); |
| 1939 | 1939 |
| 1940 ASSERT_EQ(3u, client.returned_resources().size()); | 1940 ASSERT_EQ(3u, client.returned_resources().size()); |
| 1941 ResourceId returned_ids[3]; | 1941 ResourceId returned_ids[3]; |
| 1942 for (size_t i = 0; i < 3; ++i) { | 1942 for (size_t i = 0; i < 3; ++i) { |
| 1943 returned_ids[i] = client.returned_resources()[i].id; | 1943 returned_ids[i] = client.returned_resources()[i].id; |
| 1944 } | 1944 } |
| 1945 EXPECT_THAT(returned_ids, | 1945 EXPECT_THAT(returned_ids, |
| 1946 testing::WhenSorted(testing::ElementsAreArray(ids))); | 1946 testing::WhenSorted(testing::ElementsAreArray(ids))); |
| 1947 factory.Destroy(surface_id); | 1947 factory.Destroy(surface_id); |
| 1948 } | 1948 } |
| 1949 | 1949 |
| 1950 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { | 1950 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { |
| 1951 ResourceTrackingSurfaceFactoryClient client; | 1951 ResourceTrackingSurfaceFactoryClient client; |
| 1952 SurfaceFactory factory(&manager_, &client); | 1952 SurfaceFactory factory(kArbitraryClientId, &manager_, &client); |
| 1953 SurfaceId surface_id(kArbitraryClientId, 7u, 0); | 1953 SurfaceId surface_id(kArbitraryClientId, 7u, 0); |
| 1954 factory.Create(surface_id); | 1954 factory.Create(surface_id); |
| 1955 | 1955 |
| 1956 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 1956 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 1957 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 1957 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 1958 pass->id = RenderPassId(1, 1); | 1958 pass->id = RenderPassId(1, 1); |
| 1959 TransferableResource resource; | 1959 TransferableResource resource; |
| 1960 resource.id = 11; | 1960 resource.id = 11; |
| 1961 // ResourceProvider is software but resource is not, so it should be | 1961 // ResourceProvider is software but resource is not, so it should be |
| 1962 // ignored. | 1962 // ignored. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1976 SubmitCompositorFrameWithResources(NULL, 0, true, SurfaceId(), &factory, | 1976 SubmitCompositorFrameWithResources(NULL, 0, true, SurfaceId(), &factory, |
| 1977 surface_id); | 1977 surface_id); |
| 1978 ASSERT_EQ(1u, client.returned_resources().size()); | 1978 ASSERT_EQ(1u, client.returned_resources().size()); |
| 1979 EXPECT_EQ(11u, client.returned_resources()[0].id); | 1979 EXPECT_EQ(11u, client.returned_resources()[0].id); |
| 1980 | 1980 |
| 1981 factory.Destroy(surface_id); | 1981 factory.Destroy(surface_id); |
| 1982 } | 1982 } |
| 1983 | 1983 |
| 1984 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { | 1984 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { |
| 1985 ResourceTrackingSurfaceFactoryClient client; | 1985 ResourceTrackingSurfaceFactoryClient client; |
| 1986 SurfaceFactory factory(&manager_, &client); | 1986 SurfaceFactory factory(kArbitraryClientId, &manager_, &client); |
| 1987 SurfaceId surface1_id(kArbitraryClientId, 7u, 0); | 1987 SurfaceId surface1_id(kArbitraryClientId, 7u, 0); |
| 1988 factory.Create(surface1_id); | 1988 factory.Create(surface1_id); |
| 1989 | 1989 |
| 1990 SurfaceId surface2_id(kArbitraryClientId, 8u, 0); | 1990 SurfaceId surface2_id(kArbitraryClientId, 8u, 0); |
| 1991 factory.Create(surface2_id); | 1991 factory.Create(surface2_id); |
| 1992 | 1992 |
| 1993 ResourceId ids[] = {11, 12, 13}; | 1993 ResourceId ids[] = {11, 12, 13}; |
| 1994 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1994 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 1995 &factory, surface1_id); | 1995 &factory, surface1_id); |
| 1996 ResourceId ids2[] = {14, 15, 16}; | 1996 ResourceId ids2[] = {14, 15, 16}; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2017 testing::WhenSorted(testing::ElementsAreArray(ids))); | 2017 testing::WhenSorted(testing::ElementsAreArray(ids))); |
| 2018 EXPECT_EQ(3u, resource_provider_->num_resources()); | 2018 EXPECT_EQ(3u, resource_provider_->num_resources()); |
| 2019 factory.Destroy(surface1_id); | 2019 factory.Destroy(surface1_id); |
| 2020 factory.Destroy(surface2_id); | 2020 factory.Destroy(surface2_id); |
| 2021 } | 2021 } |
| 2022 | 2022 |
| 2023 // Ensure that aggregator completely ignores Surfaces that reference invalid | 2023 // Ensure that aggregator completely ignores Surfaces that reference invalid |
| 2024 // resources. | 2024 // resources. |
| 2025 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { | 2025 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { |
| 2026 ResourceTrackingSurfaceFactoryClient client; | 2026 ResourceTrackingSurfaceFactoryClient client; |
| 2027 SurfaceFactory factory(&manager_, &client); | 2027 SurfaceFactory factory(kArbitraryClientId, &manager_, &client); |
| 2028 SurfaceId root_surface_id(kArbitraryClientId, 7u, 0); | 2028 SurfaceId root_surface_id(kArbitraryClientId, 7u, 0); |
| 2029 factory.Create(root_surface_id); | 2029 factory.Create(root_surface_id); |
| 2030 SurfaceId middle_surface_id(kArbitraryClientId, 8u, 0); | 2030 SurfaceId middle_surface_id(kArbitraryClientId, 8u, 0); |
| 2031 factory.Create(middle_surface_id); | 2031 factory.Create(middle_surface_id); |
| 2032 SurfaceId child_surface_id(kArbitraryClientId, 9u, 0); | 2032 SurfaceId child_surface_id(kArbitraryClientId, 9u, 0); |
| 2033 factory.Create(child_surface_id); | 2033 factory.Create(child_surface_id); |
| 2034 | 2034 |
| 2035 ResourceId ids[] = {14, 15, 16}; | 2035 ResourceId ids[] = {14, 15, 16}; |
| 2036 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2036 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2037 &factory, child_surface_id); | 2037 &factory, child_surface_id); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2065 EXPECT_EQ(3u, pass_list->back()->shared_quad_state_list.size()); | 2065 EXPECT_EQ(3u, pass_list->back()->shared_quad_state_list.size()); |
| 2066 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); | 2066 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); |
| 2067 | 2067 |
| 2068 factory.Destroy(root_surface_id); | 2068 factory.Destroy(root_surface_id); |
| 2069 factory.Destroy(child_surface_id); | 2069 factory.Destroy(child_surface_id); |
| 2070 factory.Destroy(middle_surface_id); | 2070 factory.Destroy(middle_surface_id); |
| 2071 } | 2071 } |
| 2072 | 2072 |
| 2073 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { | 2073 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { |
| 2074 ResourceTrackingSurfaceFactoryClient client; | 2074 ResourceTrackingSurfaceFactoryClient client; |
| 2075 SurfaceFactory factory(&manager_, &client); | 2075 SurfaceFactory factory(kArbitraryClientId, &manager_, &client); |
| 2076 SurfaceId surface1_id(kArbitraryClientId, 7u, 0); | 2076 SurfaceId surface1_id(kArbitraryClientId, 7u, 0); |
| 2077 factory.Create(surface1_id); | 2077 factory.Create(surface1_id); |
| 2078 | 2078 |
| 2079 SurfaceId surface2_id(kArbitraryClientId, 8u, 0); | 2079 SurfaceId surface2_id(kArbitraryClientId, 8u, 0); |
| 2080 factory.Create(surface2_id); | 2080 factory.Create(surface2_id); |
| 2081 | 2081 |
| 2082 ResourceId ids[] = {11, 12, 13}; | 2082 ResourceId ids[] = {11, 12, 13}; |
| 2083 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2083 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2084 &factory, surface1_id); | 2084 &factory, surface1_id); |
| 2085 | 2085 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2132 // Output is insecure, so texture should be drawn. | 2132 // Output is insecure, so texture should be drawn. |
| 2133 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); | 2133 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); |
| 2134 | 2134 |
| 2135 factory.Destroy(surface1_id); | 2135 factory.Destroy(surface1_id); |
| 2136 factory.Destroy(surface2_id); | 2136 factory.Destroy(surface2_id); |
| 2137 } | 2137 } |
| 2138 | 2138 |
| 2139 } // namespace | 2139 } // namespace |
| 2140 } // namespace cc | 2140 } // namespace cc |
| 2141 | 2141 |
| OLD | NEW |