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

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

Issue 2661543002: Rename LocalFrameId to LocalSurfaceId (Closed)
Patch Set: c Created 3 years, 10 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
« no previous file with comments | « cc/surfaces/surface_manager.cc ('k') | cc/surfaces/surface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <unordered_map> 7 #include <unordered_map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 27 matching lines...) Expand all
38 } // namespace 38 } // namespace
39 39
40 // Tests for reference tracking in SurfaceManager. 40 // Tests for reference tracking in SurfaceManager.
41 class SurfaceManagerRefTest : public testing::Test { 41 class SurfaceManagerRefTest : public testing::Test {
42 public: 42 public:
43 SurfaceManager& manager() { return *manager_; } 43 SurfaceManager& manager() { return *manager_; }
44 44
45 // Creates a new Surface with the provided |frame_sink_id| and |local_id|. 45 // Creates a new Surface with the provided |frame_sink_id| and |local_id|.
46 // Will first create a SurfaceFactory for |frame_sink_id| if necessary. 46 // Will first create a SurfaceFactory for |frame_sink_id| if necessary.
47 SurfaceId CreateSurface(const FrameSinkId& frame_sink_id, uint32_t local_id) { 47 SurfaceId CreateSurface(const FrameSinkId& frame_sink_id, uint32_t local_id) {
48 LocalFrameId local_frame_id(local_id, 48 LocalSurfaceId local_surface_id(local_id,
49 base::UnguessableToken::Deserialize(0, 1u)); 49 base::UnguessableToken::Deserialize(0, 1u));
50 GetFactory(frame_sink_id) 50 GetFactory(frame_sink_id)
51 .SubmitCompositorFrame(local_frame_id, CompositorFrame(), 51 .SubmitCompositorFrame(local_surface_id, CompositorFrame(),
52 SurfaceFactory::DrawCallback()); 52 SurfaceFactory::DrawCallback());
53 return SurfaceId(frame_sink_id, local_frame_id); 53 return SurfaceId(frame_sink_id, local_surface_id);
54 } 54 }
55 55
56 // Destroy Surface with |surface_id|. 56 // Destroy Surface with |surface_id|.
57 void DestroySurface(const SurfaceId& surface_id) { 57 void DestroySurface(const SurfaceId& surface_id) {
58 GetFactory(surface_id.frame_sink_id()).EvictSurface(); 58 GetFactory(surface_id.frame_sink_id()).EvictSurface();
59 } 59 }
60 60
61 protected: 61 protected:
62 SurfaceFactory& GetFactory(const FrameSinkId& frame_sink_id) { 62 SurfaceFactory& GetFactory(const FrameSinkId& frame_sink_id) {
63 auto& factory_ptr = factories_[frame_sink_id]; 63 auto& factory_ptr = factories_[frame_sink_id];
(...skipping 26 matching lines...) Expand all
90 const SurfaceManager::SurfaceIdSet& GetReferencesFor( 90 const SurfaceManager::SurfaceIdSet& GetReferencesFor(
91 const SurfaceId& surface_id) { 91 const SurfaceId& surface_id) {
92 return manager().child_to_parent_refs_[surface_id]; 92 return manager().child_to_parent_refs_[surface_id];
93 } 93 }
94 94
95 const SurfaceManager::SurfaceIdSet& GetReferencesFromRoot() { 95 const SurfaceManager::SurfaceIdSet& GetReferencesFromRoot() {
96 return GetReferencesFrom(manager().GetRootSurfaceId()); 96 return GetReferencesFrom(manager().GetRootSurfaceId());
97 } 97 }
98 98
99 // Returns all the temporary references for the given frame sink id. 99 // Returns all the temporary references for the given frame sink id.
100 std::vector<LocalFrameId> GetTempReferencesFor( 100 std::vector<LocalSurfaceId> GetTempReferencesFor(
101 const FrameSinkId& frame_sink_id) { 101 const FrameSinkId& frame_sink_id) {
102 return manager().temp_references_[frame_sink_id]; 102 return manager().temp_references_[frame_sink_id];
103 } 103 }
104 104
105 // Temporary references are stored as a map in SurfaceManager. This method 105 // Temporary references are stored as a map in SurfaceManager. This method
106 // converts the map to a vector. 106 // converts the map to a vector.
107 std::vector<SurfaceId> GetAllTempReferences() { 107 std::vector<SurfaceId> GetAllTempReferences() {
108 std::vector<SurfaceId> temp_references; 108 std::vector<SurfaceId> temp_references;
109 for (auto& map_entry : manager().temp_references_) { 109 for (auto& map_entry : manager().temp_references_) {
110 for (auto local_frame_id : map_entry.second) 110 for (auto local_surface_id : map_entry.second)
111 temp_references.push_back(SurfaceId(map_entry.first, local_frame_id)); 111 temp_references.push_back(SurfaceId(map_entry.first, local_surface_id));
112 } 112 }
113 return temp_references; 113 return temp_references;
114 } 114 }
115 115
116 std::unordered_map<FrameSinkId, 116 std::unordered_map<FrameSinkId,
117 std::unique_ptr<SurfaceFactory>, 117 std::unique_ptr<SurfaceFactory>,
118 FrameSinkIdHash> 118 FrameSinkIdHash>
119 factories_; 119 factories_;
120 std::unique_ptr<SurfaceManager> manager_; 120 std::unique_ptr<SurfaceManager> manager_;
121 StubSurfaceFactoryClient client_; 121 StubSurfaceFactoryClient client_;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // Removing the reference from the root to id1 should allow all three surfaces 257 // Removing the reference from the root to id1 should allow all three surfaces
258 // to be deleted during GC. 258 // to be deleted during GC.
259 EXPECT_EQ(nullptr, manager().GetSurfaceForId(id1)); 259 EXPECT_EQ(nullptr, manager().GetSurfaceForId(id1));
260 EXPECT_EQ(nullptr, manager().GetSurfaceForId(id2)); 260 EXPECT_EQ(nullptr, manager().GetSurfaceForId(id2));
261 EXPECT_EQ(nullptr, manager().GetSurfaceForId(id3)); 261 EXPECT_EQ(nullptr, manager().GetSurfaceForId(id3));
262 } 262 }
263 263
264 TEST_F(SurfaceManagerRefTest, TryAddReferenceToBadSurface) { 264 TEST_F(SurfaceManagerRefTest, TryAddReferenceToBadSurface) {
265 // Not creating an accompanying Surface and SurfaceFactory. 265 // Not creating an accompanying Surface and SurfaceFactory.
266 SurfaceId id(FrameSinkId(100u, 200u), 266 SurfaceId id(FrameSinkId(100u, 200u),
267 LocalFrameId(1u, base::UnguessableToken::Create())); 267 LocalSurfaceId(1u, base::UnguessableToken::Create()));
268 268
269 // Adding reference from root to the Surface should do nothing because 269 // Adding reference from root to the Surface should do nothing because
270 // SurfaceManager doesn't know Surface for |id| exists. 270 // SurfaceManager doesn't know Surface for |id| exists.
271 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id); 271 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id);
272 EXPECT_THAT(GetReferencesFor(id), IsEmpty()); 272 EXPECT_THAT(GetReferencesFor(id), IsEmpty());
273 } 273 }
274 274
275 TEST_F(SurfaceManagerRefTest, TryDoubleAddReference) { 275 TEST_F(SurfaceManagerRefTest, TryDoubleAddReference) {
276 SurfaceId id1 = CreateSurface(kFrameSink1, 1); 276 SurfaceId id1 = CreateSurface(kFrameSink1, 1);
277 SurfaceId id2 = CreateSurface(kFrameSink2, 1); 277 SurfaceId id2 = CreateSurface(kFrameSink2, 1);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 379
380 TEST_F(SurfaceManagerRefTest, AddSurfacesSkipReference) { 380 TEST_F(SurfaceManagerRefTest, AddSurfacesSkipReference) {
381 // Add two surfaces that have the same FrameSinkId. This would happen when a 381 // Add two surfaces that have the same FrameSinkId. This would happen when a
382 // client submits two CompositorFrames before parent submits a new 382 // client submits two CompositorFrames before parent submits a new
383 // CompositorFrame. 383 // CompositorFrame.
384 const SurfaceId surface_id1 = CreateSurface(kFrameSink2, 2); 384 const SurfaceId surface_id1 = CreateSurface(kFrameSink2, 2);
385 const SurfaceId surface_id2 = CreateSurface(kFrameSink2, 1); 385 const SurfaceId surface_id2 = CreateSurface(kFrameSink2, 1);
386 386
387 // Temporary references should be added for both surfaces and they should be 387 // Temporary references should be added for both surfaces and they should be
388 // stored in the order of creation. 388 // stored in the order of creation.
389 EXPECT_THAT( 389 EXPECT_THAT(GetTempReferencesFor(surface_id1.frame_sink_id()),
390 GetTempReferencesFor(surface_id1.frame_sink_id()), 390 ElementsAre(surface_id1.local_surface_id(),
391 ElementsAre(surface_id1.local_frame_id(), surface_id2.local_frame_id())); 391 surface_id2.local_surface_id()));
392 EXPECT_THAT(GetReferencesFromRoot(), 392 EXPECT_THAT(GetReferencesFromRoot(),
393 UnorderedElementsAre(surface_id1, surface_id2)); 393 UnorderedElementsAre(surface_id1, surface_id2));
394 394
395 // Create |parent_id| and add a reference from it to |surface_id2| which was 395 // Create |parent_id| and add a reference from it to |surface_id2| which was
396 // created later. 396 // created later.
397 const SurfaceId parent_id = CreateSurface(kFrameSink1, 1); 397 const SurfaceId parent_id = CreateSurface(kFrameSink1, 1);
398 manager().AddSurfaceReference(parent_id, surface_id2); 398 manager().AddSurfaceReference(parent_id, surface_id2);
399 399
400 // The real reference should be added for |surface_id2| and the temporary 400 // The real reference should be added for |surface_id2| and the temporary
401 // references to both |surface_id1| and |surface_id2| should be gone. 401 // references to both |surface_id1| and |surface_id2| should be gone.
402 // There should be a temporary reference to |parent_id|. 402 // There should be a temporary reference to |parent_id|.
403 EXPECT_THAT(GetAllTempReferences(), ElementsAre(parent_id)); 403 EXPECT_THAT(GetAllTempReferences(), ElementsAre(parent_id));
404 EXPECT_THAT(GetReferencesFromRoot(), ElementsAre(parent_id)); 404 EXPECT_THAT(GetReferencesFromRoot(), ElementsAre(parent_id));
405 EXPECT_THAT(GetReferencesFrom(parent_id), ElementsAre(surface_id2)); 405 EXPECT_THAT(GetReferencesFrom(parent_id), ElementsAre(surface_id2));
406 } 406 }
407 407
408 TEST_F(SurfaceManagerRefTest, RemoveFirstTempRefOnly) { 408 TEST_F(SurfaceManagerRefTest, RemoveFirstTempRefOnly) {
409 // Add two surfaces that have the same FrameSinkId. This would happen when a 409 // Add two surfaces that have the same FrameSinkId. This would happen when a
410 // client submits two CFs before parent submits a new CF. 410 // client submits two CFs before parent submits a new CF.
411 const SurfaceId surface_id1 = CreateSurface(kFrameSink2, 1); 411 const SurfaceId surface_id1 = CreateSurface(kFrameSink2, 1);
412 const SurfaceId surface_id2 = CreateSurface(kFrameSink2, 2); 412 const SurfaceId surface_id2 = CreateSurface(kFrameSink2, 2);
413 413
414 // Temporary references should be added for both surfaces and they should be 414 // Temporary references should be added for both surfaces and they should be
415 // stored in the order of creation. 415 // stored in the order of creation.
416 EXPECT_THAT( 416 EXPECT_THAT(GetTempReferencesFor(surface_id1.frame_sink_id()),
417 GetTempReferencesFor(surface_id1.frame_sink_id()), 417 ElementsAre(surface_id1.local_surface_id(),
418 ElementsAre(surface_id1.local_frame_id(), surface_id2.local_frame_id())); 418 surface_id2.local_surface_id()));
419 EXPECT_THAT(GetReferencesFromRoot(), 419 EXPECT_THAT(GetReferencesFromRoot(),
420 UnorderedElementsAre(surface_id1, surface_id2)); 420 UnorderedElementsAre(surface_id1, surface_id2));
421 421
422 // Create |parent_id| and add a reference from it to |surface_id1| which was 422 // Create |parent_id| and add a reference from it to |surface_id1| which was
423 // created earlier. 423 // created earlier.
424 const SurfaceId parent_id = CreateSurface(kFrameSink1, 1); 424 const SurfaceId parent_id = CreateSurface(kFrameSink1, 1);
425 manager().AddSurfaceReference(parent_id, surface_id1); 425 manager().AddSurfaceReference(parent_id, surface_id1);
426 426
427 // The real reference should be added for |surface_id1| and its temporary 427 // The real reference should be added for |surface_id1| and its temporary
428 // reference should be removed. The temporary reference for |surface_id2| 428 // reference should be removed. The temporary reference for |surface_id2|
429 // should remain. A temporary reference must be added for |parent_id|. 429 // should remain. A temporary reference must be added for |parent_id|.
430 EXPECT_THAT(GetAllTempReferences(), 430 EXPECT_THAT(GetAllTempReferences(),
431 UnorderedElementsAre(parent_id, surface_id2)); 431 UnorderedElementsAre(parent_id, surface_id2));
432 EXPECT_THAT(GetReferencesFromRoot(), 432 EXPECT_THAT(GetReferencesFromRoot(),
433 UnorderedElementsAre(parent_id, surface_id2)); 433 UnorderedElementsAre(parent_id, surface_id2));
434 EXPECT_THAT(GetReferencesFrom(parent_id), ElementsAre(surface_id1)); 434 EXPECT_THAT(GetReferencesFrom(parent_id), ElementsAre(surface_id1));
435 } 435 }
436 436
437 } // namespace cc 437 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_manager.cc ('k') | cc/surfaces/surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698