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