| 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 20 matching lines...) Expand all Loading... |
| 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 SurfaceId InvalidSurfaceId() { | 40 SurfaceId InvalidSurfaceId() { |
| 41 static SurfaceId invalid; | 41 static SurfaceId invalid(0, 0xdeadbeef, 0); |
| 42 invalid.id = static_cast<uint64_t>(-1); | |
| 43 return invalid; | 42 return invalid; |
| 44 } | 43 } |
| 45 | 44 |
| 46 gfx::Size SurfaceSize() { | 45 gfx::Size SurfaceSize() { |
| 47 static gfx::Size size(100, 100); | 46 static gfx::Size size(100, 100); |
| 48 return size; | 47 return size; |
| 49 } | 48 } |
| 50 | 49 |
| 51 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 50 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
| 52 public: | 51 public: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} | 71 SurfaceAggregatorTest() : SurfaceAggregatorTest(false) {} |
| 73 | 72 |
| 74 protected: | 73 protected: |
| 75 SurfaceManager manager_; | 74 SurfaceManager manager_; |
| 76 EmptySurfaceFactoryClient empty_client_; | 75 EmptySurfaceFactoryClient empty_client_; |
| 77 SurfaceFactory factory_; | 76 SurfaceFactory factory_; |
| 78 SurfaceAggregator aggregator_; | 77 SurfaceAggregator aggregator_; |
| 79 }; | 78 }; |
| 80 | 79 |
| 81 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { | 80 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { |
| 82 SurfaceId one_id(7); | 81 SurfaceId one_id(0, 7, 0); |
| 83 factory_.Create(one_id); | 82 factory_.Create(one_id); |
| 84 | 83 |
| 85 std::unique_ptr<CompositorFrame> frame = aggregator_.Aggregate(one_id); | 84 std::unique_ptr<CompositorFrame> frame = aggregator_.Aggregate(one_id); |
| 86 EXPECT_FALSE(frame); | 85 EXPECT_FALSE(frame); |
| 87 | 86 |
| 88 factory_.Destroy(one_id); | 87 factory_.Destroy(one_id); |
| 89 } | 88 } |
| 90 | 89 |
| 91 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { | 90 class SurfaceAggregatorValidSurfaceTest : public SurfaceAggregatorTest { |
| 92 public: | 91 public: |
| (...skipping 1861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 frame_data->render_pass_list.push_back(std::move(pass)); | 1953 frame_data->render_pass_list.push_back(std::move(pass)); |
| 1955 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); | 1954 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
| 1956 frame->delegated_frame_data = std::move(frame_data); | 1955 frame->delegated_frame_data = std::move(frame_data); |
| 1957 factory->SubmitCompositorFrame(surface_id, std::move(frame), | 1956 factory->SubmitCompositorFrame(surface_id, std::move(frame), |
| 1958 SurfaceFactory::DrawCallback()); | 1957 SurfaceFactory::DrawCallback()); |
| 1959 } | 1958 } |
| 1960 | 1959 |
| 1961 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { | 1960 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { |
| 1962 ResourceTrackingSurfaceFactoryClient client; | 1961 ResourceTrackingSurfaceFactoryClient client; |
| 1963 SurfaceFactory factory(&manager_, &client); | 1962 SurfaceFactory factory(&manager_, &client); |
| 1964 SurfaceId surface_id(7u); | 1963 SurfaceId surface_id(0, 7u, 0); |
| 1965 factory.Create(surface_id); | 1964 factory.Create(surface_id); |
| 1966 | 1965 |
| 1967 ResourceId ids[] = {11, 12, 13}; | 1966 ResourceId ids[] = {11, 12, 13}; |
| 1968 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1967 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 1969 &factory, surface_id); | 1968 &factory, surface_id); |
| 1970 | 1969 |
| 1971 std::unique_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id); | 1970 std::unique_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id); |
| 1972 | 1971 |
| 1973 // Nothing should be available to be returned yet. | 1972 // Nothing should be available to be returned yet. |
| 1974 EXPECT_TRUE(client.returned_resources().empty()); | 1973 EXPECT_TRUE(client.returned_resources().empty()); |
| 1975 | 1974 |
| 1976 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, | 1975 SubmitCompositorFrameWithResources(NULL, 0u, true, SurfaceId(), &factory, |
| 1977 surface_id); | 1976 surface_id); |
| 1978 | 1977 |
| 1979 frame = aggregator_->Aggregate(surface_id); | 1978 frame = aggregator_->Aggregate(surface_id); |
| 1980 | 1979 |
| 1981 ASSERT_EQ(3u, client.returned_resources().size()); | 1980 ASSERT_EQ(3u, client.returned_resources().size()); |
| 1982 ResourceId returned_ids[3]; | 1981 ResourceId returned_ids[3]; |
| 1983 for (size_t i = 0; i < 3; ++i) { | 1982 for (size_t i = 0; i < 3; ++i) { |
| 1984 returned_ids[i] = client.returned_resources()[i].id; | 1983 returned_ids[i] = client.returned_resources()[i].id; |
| 1985 } | 1984 } |
| 1986 EXPECT_THAT(returned_ids, | 1985 EXPECT_THAT(returned_ids, |
| 1987 testing::WhenSorted(testing::ElementsAreArray(ids))); | 1986 testing::WhenSorted(testing::ElementsAreArray(ids))); |
| 1988 factory.Destroy(surface_id); | 1987 factory.Destroy(surface_id); |
| 1989 } | 1988 } |
| 1990 | 1989 |
| 1991 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { | 1990 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { |
| 1992 ResourceTrackingSurfaceFactoryClient client; | 1991 ResourceTrackingSurfaceFactoryClient client; |
| 1993 SurfaceFactory factory(&manager_, &client); | 1992 SurfaceFactory factory(&manager_, &client); |
| 1994 SurfaceId surface_id(7u); | 1993 SurfaceId surface_id(0, 7u, 0); |
| 1995 factory.Create(surface_id); | 1994 factory.Create(surface_id); |
| 1996 | 1995 |
| 1997 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 1996 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 1998 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 1997 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
| 1999 pass->id = RenderPassId(1, 1); | 1998 pass->id = RenderPassId(1, 1); |
| 2000 TransferableResource resource; | 1999 TransferableResource resource; |
| 2001 resource.id = 11; | 2000 resource.id = 11; |
| 2002 // ResourceProvider is software but resource is not, so it should be | 2001 // ResourceProvider is software but resource is not, so it should be |
| 2003 // ignored. | 2002 // ignored. |
| 2004 resource.is_software = false; | 2003 resource.is_software = false; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2019 surface_id); | 2018 surface_id); |
| 2020 ASSERT_EQ(1u, client.returned_resources().size()); | 2019 ASSERT_EQ(1u, client.returned_resources().size()); |
| 2021 EXPECT_EQ(11u, client.returned_resources()[0].id); | 2020 EXPECT_EQ(11u, client.returned_resources()[0].id); |
| 2022 | 2021 |
| 2023 factory.Destroy(surface_id); | 2022 factory.Destroy(surface_id); |
| 2024 } | 2023 } |
| 2025 | 2024 |
| 2026 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { | 2025 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { |
| 2027 ResourceTrackingSurfaceFactoryClient client; | 2026 ResourceTrackingSurfaceFactoryClient client; |
| 2028 SurfaceFactory factory(&manager_, &client); | 2027 SurfaceFactory factory(&manager_, &client); |
| 2029 SurfaceId surface1_id(7u); | 2028 SurfaceId surface1_id(0, 7u, 0); |
| 2030 factory.Create(surface1_id); | 2029 factory.Create(surface1_id); |
| 2031 | 2030 |
| 2032 SurfaceId surface2_id(8u); | 2031 SurfaceId surface2_id(0, 8u, 0); |
| 2033 factory.Create(surface2_id); | 2032 factory.Create(surface2_id); |
| 2034 | 2033 |
| 2035 ResourceId ids[] = {11, 12, 13}; | 2034 ResourceId ids[] = {11, 12, 13}; |
| 2036 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2035 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2037 &factory, surface1_id); | 2036 &factory, surface1_id); |
| 2038 ResourceId ids2[] = {14, 15, 16}; | 2037 ResourceId ids2[] = {14, 15, 16}; |
| 2039 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), | 2038 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), |
| 2040 &factory, surface2_id); | 2039 &factory, surface2_id); |
| 2041 | 2040 |
| 2042 std::unique_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface1_id); | 2041 std::unique_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface1_id); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2060 EXPECT_EQ(3u, resource_provider_->num_resources()); | 2059 EXPECT_EQ(3u, resource_provider_->num_resources()); |
| 2061 factory.Destroy(surface1_id); | 2060 factory.Destroy(surface1_id); |
| 2062 factory.Destroy(surface2_id); | 2061 factory.Destroy(surface2_id); |
| 2063 } | 2062 } |
| 2064 | 2063 |
| 2065 // Ensure that aggregator completely ignores Surfaces that reference invalid | 2064 // Ensure that aggregator completely ignores Surfaces that reference invalid |
| 2066 // resources. | 2065 // resources. |
| 2067 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { | 2066 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { |
| 2068 ResourceTrackingSurfaceFactoryClient client; | 2067 ResourceTrackingSurfaceFactoryClient client; |
| 2069 SurfaceFactory factory(&manager_, &client); | 2068 SurfaceFactory factory(&manager_, &client); |
| 2070 SurfaceId root_surface_id(7u); | 2069 SurfaceId root_surface_id(0, 7u, 0); |
| 2071 factory.Create(root_surface_id); | 2070 factory.Create(root_surface_id); |
| 2072 SurfaceId middle_surface_id(8u); | 2071 SurfaceId middle_surface_id(0, 8u, 0); |
| 2073 factory.Create(middle_surface_id); | 2072 factory.Create(middle_surface_id); |
| 2074 SurfaceId child_surface_id(9u); | 2073 SurfaceId child_surface_id(0, 9u, 0); |
| 2075 factory.Create(child_surface_id); | 2074 factory.Create(child_surface_id); |
| 2076 | 2075 |
| 2077 ResourceId ids[] = {14, 15, 16}; | 2076 ResourceId ids[] = {14, 15, 16}; |
| 2078 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2077 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2079 &factory, child_surface_id); | 2078 &factory, child_surface_id); |
| 2080 | 2079 |
| 2081 ResourceId ids2[] = {17, 18, 19}; | 2080 ResourceId ids2[] = {17, 18, 19}; |
| 2082 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, | 2081 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, |
| 2083 child_surface_id, &factory, | 2082 child_surface_id, &factory, |
| 2084 middle_surface_id); | 2083 middle_surface_id); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2108 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); | 2107 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); |
| 2109 | 2108 |
| 2110 factory.Destroy(root_surface_id); | 2109 factory.Destroy(root_surface_id); |
| 2111 factory.Destroy(child_surface_id); | 2110 factory.Destroy(child_surface_id); |
| 2112 factory.Destroy(middle_surface_id); | 2111 factory.Destroy(middle_surface_id); |
| 2113 } | 2112 } |
| 2114 | 2113 |
| 2115 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { | 2114 TEST_F(SurfaceAggregatorWithResourcesTest, SecureOutputTexture) { |
| 2116 ResourceTrackingSurfaceFactoryClient client; | 2115 ResourceTrackingSurfaceFactoryClient client; |
| 2117 SurfaceFactory factory(&manager_, &client); | 2116 SurfaceFactory factory(&manager_, &client); |
| 2118 SurfaceId surface1_id(7u); | 2117 SurfaceId surface1_id(0, 7u, 0); |
| 2119 factory.Create(surface1_id); | 2118 factory.Create(surface1_id); |
| 2120 | 2119 |
| 2121 SurfaceId surface2_id(8u); | 2120 SurfaceId surface2_id(0, 8u, 0); |
| 2122 factory.Create(surface2_id); | 2121 factory.Create(surface2_id); |
| 2123 | 2122 |
| 2124 ResourceId ids[] = {11, 12, 13}; | 2123 ResourceId ids[] = {11, 12, 13}; |
| 2125 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2124 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2126 &factory, surface1_id); | 2125 &factory, surface1_id); |
| 2127 | 2126 |
| 2128 std::unique_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface1_id); | 2127 std::unique_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface1_id); |
| 2129 | 2128 |
| 2130 RenderPass* render_pass = | 2129 RenderPass* render_pass = |
| 2131 frame->delegated_frame_data->render_pass_list.back().get(); | 2130 frame->delegated_frame_data->render_pass_list.back().get(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 // Output is insecure, so texture should be drawn. | 2173 // Output is insecure, so texture should be drawn. |
| 2175 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); | 2174 EXPECT_EQ(DrawQuad::SOLID_COLOR, render_pass->quad_list.back()->material); |
| 2176 | 2175 |
| 2177 factory.Destroy(surface1_id); | 2176 factory.Destroy(surface1_id); |
| 2178 factory.Destroy(surface2_id); | 2177 factory.Destroy(surface2_id); |
| 2179 } | 2178 } |
| 2180 | 2179 |
| 2181 } // namespace | 2180 } // namespace |
| 2182 } // namespace cc | 2181 } // namespace cc |
| 2183 | 2182 |
| OLD | NEW |