| 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 <limits> |
| 6 |
| 5 #include "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
| 6 #include "cc/output/delegated_frame_data.h" | 8 #include "cc/output/delegated_frame_data.h" |
| 7 #include "cc/quads/render_pass.h" | 9 #include "cc/quads/render_pass.h" |
| 8 #include "cc/quads/render_pass_draw_quad.h" | 10 #include "cc/quads/render_pass_draw_quad.h" |
| 9 #include "cc/quads/solid_color_draw_quad.h" | 11 #include "cc/quads/solid_color_draw_quad.h" |
| 10 #include "cc/quads/surface_draw_quad.h" | 12 #include "cc/quads/surface_draw_quad.h" |
| 11 #include "cc/quads/texture_draw_quad.h" | 13 #include "cc/quads/texture_draw_quad.h" |
| 12 #include "cc/resources/shared_bitmap_manager.h" | 14 #include "cc/resources/shared_bitmap_manager.h" |
| 13 #include "cc/surfaces/surface.h" | 15 #include "cc/surfaces/surface.h" |
| 14 #include "cc/surfaces/surface_aggregator.h" | 16 #include "cc/surfaces/surface_aggregator.h" |
| 15 #include "cc/surfaces/surface_factory.h" | 17 #include "cc/surfaces/surface_factory.h" |
| 16 #include "cc/surfaces/surface_factory_client.h" | 18 #include "cc/surfaces/surface_factory_client.h" |
| 17 #include "cc/surfaces/surface_id_allocator.h" | 19 #include "cc/surfaces/surface_id_allocator.h" |
| 18 #include "cc/surfaces/surface_manager.h" | 20 #include "cc/surfaces/surface_manager.h" |
| 19 #include "cc/test/fake_output_surface.h" | 21 #include "cc/test/fake_output_surface.h" |
| 20 #include "cc/test/fake_output_surface_client.h" | 22 #include "cc/test/fake_output_surface_client.h" |
| 21 #include "cc/test/fake_resource_provider.h" | 23 #include "cc/test/fake_resource_provider.h" |
| 22 #include "cc/test/render_pass_test_utils.h" | 24 #include "cc/test/render_pass_test_utils.h" |
| 23 #include "cc/test/surface_aggregator_test_helpers.h" | 25 #include "cc/test/surface_aggregator_test_helpers.h" |
| 24 #include "cc/test/test_shared_bitmap_manager.h" | 26 #include "cc/test/test_shared_bitmap_manager.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "third_party/skia/include/core/SkColor.h" | 29 #include "third_party/skia/include/core/SkColor.h" |
| 28 | 30 |
| 29 namespace cc { | 31 namespace cc { |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 SurfaceId InvalidSurfaceId() { | 34 SurfaceId InvalidSurfaceId() { |
| 33 static SurfaceId invalid; | 35 return SurfaceId::FromUnsafeValue(std::numeric_limits<uint64_t>::max()); |
| 34 invalid.id = static_cast<uint64_t>(-1); | |
| 35 return invalid; | |
| 36 } | 36 } |
| 37 | 37 |
| 38 gfx::Size SurfaceSize() { | 38 gfx::Size SurfaceSize() { |
| 39 static gfx::Size size(5, 5); | 39 static gfx::Size size(5, 5); |
| 40 return size; | 40 return size; |
| 41 } | 41 } |
| 42 | 42 |
| 43 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { | 43 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
| 44 public: | 44 public: |
| 45 void ReturnResources(const ReturnedResourceArray& resources) override {} | 45 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 protected: | 82 protected: |
| 83 SurfaceManager manager_; | 83 SurfaceManager manager_; |
| 84 EmptySurfaceFactoryClient empty_client_; | 84 EmptySurfaceFactoryClient empty_client_; |
| 85 SurfaceFactory factory_; | 85 SurfaceFactory factory_; |
| 86 FakeSurfaceAggregatorClient surface_aggregator_client_; | 86 FakeSurfaceAggregatorClient surface_aggregator_client_; |
| 87 SurfaceAggregator aggregator_; | 87 SurfaceAggregator aggregator_; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { | 90 TEST_F(SurfaceAggregatorTest, ValidSurfaceNoFrame) { |
| 91 SurfaceId one_id(7); | 91 SurfaceId one_id = SurfaceId::FromUnsafeValue(7); |
| 92 factory_.Create(one_id); | 92 factory_.Create(one_id); |
| 93 Surface* surface = manager_.GetSurfaceForId(one_id); | 93 Surface* surface = manager_.GetSurfaceForId(one_id); |
| 94 | 94 |
| 95 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); | 95 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); |
| 96 scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(one_id); | 96 scoped_ptr<CompositorFrame> frame = aggregator_.Aggregate(one_id); |
| 97 EXPECT_FALSE(frame); | 97 EXPECT_FALSE(frame); |
| 98 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); | 98 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); |
| 99 | 99 |
| 100 factory_.Destroy(one_id); | 100 factory_.Destroy(one_id); |
| 101 } | 101 } |
| (...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1799 frame_data->render_pass_list.push_back(std::move(pass)); | 1799 frame_data->render_pass_list.push_back(std::move(pass)); |
| 1800 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 1800 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 1801 frame->delegated_frame_data = std::move(frame_data); | 1801 frame->delegated_frame_data = std::move(frame_data); |
| 1802 factory->SubmitCompositorFrame(surface_id, std::move(frame), | 1802 factory->SubmitCompositorFrame(surface_id, std::move(frame), |
| 1803 SurfaceFactory::DrawCallback()); | 1803 SurfaceFactory::DrawCallback()); |
| 1804 } | 1804 } |
| 1805 | 1805 |
| 1806 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { | 1806 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { |
| 1807 ResourceTrackingSurfaceFactoryClient client; | 1807 ResourceTrackingSurfaceFactoryClient client; |
| 1808 SurfaceFactory factory(&manager_, &client); | 1808 SurfaceFactory factory(&manager_, &client); |
| 1809 SurfaceId surface_id(7u); | 1809 SurfaceId surface_id = SurfaceId::FromUnsafeValue(7u); |
| 1810 factory.Create(surface_id); | 1810 factory.Create(surface_id); |
| 1811 Surface* surface = manager_.GetSurfaceForId(surface_id); | 1811 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 1812 | 1812 |
| 1813 ResourceId ids[] = {11, 12, 13}; | 1813 ResourceId ids[] = {11, 12, 13}; |
| 1814 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1814 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 1815 &factory, surface_id); | 1815 &factory, surface_id); |
| 1816 | 1816 |
| 1817 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); | 1817 EXPECT_FALSE(surface_aggregator_client_.HasSurface(surface)); |
| 1818 | 1818 |
| 1819 scoped_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id); | 1819 scoped_ptr<CompositorFrame> frame = aggregator_->Aggregate(surface_id); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1838 returned_ids[i] = client.returned_resources()[i].id; | 1838 returned_ids[i] = client.returned_resources()[i].id; |
| 1839 } | 1839 } |
| 1840 EXPECT_THAT(returned_ids, | 1840 EXPECT_THAT(returned_ids, |
| 1841 testing::WhenSorted(testing::ElementsAreArray(ids))); | 1841 testing::WhenSorted(testing::ElementsAreArray(ids))); |
| 1842 factory.Destroy(surface_id); | 1842 factory.Destroy(surface_id); |
| 1843 } | 1843 } |
| 1844 | 1844 |
| 1845 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { | 1845 TEST_F(SurfaceAggregatorWithResourcesTest, TakeInvalidResources) { |
| 1846 ResourceTrackingSurfaceFactoryClient client; | 1846 ResourceTrackingSurfaceFactoryClient client; |
| 1847 SurfaceFactory factory(&manager_, &client); | 1847 SurfaceFactory factory(&manager_, &client); |
| 1848 SurfaceId surface_id(7u); | 1848 SurfaceId surface_id = SurfaceId::FromUnsafeValue(7u); |
| 1849 factory.Create(surface_id); | 1849 factory.Create(surface_id); |
| 1850 Surface* surface = manager_.GetSurfaceForId(surface_id); | 1850 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 1851 | 1851 |
| 1852 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 1852 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 1853 scoped_ptr<RenderPass> pass = RenderPass::Create(); | 1853 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 1854 pass->id = RenderPassId(1, 1); | 1854 pass->id = RenderPassId(1, 1); |
| 1855 TransferableResource resource; | 1855 TransferableResource resource; |
| 1856 resource.id = 11; | 1856 resource.id = 11; |
| 1857 // ResourceProvider is software but resource is not, so it should be | 1857 // ResourceProvider is software but resource is not, so it should be |
| 1858 // ignored. | 1858 // ignored. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1878 surface_id); | 1878 surface_id); |
| 1879 ASSERT_EQ(1u, client.returned_resources().size()); | 1879 ASSERT_EQ(1u, client.returned_resources().size()); |
| 1880 EXPECT_EQ(11u, client.returned_resources()[0].id); | 1880 EXPECT_EQ(11u, client.returned_resources()[0].id); |
| 1881 | 1881 |
| 1882 factory.Destroy(surface_id); | 1882 factory.Destroy(surface_id); |
| 1883 } | 1883 } |
| 1884 | 1884 |
| 1885 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { | 1885 TEST_F(SurfaceAggregatorWithResourcesTest, TwoSurfaces) { |
| 1886 ResourceTrackingSurfaceFactoryClient client; | 1886 ResourceTrackingSurfaceFactoryClient client; |
| 1887 SurfaceFactory factory(&manager_, &client); | 1887 SurfaceFactory factory(&manager_, &client); |
| 1888 SurfaceId surface1_id(7u); | 1888 SurfaceId surface1_id = SurfaceId::FromUnsafeValue(7u); |
| 1889 factory.Create(surface1_id); | 1889 factory.Create(surface1_id); |
| 1890 Surface* surface1 = manager_.GetSurfaceForId(surface1_id); | 1890 Surface* surface1 = manager_.GetSurfaceForId(surface1_id); |
| 1891 | 1891 |
| 1892 SurfaceId surface2_id(8u); | 1892 SurfaceId surface2_id = SurfaceId::FromUnsafeValue(8u); |
| 1893 factory.Create(surface2_id); | 1893 factory.Create(surface2_id); |
| 1894 Surface* surface2 = manager_.GetSurfaceForId(surface2_id); | 1894 Surface* surface2 = manager_.GetSurfaceForId(surface2_id); |
| 1895 | 1895 |
| 1896 ResourceId ids[] = {11, 12, 13}; | 1896 ResourceId ids[] = {11, 12, 13}; |
| 1897 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1897 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 1898 &factory, surface1_id); | 1898 &factory, surface1_id); |
| 1899 ResourceId ids2[] = {14, 15, 16}; | 1899 ResourceId ids2[] = {14, 15, 16}; |
| 1900 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), | 1900 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), true, SurfaceId(), |
| 1901 &factory, surface2_id); | 1901 &factory, surface2_id); |
| 1902 | 1902 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1933 EXPECT_EQ(3u, resource_provider_->num_resources()); | 1933 EXPECT_EQ(3u, resource_provider_->num_resources()); |
| 1934 factory.Destroy(surface1_id); | 1934 factory.Destroy(surface1_id); |
| 1935 factory.Destroy(surface2_id); | 1935 factory.Destroy(surface2_id); |
| 1936 } | 1936 } |
| 1937 | 1937 |
| 1938 // Ensure that aggregator completely ignores Surfaces that reference invalid | 1938 // Ensure that aggregator completely ignores Surfaces that reference invalid |
| 1939 // resources. | 1939 // resources. |
| 1940 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { | 1940 TEST_F(SurfaceAggregatorWithResourcesTest, InvalidChildSurface) { |
| 1941 ResourceTrackingSurfaceFactoryClient client; | 1941 ResourceTrackingSurfaceFactoryClient client; |
| 1942 SurfaceFactory factory(&manager_, &client); | 1942 SurfaceFactory factory(&manager_, &client); |
| 1943 SurfaceId root_surface_id(7u); | 1943 SurfaceId root_surface_id = SurfaceId::FromUnsafeValue(7u); |
| 1944 factory.Create(root_surface_id); | 1944 factory.Create(root_surface_id); |
| 1945 Surface* root_surface = manager_.GetSurfaceForId(root_surface_id); | 1945 Surface* root_surface = manager_.GetSurfaceForId(root_surface_id); |
| 1946 SurfaceId middle_surface_id(8u); | 1946 SurfaceId middle_surface_id = SurfaceId::FromUnsafeValue(8u); |
| 1947 factory.Create(middle_surface_id); | 1947 factory.Create(middle_surface_id); |
| 1948 Surface* middle_surface = manager_.GetSurfaceForId(middle_surface_id); | 1948 Surface* middle_surface = manager_.GetSurfaceForId(middle_surface_id); |
| 1949 SurfaceId child_surface_id(9u); | 1949 SurfaceId child_surface_id = SurfaceId::FromUnsafeValue(9u); |
| 1950 factory.Create(child_surface_id); | 1950 factory.Create(child_surface_id); |
| 1951 Surface* child_surface = manager_.GetSurfaceForId(child_surface_id); | 1951 Surface* child_surface = manager_.GetSurfaceForId(child_surface_id); |
| 1952 | 1952 |
| 1953 ResourceId ids[] = {14, 15, 16}; | 1953 ResourceId ids[] = {14, 15, 16}; |
| 1954 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), | 1954 SubmitCompositorFrameWithResources(ids, arraysize(ids), true, SurfaceId(), |
| 1955 &factory, child_surface_id); | 1955 &factory, child_surface_id); |
| 1956 | 1956 |
| 1957 ResourceId ids2[] = {17, 18, 19}; | 1957 ResourceId ids2[] = {17, 18, 19}; |
| 1958 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, | 1958 SubmitCompositorFrameWithResources(ids2, arraysize(ids2), false, |
| 1959 child_surface_id, &factory, | 1959 child_surface_id, &factory, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2000 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); | 2000 EXPECT_EQ(9u, pass_list->back()->quad_list.size()); |
| 2001 | 2001 |
| 2002 factory.Destroy(root_surface_id); | 2002 factory.Destroy(root_surface_id); |
| 2003 factory.Destroy(child_surface_id); | 2003 factory.Destroy(child_surface_id); |
| 2004 factory.Destroy(middle_surface_id); | 2004 factory.Destroy(middle_surface_id); |
| 2005 } | 2005 } |
| 2006 | 2006 |
| 2007 } // namespace | 2007 } // namespace |
| 2008 } // namespace cc | 2008 } // namespace cc |
| 2009 | 2009 |
| OLD | NEW |