| 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 <limits> |
| 10 #include <utility> | 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "cc/output/compositor_frame.h" | 14 #include "cc/output/compositor_frame.h" |
| 14 #include "cc/output/delegated_frame_data.h" | 15 #include "cc/output/delegated_frame_data.h" |
| 15 #include "cc/quads/render_pass.h" | 16 #include "cc/quads/render_pass.h" |
| 16 #include "cc/quads/render_pass_draw_quad.h" | 17 #include "cc/quads/render_pass_draw_quad.h" |
| 17 #include "cc/quads/solid_color_draw_quad.h" | 18 #include "cc/quads/solid_color_draw_quad.h" |
| 18 #include "cc/quads/surface_draw_quad.h" | 19 #include "cc/quads/surface_draw_quad.h" |
| 19 #include "cc/quads/texture_draw_quad.h" | 20 #include "cc/quads/texture_draw_quad.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 30 #include "cc/test/surface_aggregator_test_helpers.h" | 31 #include "cc/test/surface_aggregator_test_helpers.h" |
| 31 #include "cc/test/test_shared_bitmap_manager.h" | 32 #include "cc/test/test_shared_bitmap_manager.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "third_party/skia/include/core/SkColor.h" | 35 #include "third_party/skia/include/core/SkColor.h" |
| 35 | 36 |
| 36 namespace cc { | 37 namespace cc { |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 SurfaceId InvalidSurfaceId() { | 40 SurfaceId InvalidSurfaceId() { |
| 40 static SurfaceId invalid; | 41 return SurfaceId::FromUnsafeValue(std::numeric_limits<uint64_t>::max()); |
| 41 invalid.id = static_cast<uint64_t>(-1); | |
| 42 return invalid; | |
| 43 } | 42 } |
| 44 | 43 |
| 45 gfx::Size SurfaceSize() { | 44 gfx::Size SurfaceSize() { |
| 46 static gfx::Size size(5, 5); | 45 static gfx::Size size(5, 5); |
| 47 return size; | 46 return size; |
| 48 } | 47 } |
| 49 | 48 |
| 50 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 49 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
| 51 public: | 50 public: |
| 52 void ReturnResources(const ReturnedResourceArray& resources) override {} | 51 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 95 |
| 97 protected: | 96 protected: |
| 98 SurfaceManager manager_; | 97 SurfaceManager manager_; |
| 99 EmptySurfaceFactoryClient empty_client_; | 98 EmptySurfaceFactoryClient empty_client_; |
| 100 SurfaceFactory factory_; | 99 SurfaceFactory factory_; |
| 101 FakeSurfaceAggregatorClient surface_aggregator_client_; | 100 FakeSurfaceAggregatorClient surface_aggregator_client_; |
| 102 SurfaceAggregator aggregator_; | 101 SurfaceAggregator aggregator_; |
| 103 }; | 102 }; |
| 104 | 103 |
| 105 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { | 104 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { |
| 106 SurfaceId one_id(7); | 105 SurfaceId one_id = SurfaceId::FromUnsafeValue(7); |
| 107 factory_.Create(one_id); | 106 factory_.Create(one_id); |
| 108 Surface* surface = manager_.GetSurfaceForId(one_id); | 107 Surface* surface = manager_.GetSurfaceForId(one_id); |
| 109 | 108 |
| 110 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); | 109 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); |
| 111 scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(one_id); | 110 scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(one_id); |
| 112 EXPECT_FALSE(frame); | 111 EXPECT_FALSE(frame); |
| 113 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); | 112 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); |
| 114 | 113 |
| 115 factory_.Destroy(one_id); | 114 factory_.Destroy(one_id); |
| 116 } | 115 } |
| (...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1924 frame_data->render_pass_list.push_back(std::move(pass)); | 1923 frame_data->render_pass_list.push_back(std::move(pass)); |
| 1925 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 1924 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 1926 frame->delegated_frame_data = std::move(frame_data); | 1925 frame->delegated_frame_data = std::move(frame_data); |
| 1927 factory->SubmitCompositorFrame(surface_id, std::move(frame), | 1926 factory->SubmitCompositorFrame(surface_id, std::move(frame), |
| 1928 SurfaceFactory::DrawCallback()); | 1927 SurfaceFactory::DrawCallback()); |
| 1929 } | 1928 } |
| 1930 | 1929 |
| 1931 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { | 1930 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { |
| 1932 ResourceTrackingSurfaceFactoryClient client; | 1931 ResourceTrackingSurfaceFactoryClient client; |
| 1933 SurfaceFactory factory(&manager_, &client); | 1932 SurfaceFactory factory(&manager_, &client); |
| 1934 SurfaceId surface_id(7u); | 1933 SurfaceId surface_id = SurfaceId::FromUnsafeValue(7u); |
| 1935 factory.Create(surface_id); | 1934 factory.Create(surface_id); |
| 1936 Surface* surface = manager_.GetSurfaceForId(surface_id); | 1935 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 1937 | 1936 |
| 1938 ResourceId ids[] = {11, 12, 13}; | 1937 ResourceId ids[] = {11, 12, 13}; |
| 1939 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1938 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 1940 &factory, surface_id); | 1939 &factory, surface_id); |
| 1941 | 1940 |
| 1942 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); | 1941 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); |
| 1943 | 1942 |
| 1944 scoped_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id); | 1943 scoped_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1963 returned_ids[i] = client.returned_resources()[i].id; | 1962 returned_ids[i] = client.returned_resources()[i].id; |
| 1964 } | 1963 } |
| 1965 EXPECT_THAT(returned_ids, | 1964 EXPECT_THAT(returned_ids, |
| 1966 testing::WhenSorted(testing::ElementsAreArray(ids))); | 1965 testing::WhenSorted(testing::ElementsAreArray(ids))); |
| 1967 factory.Destroy(surface_id); | 1966 factory.Destroy(surface_id); |
| 1968 } | 1967 } |
| 1969 | 1968 |
| 1970 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { | 1969 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { |
| 1971 ResourceTrackingSurfaceFactoryClient client; | 1970 ResourceTrackingSurfaceFactoryClient client; |
| 1972 SurfaceFactory factory(&manager_, &client); | 1971 SurfaceFactory factory(&manager_, &client); |
| 1973 SurfaceId surface_id(7u); | 1972 SurfaceId surface_id = SurfaceId::FromUnsafeValue(7u); |
| 1974 factory.Create(surface_id); | 1973 factory.Create(surface_id); |
| 1975 Surface* surface = manager_.GetSurfaceForId(surface_id); | 1974 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 1976 | 1975 |
| 1977 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 1976 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 1978 scoped_ptr<RenderPass> pass = RenderPass::Create(); | 1977 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 1979 pass->id = RenderPassId(1, 1); | 1978 pass->id = RenderPassId(1, 1); |
| 1980 TransferableResource resource; | 1979 TransferableResource resource; |
| 1981 resource.id = 11; | 1980 resource.id = 11; |
| 1982 // ResourceProvider is software but resource is not, so it should be | 1981 // ResourceProvider is software but resource is not, so it should be |
| 1983 // ignored. | 1982 // ignored. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2003 surface_id); | 2002 surface_id); |
| 2004 ASSERT_EQ(1u, client.returned_resources().size()); | 2003 ASSERT_EQ(1u, client.returned_resources().size()); |
| 2005 EXPECT_EQ(11u, client.returned_resources()[0].id); | 2004 EXPECT_EQ(11u, client.returned_resources()[0].id); |
| 2006 | 2005 |
| 2007 factory.Destroy(surface_id); | 2006 factory.Destroy(surface_id); |
| 2008 } | 2007 } |
| 2009 | 2008 |
| 2010 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { | 2009 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { |
| 2011 ResourceTrackingSurfaceFactoryClient client; | 2010 ResourceTrackingSurfaceFactoryClient client; |
| 2012 SurfaceFactory factory(&manager_, &client); | 2011 SurfaceFactory factory(&manager_, &client); |
| 2013 SurfaceId surface1_id(7u); | 2012 SurfaceId surface1_id = SurfaceId::FromUnsafeValue(7u); |
| 2014 factory.Create(surface1_id); | 2013 factory.Create(surface1_id); |
| 2015 Surface* surface1 = manager_.GetSurfaceForId(surface1_id); | 2014 Surface* surface1 = manager_.GetSurfaceForId(surface1_id); |
| 2016 | 2015 |
| 2017 SurfaceId surface2_id(8u); | 2016 SurfaceId surface2_id = SurfaceId::FromUnsafeValue(8u); |
| 2018 factory.Create(surface2_id); | 2017 factory.Create(surface2_id); |
| 2019 Surface* surface2 = manager_.GetSurfaceForId(surface2_id); | 2018 Surface* surface2 = manager_.GetSurfaceForId(surface2_id); |
| 2020 | 2019 |
| 2021 ResourceId ids[] = {11, 12, 13}; | 2020 ResourceId ids[] = {11, 12, 13}; |
| 2022 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2021 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2023 &factory, surface1_id); | 2022 &factory, surface1_id); |
| 2024 ResourceId ids2[] = {14, 15, 16}; | 2023 ResourceId ids2[] = {14, 15, 16}; |
| 2025 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), | 2024 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), |
| 2026 &factory, surface2_id); | 2025 &factory, surface2_id); |
| 2027 | 2026 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2058 EXPECT_EQ(3u, resource_provider_->num_resources()); | 2057 EXPECT_EQ(3u, resource_provider_->num_resources()); |
| 2059 factory.Destroy(surface1_id); | 2058 factory.Destroy(surface1_id); |
| 2060 factory.Destroy(surface2_id); | 2059 factory.Destroy(surface2_id); |
| 2061 } | 2060 } |
| 2062 | 2061 |
| 2063 // Ensure that aggregator completely ignores Surfaces that reference invalid | 2062 // Ensure that aggregator completely ignores Surfaces that reference invalid |
| 2064 // resources. | 2063 // resources. |
| 2065 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { | 2064 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { |
| 2066 ResourceTrackingSurfaceFactoryClient client; | 2065 ResourceTrackingSurfaceFactoryClient client; |
| 2067 SurfaceFactory factory(&manager_, &client); | 2066 SurfaceFactory factory(&manager_, &client); |
| 2068 SurfaceId root_surface_id(7u); | 2067 SurfaceId root_surface_id = SurfaceId::FromUnsafeValue(7u); |
| 2069 factory.Create(root_surface_id); | 2068 factory.Create(root_surface_id); |
| 2070 Surface* root_surface = manager_.GetSurfaceForId(root_surface_id); | 2069 Surface* root_surface = manager_.GetSurfaceForId(root_surface_id); |
| 2071 SurfaceId middle_surface_id(8u); | 2070 SurfaceId middle_surface_id = SurfaceId::FromUnsafeValue(8u); |
| 2072 factory.Create(middle_surface_id); | 2071 factory.Create(middle_surface_id); |
| 2073 Surface* middle_surface = manager_.GetSurfaceForId(middle_surface_id); | 2072 Surface* middle_surface = manager_.GetSurfaceForId(middle_surface_id); |
| 2074 SurfaceId child_surface_id(9u); | 2073 SurfaceId child_surface_id = SurfaceId::FromUnsafeValue(9u); |
| 2075 factory.Create(child_surface_id); | 2074 factory.Create(child_surface_id); |
| 2076 Surface* child_surface = manager_.GetSurfaceForId(child_surface_id); | 2075 Surface* child_surface = manager_.GetSurfaceForId(child_surface_id); |
| 2077 | 2076 |
| 2078 ResourceId ids[] = {14, 15, 16}; | 2077 ResourceId ids[] = {14, 15, 16}; |
| 2079 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 2078 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 2080 &factory, child_surface_id); | 2079 &factory, child_surface_id); |
| 2081 | 2080 |
| 2082 ResourceId ids2[] = {17, 18, 19}; | 2081 ResourceId ids2[] = {17, 18, 19}; |
| 2083 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, | 2082 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, |
| 2084 child_surface_id, &factory, | 2083 child_surface_id, &factory, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2125 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); | 2124 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); |
| 2126 | 2125 |
| 2127 factory.Destroy(root_surface_id); | 2126 factory.Destroy(root_surface_id); |
| 2128 factory.Destroy(child_surface_id); | 2127 factory.Destroy(child_surface_id); |
| 2129 factory.Destroy(middle_surface_id); | 2128 factory.Destroy(middle_surface_id); |
| 2130 } | 2129 } |
| 2131 | 2130 |
| 2132 } // namespace | 2131 } // namespace |
| 2133 } // namespace cc | 2132 } // namespace cc |
| 2134 | 2133 |
| OLD | NEW |