Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: cc/surfaces/surface_synchronization_unittest.cc

Issue 2940183002: cc: Move ownership of surfaces to SurfaceManager (Closed)
Patch Set: Fix test Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } // namespace 46 } // namespace
47 47
48 class SurfaceSynchronizationTest : public testing::Test { 48 class SurfaceSynchronizationTest : public testing::Test {
49 public: 49 public:
50 SurfaceSynchronizationTest() 50 SurfaceSynchronizationTest()
51 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES), 51 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES),
52 surface_observer_(false) {} 52 surface_observer_(false) {}
53 ~SurfaceSynchronizationTest() override {} 53 ~SurfaceSynchronizationTest() override {}
54 54
55 CompositorFrameSinkSupport& display_support() { return *supports_[0]; } 55 CompositorFrameSinkSupport& display_support() { return *supports_[0]; }
56 Surface* display_surface() { 56 Surface* display_surface() { return display_support().GetCurrentSurface(); }
57 return display_support().current_surface_for_testing();
58 }
59 57
60 CompositorFrameSinkSupport& parent_support() { return *supports_[1]; } 58 CompositorFrameSinkSupport& parent_support() { return *supports_[1]; }
61 Surface* parent_surface() { 59 Surface* parent_surface() { return parent_support().GetCurrentSurface(); }
62 return parent_support().current_surface_for_testing();
63 }
64 60
65 CompositorFrameSinkSupport& child_support1() { return *supports_[2]; } 61 CompositorFrameSinkSupport& child_support1() { return *supports_[2]; }
66 Surface* child_surface1() { 62 Surface* child_surface1() { return child_support1().GetCurrentSurface(); }
67 return child_support1().current_surface_for_testing();
68 }
69 63
70 CompositorFrameSinkSupport& child_support2() { return *supports_[3]; } 64 CompositorFrameSinkSupport& child_support2() { return *supports_[3]; }
71 Surface* child_surface2() { 65 Surface* child_surface2() { return child_support2().GetCurrentSurface(); }
72 return child_support2().current_surface_for_testing();
73 }
74 66
75 CompositorFrameSinkSupport& support(int index) { return *supports_[index]; } 67 CompositorFrameSinkSupport& support(int index) { return *supports_[index]; }
76 Surface* surface(int index) { 68 Surface* surface(int index) { return support(index).GetCurrentSurface(); }
77 return support(index).current_surface_for_testing();
78 }
79 69
80 SurfaceManager& surface_manager() { return surface_manager_; } 70 SurfaceManager& surface_manager() { return surface_manager_; }
81 71
82 // Returns all the references where |surface_id| is the parent. 72 // Returns all the references where |surface_id| is the parent.
83 const base::flat_set<SurfaceId>& GetChildReferences( 73 const base::flat_set<SurfaceId>& GetChildReferences(
84 const SurfaceId& surface_id) { 74 const SurfaceId& surface_id) {
85 return surface_manager().GetSurfacesReferencedByParent(surface_id); 75 return surface_manager().GetSurfacesReferencedByParent(surface_id);
86 } 76 }
87 77
88 // Returns true if there is a temporary reference for |surface_id|. 78 // Returns true if there is a temporary reference for |surface_id|.
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 // Add a reference from the parent to the child. 993 // Add a reference from the parent to the child.
1004 parent_support().SubmitCompositorFrame( 994 parent_support().SubmitCompositorFrame(
1005 parent_id.local_surface_id(), 995 parent_id.local_surface_id(),
1006 MakeCompositorFrame({child_id}, {child_id}, TransferableResourceArray())); 996 MakeCompositorFrame({child_id}, {child_id}, TransferableResourceArray()));
1007 997
1008 // Attempt to destroy the child surface. The surface must still exist since 998 // Attempt to destroy the child surface. The surface must still exist since
1009 // the parent needs it but it will be marked as destroyed. 999 // the parent needs it but it will be marked as destroyed.
1010 child_support1().EvictCurrentSurface(); 1000 child_support1().EvictCurrentSurface();
1011 surface = surface_manager().GetSurfaceForId(child_id); 1001 surface = surface_manager().GetSurfaceForId(child_id);
1012 EXPECT_NE(nullptr, surface); 1002 EXPECT_NE(nullptr, surface);
1013 EXPECT_TRUE(surface->destroyed()); 1003 EXPECT_TRUE(surface_manager().IsMarkedForDestruction(child_id));
1014 1004
1015 // Child submits another frame to the same local surface id that is marked 1005 // Child submits another frame to the same local surface id that is marked
1016 // destroyed. 1006 // destroyed.
1017 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), 1007 child_support1().SubmitCompositorFrame(child_id.local_surface_id(),
1018 MakeCompositorFrame()); 1008 MakeCompositorFrame());
1019 1009
1020 // Verify that the surface that was marked destroyed is recovered and is being 1010 // Verify that the surface that was marked destroyed is recovered and is being
1021 // used again. 1011 // used again.
1022 Surface* surface2 = surface_manager().GetSurfaceForId(child_id); 1012 Surface* surface2 = surface_manager().GetSurfaceForId(child_id);
1023 EXPECT_EQ(surface, surface2); 1013 EXPECT_EQ(surface, surface2);
1024 EXPECT_FALSE(surface2->destroyed()); 1014 EXPECT_FALSE(surface_manager().IsMarkedForDestruction(child_id));
1025 } 1015 }
1026 1016
1027 // Verifies that if a LocalSurfaceId belonged to a surface that doesn't exist 1017 // Verifies that if a LocalSurfaceId belonged to a surface that doesn't exist
1028 // anymore, it can still be reused for new surfaces. 1018 // anymore, it can still be reused for new surfaces.
1029 TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) { 1019 TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) {
1030 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 1020 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
1031 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); 1021 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3);
1032 1022
1033 // Submit the first frame. Creates the surface. 1023 // Submit the first frame. Creates the surface.
1034 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), 1024 child_support1().SubmitCompositorFrame(child_id.local_surface_id(),
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 DidReceiveCompositorFrameAck(Eq(returned_resources2))); 1332 DidReceiveCompositorFrameAck(Eq(returned_resources2)));
1343 child_support1().SubmitCompositorFrame( 1333 child_support1().SubmitCompositorFrame(
1344 child_id1.local_surface_id(), 1334 child_id1.local_surface_id(),
1345 MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(), 1335 MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(),
1346 {resource2})); 1336 {resource2}));
1347 testing::Mock::VerifyAndClearExpectations(&support_client_); 1337 testing::Mock::VerifyAndClearExpectations(&support_client_);
1348 } 1338 }
1349 1339
1350 } // namespace test 1340 } // namespace test
1351 } // namespace cc 1341 } // namespace cc
OLDNEW
« cc/surfaces/surface_manager.h ('K') | « cc/surfaces/surface_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698