| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "base/containers/flat_set.h" | 5 #include "base/containers/flat_set.h" |
| 6 #include "cc/surfaces/compositor_frame_sink_support.h" | 6 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 7 #include "cc/surfaces/surface_id.h" | 7 #include "cc/surfaces/surface_id.h" |
| 8 #include "cc/surfaces/surface_manager.h" | 8 #include "cc/surfaces/surface_manager.h" |
| 9 #include "cc/test/begin_frame_args_test.h" | 9 #include "cc/test/begin_frame_args_test.h" |
| 10 #include "cc/test/compositor_frame_helpers.h" | 10 #include "cc/test/compositor_frame_helpers.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 class SurfaceSynchronizationTest : public testing::Test { | 70 class SurfaceSynchronizationTest : public testing::Test { |
| 71 public: | 71 public: |
| 72 SurfaceSynchronizationTest() | 72 SurfaceSynchronizationTest() |
| 73 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES), | 73 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES), |
| 74 surface_observer_(false) {} | 74 surface_observer_(false) {} |
| 75 ~SurfaceSynchronizationTest() override {} | 75 ~SurfaceSynchronizationTest() override {} |
| 76 | 76 |
| 77 CompositorFrameSinkSupport& display_support() { return *supports_[0]; } | 77 CompositorFrameSinkSupport& display_support() { return *supports_[0]; } |
| 78 Surface* display_surface() { | 78 Surface* display_surface() { return display_support().GetCurrentSurface(); } |
| 79 return display_support().current_surface_for_testing(); | |
| 80 } | |
| 81 | 79 |
| 82 CompositorFrameSinkSupport& parent_support() { return *supports_[1]; } | 80 CompositorFrameSinkSupport& parent_support() { return *supports_[1]; } |
| 83 Surface* parent_surface() { | 81 Surface* parent_surface() { return parent_support().GetCurrentSurface(); } |
| 84 return parent_support().current_surface_for_testing(); | |
| 85 } | |
| 86 | 82 |
| 87 CompositorFrameSinkSupport& child_support1() { return *supports_[2]; } | 83 CompositorFrameSinkSupport& child_support1() { return *supports_[2]; } |
| 88 Surface* child_surface1() { | 84 Surface* child_surface1() { return child_support1().GetCurrentSurface(); } |
| 89 return child_support1().current_surface_for_testing(); | |
| 90 } | |
| 91 | 85 |
| 92 CompositorFrameSinkSupport& child_support2() { return *supports_[3]; } | 86 CompositorFrameSinkSupport& child_support2() { return *supports_[3]; } |
| 93 Surface* child_surface2() { | 87 Surface* child_surface2() { return child_support2().GetCurrentSurface(); } |
| 94 return child_support2().current_surface_for_testing(); | |
| 95 } | |
| 96 | 88 |
| 97 CompositorFrameSinkSupport& support(int index) { return *supports_[index]; } | 89 CompositorFrameSinkSupport& support(int index) { return *supports_[index]; } |
| 98 Surface* surface(int index) { | 90 Surface* surface(int index) { return support(index).GetCurrentSurface(); } |
| 99 return support(index).current_surface_for_testing(); | |
| 100 } | |
| 101 | 91 |
| 102 SurfaceManager& surface_manager() { return surface_manager_; } | 92 SurfaceManager& surface_manager() { return surface_manager_; } |
| 103 | 93 |
| 104 // Returns all the references where |surface_id| is the parent. | 94 // Returns all the references where |surface_id| is the parent. |
| 105 const base::flat_set<SurfaceId>& GetChildReferences( | 95 const base::flat_set<SurfaceId>& GetChildReferences( |
| 106 const SurfaceId& surface_id) { | 96 const SurfaceId& surface_id) { |
| 107 return surface_manager().GetSurfacesReferencedByParent(surface_id); | 97 return surface_manager().GetSurfacesReferencedByParent(surface_id); |
| 108 } | 98 } |
| 109 | 99 |
| 110 // Returns true if there is a temporary reference for |surface_id|. | 100 // Returns true if there is a temporary reference for |surface_id|. |
| (...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 // Add a reference from the parent to the child. | 1024 // Add a reference from the parent to the child. |
| 1035 parent_support().SubmitCompositorFrame( | 1025 parent_support().SubmitCompositorFrame( |
| 1036 parent_id.local_surface_id(), | 1026 parent_id.local_surface_id(), |
| 1037 MakeCompositorFrame({child_id}, {child_id}, TransferableResourceArray())); | 1027 MakeCompositorFrame({child_id}, {child_id}, TransferableResourceArray())); |
| 1038 | 1028 |
| 1039 // Attempt to destroy the child surface. The surface must still exist since | 1029 // Attempt to destroy the child surface. The surface must still exist since |
| 1040 // the parent needs it but it will be marked as destroyed. | 1030 // the parent needs it but it will be marked as destroyed. |
| 1041 child_support1().EvictCurrentSurface(); | 1031 child_support1().EvictCurrentSurface(); |
| 1042 surface = surface_manager().GetSurfaceForId(child_id); | 1032 surface = surface_manager().GetSurfaceForId(child_id); |
| 1043 EXPECT_NE(nullptr, surface); | 1033 EXPECT_NE(nullptr, surface); |
| 1044 EXPECT_TRUE(surface->destroyed()); | 1034 EXPECT_TRUE(surface_manager().IsMarkedForDestruction(child_id)); |
| 1045 | 1035 |
| 1046 // Child submits another frame to the same local surface id that is marked | 1036 // Child submits another frame to the same local surface id that is marked |
| 1047 // destroyed. | 1037 // destroyed. |
| 1048 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | 1038 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), |
| 1049 MakeCompositorFrame()); | 1039 MakeCompositorFrame()); |
| 1050 | 1040 |
| 1051 // Verify that the surface that was marked destroyed is recovered and is being | 1041 // Verify that the surface that was marked destroyed is recovered and is being |
| 1052 // used again. | 1042 // used again. |
| 1053 Surface* surface2 = surface_manager().GetSurfaceForId(child_id); | 1043 Surface* surface2 = surface_manager().GetSurfaceForId(child_id); |
| 1054 EXPECT_EQ(surface, surface2); | 1044 EXPECT_EQ(surface, surface2); |
| 1055 EXPECT_FALSE(surface2->destroyed()); | 1045 EXPECT_FALSE(surface_manager().IsMarkedForDestruction(child_id)); |
| 1056 } | 1046 } |
| 1057 | 1047 |
| 1058 // Verifies that if a LocalSurfaceId belonged to a surface that doesn't exist | 1048 // Verifies that if a LocalSurfaceId belonged to a surface that doesn't exist |
| 1059 // anymore, it can still be reused for new surfaces. | 1049 // anymore, it can still be reused for new surfaces. |
| 1060 TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) { | 1050 TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) { |
| 1061 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); | 1051 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); |
| 1062 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); | 1052 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); |
| 1063 | 1053 |
| 1064 // Submit the first frame. Creates the surface. | 1054 // Submit the first frame. Creates the surface. |
| 1065 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), | 1055 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 DidReceiveCompositorFrameAck(Eq(returned_resources2))); | 1363 DidReceiveCompositorFrameAck(Eq(returned_resources2))); |
| 1374 child_support1().SubmitCompositorFrame( | 1364 child_support1().SubmitCompositorFrame( |
| 1375 child_id1.local_surface_id(), | 1365 child_id1.local_surface_id(), |
| 1376 MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(), | 1366 MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(), |
| 1377 {resource2})); | 1367 {resource2})); |
| 1378 testing::Mock::VerifyAndClearExpectations(&support_client_); | 1368 testing::Mock::VerifyAndClearExpectations(&support_client_); |
| 1379 } | 1369 } |
| 1380 | 1370 |
| 1381 } // namespace test | 1371 } // namespace test |
| 1382 } // namespace cc | 1372 } // namespace cc |
| OLD | NEW |