Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "cc/surfaces/surface.h" | 11 #include "cc/surfaces/surface.h" |
| 12 #include "cc/surfaces/surface_factory.h" | 12 #include "cc/surfaces/surface_factory.h" |
| 13 #include "cc/surfaces/surface_factory_client.h" | 13 #include "cc/surfaces/surface_factory_client.h" |
| 14 #include "cc/surfaces/surface_id.h" | 14 #include "cc/surfaces/surface_id.h" |
| 15 #include "cc/surfaces/surface_info.h" | |
|
kylechar
2017/01/17 16:15:35
Is this used?
Saman Sami
2017/01/17 18:29:05
Done.
| |
| 15 #include "cc/surfaces/surface_manager.h" | 16 #include "cc/surfaces/surface_manager.h" |
| 16 #include "cc/surfaces/surface_sequence_generator.h" | 17 #include "cc/surfaces/surface_sequence_generator.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 namespace cc { | 19 namespace cc { |
| 19 namespace { | |
| 20 | 20 |
| 21 constexpr FrameSinkId kFrameSink1(1, 0); | 21 constexpr FrameSinkId kFrameSink1(1, 0); |
|
kylechar
2017/01/17 16:15:35
You should leave constants/helper classes/helper f
Saman Sami
2017/01/17 18:29:05
Done.
| |
| 22 constexpr FrameSinkId kFrameSink2(2, 0); | 22 constexpr FrameSinkId kFrameSink2(2, 0); |
| 23 constexpr FrameSinkId kFrameSink3(3, 0); | 23 constexpr FrameSinkId kFrameSink3(3, 0); |
| 24 const LocalFrameId kLocalFrame1(1, base::UnguessableToken::Create()); | 24 const LocalFrameId kLocalFrame1(1, base::UnguessableToken::Create()); |
| 25 const LocalFrameId kLocalFrame2(2, base::UnguessableToken::Create()); | 25 const LocalFrameId kLocalFrame2(2, base::UnguessableToken::Create()); |
| 26 | 26 |
| 27 class StubSurfaceFactoryClient : public SurfaceFactoryClient { | 27 class StubSurfaceFactoryClient : public SurfaceFactoryClient { |
| 28 public: | 28 public: |
| 29 void ReturnResources(const ReturnedResourceArray& resources) override {} | 29 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| 30 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} | 30 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 // Tests for reference tracking in SurfaceManager. | 33 // Tests for reference tracking in SurfaceManager. |
| 34 class SurfaceManagerRefTest : public testing::Test { | 34 class SurfaceManagerRefTest : public testing::Test { |
| 35 public: | 35 public: |
| 36 SurfaceManager& manager() { return *manager_; } | 36 SurfaceManager& manager() { return *manager_; } |
| 37 | 37 |
| 38 // Creates a new Surface with the provided SurfaceId. Will first create the | 38 // Creates a new Surface with the provided SurfaceId. Will first create the |
| 39 // SurfaceFactory for |frame_sink_id| if necessary. | 39 // SurfaceFactory for |frame_sink_id| if necessary. |
| 40 SurfaceId CreateSurface(const FrameSinkId& frame_sink_id, | 40 SurfaceId CreateSurface(const FrameSinkId& frame_sink_id, |
| 41 const LocalFrameId& local_frame_id) { | 41 const LocalFrameId& local_frame_id) { |
| 42 GetFactory(frame_sink_id) | 42 GetFactory(frame_sink_id) |
| 43 .SubmitCompositorFrame(local_frame_id, CompositorFrame(), | 43 .SubmitCompositorFrame(local_frame_id, CompositorFrame(), |
| 44 SurfaceFactory::DrawCallback()); | 44 SurfaceFactory::DrawCallback()); |
| 45 return SurfaceId(frame_sink_id, local_frame_id); | 45 return SurfaceId(frame_sink_id, local_frame_id); |
| 46 } | 46 } |
| 47 | 47 |
| 48 SurfaceId CreateSurface(uint32_t client_id, | |
| 49 uint32_t sink_id, | |
| 50 uint32_t local_id) { | |
| 51 return CreateSurface( | |
| 52 FrameSinkId(client_id, sink_id), | |
| 53 LocalFrameId(local_id, base::UnguessableToken::Deserialize(0, 1u))); | |
| 54 } | |
| 55 | |
| 48 // Destroy Surface with |surface_id|. | 56 // Destroy Surface with |surface_id|. |
| 49 void DestroySurface(const SurfaceId& surface_id) { | 57 void DestroySurface(const SurfaceId& surface_id) { |
| 50 GetFactory(surface_id.frame_sink_id()).EvictSurface(); | 58 GetFactory(surface_id.frame_sink_id()).EvictSurface(); |
| 51 } | 59 } |
| 52 | 60 |
| 53 protected: | 61 protected: |
| 54 SurfaceFactory& GetFactory(const FrameSinkId& frame_sink_id) { | 62 SurfaceFactory& GetFactory(const FrameSinkId& frame_sink_id) { |
| 55 auto& factory_ptr = factories_[frame_sink_id]; | 63 auto& factory_ptr = factories_[frame_sink_id]; |
| 56 if (!factory_ptr) | 64 if (!factory_ptr) |
| 57 factory_ptr = base::MakeUnique<SurfaceFactory>(frame_sink_id, | 65 factory_ptr = base::MakeUnique<SurfaceFactory>(frame_sink_id, |
| 58 manager_.get(), &client_); | 66 manager_.get(), &client_); |
| 59 return *factory_ptr; | 67 return *factory_ptr; |
| 60 } | 68 } |
| 61 | 69 |
| 62 // testing::Test: | 70 // testing::Test: |
| 63 void SetUp() override { | 71 void SetUp() override { |
| 64 // Start each test with a fresh SurfaceManager instance. | 72 // Start each test with a fresh SurfaceManager instance. |
| 65 manager_ = base::MakeUnique<SurfaceManager>(); | 73 manager_ = base::MakeUnique<SurfaceManager>( |
| 74 SurfaceManager::LifetimeType::REFERENCES); | |
| 66 } | 75 } |
| 67 void TearDown() override { | 76 void TearDown() override { |
| 68 for (auto& factory : factories_) | 77 for (auto& factory : factories_) |
| 69 factory.second->EvictSurface(); | 78 factory.second->EvictSurface(); |
| 70 factories_.clear(); | 79 factories_.clear(); |
| 71 manager_.reset(); | 80 manager_.reset(); |
| 72 } | 81 } |
| 73 | 82 |
| 83 SurfaceManager::SurfaceIdSet refs(SurfaceId surface_id) { | |
| 84 return manager().parent_to_child_refs_[surface_id]; | |
| 85 } | |
| 86 | |
| 87 std::unordered_map<FrameSinkId, std::vector<LocalFrameId>, FrameSinkIdHash> | |
| 88 tmp_refs() { | |
| 89 return manager().temp_references_; | |
| 90 } | |
| 91 | |
| 74 std::unordered_map<FrameSinkId, | 92 std::unordered_map<FrameSinkId, |
| 75 std::unique_ptr<SurfaceFactory>, | 93 std::unique_ptr<SurfaceFactory>, |
| 76 FrameSinkIdHash> | 94 FrameSinkIdHash> |
| 77 factories_; | 95 factories_; |
| 78 std::unique_ptr<SurfaceManager> manager_; | 96 std::unique_ptr<SurfaceManager> manager_; |
| 79 StubSurfaceFactoryClient client_; | 97 StubSurfaceFactoryClient client_; |
| 80 }; | 98 }; |
| 81 | 99 |
| 82 } // namespace | |
| 83 | |
| 84 TEST_F(SurfaceManagerRefTest, AddReference) { | 100 TEST_F(SurfaceManagerRefTest, AddReference) { |
| 85 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); | 101 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); |
| 86 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id1); | 102 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id1); |
| 87 | 103 |
| 88 EXPECT_EQ(manager().GetSurfaceReferenceCount(id1), 1u); | 104 EXPECT_EQ(manager().GetSurfaceReferenceCount(id1), 1u); |
| 89 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 0u); | 105 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 0u); |
| 90 } | 106 } |
| 91 | 107 |
| 92 TEST_F(SurfaceManagerRefTest, AddRemoveReference) { | 108 TEST_F(SurfaceManagerRefTest, AddRemoveReference) { |
| 93 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); | 109 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 | 230 |
| 215 manager().RemoveSurfaceReference(manager().GetRootSurfaceId(), id1); | 231 manager().RemoveSurfaceReference(manager().GetRootSurfaceId(), id1); |
| 216 | 232 |
| 217 // Removing the reference from the root to id1 should allow all three surfaces | 233 // Removing the reference from the root to id1 should allow all three surfaces |
| 218 // to be deleted during GC. | 234 // to be deleted during GC. |
| 219 EXPECT_EQ(manager().GetSurfaceForId(id1), nullptr); | 235 EXPECT_EQ(manager().GetSurfaceForId(id1), nullptr); |
| 220 EXPECT_EQ(manager().GetSurfaceForId(id2), nullptr); | 236 EXPECT_EQ(manager().GetSurfaceForId(id2), nullptr); |
| 221 EXPECT_EQ(manager().GetSurfaceForId(id3), nullptr); | 237 EXPECT_EQ(manager().GetSurfaceForId(id3), nullptr); |
| 222 } | 238 } |
| 223 | 239 |
| 224 TEST_F(SurfaceManagerRefTest, CheckGCWithSequences) { | |
| 225 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); | |
| 226 SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1); | |
| 227 | |
| 228 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id1); | |
| 229 manager().AddSurfaceReference(id1, id2); | |
| 230 | |
| 231 SurfaceId id3 = CreateSurface(kFrameSink3, kLocalFrame1); | |
| 232 Surface* surface3 = manager().GetSurfaceForId(id3); | |
| 233 | |
| 234 // Add destruction dependency from |id2| to |id3|. | |
| 235 manager().RegisterFrameSinkId(kFrameSink2); | |
| 236 SurfaceSequence sequence(kFrameSink2, 1u); | |
| 237 surface3->AddDestructionDependency(sequence); | |
| 238 EXPECT_EQ(surface3->GetDestructionDependencyCount(), 1u); | |
| 239 | |
| 240 // Surface for |id3| isn't delete yet because it has a valid destruction | |
| 241 // dependency from |kFrameSink2|. | |
| 242 DestroySurface(id3); | |
| 243 EXPECT_NE(manager().GetSurfaceForId(id3), nullptr); | |
| 244 | |
| 245 // Surface for |id2| isn't deleted because it has a reference. | |
| 246 DestroySurface(id2); | |
| 247 EXPECT_NE(manager().GetSurfaceForId(id2), nullptr); | |
| 248 | |
| 249 // Satisfy destruction dependency on |id3| and delete during GC. | |
| 250 manager().SatisfySequence(sequence); | |
| 251 EXPECT_EQ(manager().GetSurfaceForId(id3), nullptr); | |
| 252 | |
| 253 // Remove ref on |id2| and delete during GC. | |
| 254 manager().RemoveSurfaceReference(id1, id2); | |
| 255 EXPECT_EQ(manager().GetSurfaceForId(id2), nullptr); | |
| 256 } | |
| 257 | |
| 258 TEST_F(SurfaceManagerRefTest, TryAddReferenceToBadSurface) { | 240 TEST_F(SurfaceManagerRefTest, TryAddReferenceToBadSurface) { |
| 259 // Not creating an accompanying Surface and SurfaceFactory. | 241 // Not creating an accompanying Surface and SurfaceFactory. |
| 260 SurfaceId id(FrameSinkId(100u, 200u), | 242 SurfaceId id(FrameSinkId(100u, 200u), |
| 261 LocalFrameId(1u, base::UnguessableToken::Create())); | 243 LocalFrameId(1u, base::UnguessableToken::Create())); |
| 262 | 244 |
| 263 // Adding reference from root to the Surface should do nothing because | 245 // Adding reference from root to the Surface should do nothing because |
| 264 // SurfaceManager doesn't know Surface for |id| exists. | 246 // SurfaceManager doesn't know Surface for |id| exists. |
| 265 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id); | 247 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id); |
| 266 EXPECT_EQ(manager().GetSurfaceReferenceCount(id), 0u); | 248 EXPECT_EQ(manager().GetSurfaceReferenceCount(id), 0u); |
| 267 } | 249 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 279 manager().AddSurfaceReference(id1, id2); | 261 manager().AddSurfaceReference(id1, id2); |
| 280 EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u); | 262 EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u); |
| 281 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 1u); | 263 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 1u); |
| 282 } | 264 } |
| 283 | 265 |
| 284 TEST_F(SurfaceManagerRefTest, TryAddSelfReference) { | 266 TEST_F(SurfaceManagerRefTest, TryAddSelfReference) { |
| 285 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); | 267 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); |
| 286 | 268 |
| 287 // Adding a self reference should be ignored without crashing. | 269 // Adding a self reference should be ignored without crashing. |
| 288 manager().AddSurfaceReference(id1, id1); | 270 manager().AddSurfaceReference(id1, id1); |
| 289 EXPECT_EQ(manager().GetSurfaceReferenceCount(id1), 0u); | |
| 290 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 0u); | 271 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 0u); |
| 272 // There should still be one temporary reference to id1 | |
| 273 EXPECT_EQ(manager().GetSurfaceReferenceCount(id1), 1u); | |
|
kylechar
2017/01/17 16:15:35
Can you also check this is true before AddSurfaceR
Saman Sami
2017/01/17 18:29:05
Done.
| |
| 291 } | 274 } |
| 292 | 275 |
| 293 TEST_F(SurfaceManagerRefTest, TryRemoveBadReference) { | 276 TEST_F(SurfaceManagerRefTest, TryRemoveBadReference) { |
| 294 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); | 277 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); |
| 295 SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1); | 278 SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1); |
| 296 | 279 |
| 297 // Removing non-existent reference should be ignored. | 280 // Removing non-existent reference should be ignored. |
| 298 manager().AddSurfaceReference(id1, id2); | 281 manager().AddSurfaceReference(id1, id2); |
| 299 manager().RemoveSurfaceReference(id2, id1); | 282 manager().RemoveSurfaceReference(id2, id1); |
| 300 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 1u); | 283 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 1u); |
| 301 EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u); | 284 EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u); |
| 302 } | 285 } |
| 303 | 286 |
| 287 // Temporary Reference Tests | |
| 288 | |
| 289 TEST_F(SurfaceManagerRefTest, AddSurfaceThenReference) { | |
| 290 const SurfaceId surface_id = CreateSurface(2, 1, 1); | |
| 291 | |
| 292 // Temporary reference must be added. | |
| 293 EXPECT_EQ(1u, tmp_refs().size()); | |
| 294 EXPECT_EQ(std::vector<LocalFrameId>{surface_id.local_frame_id()}, | |
|
kylechar
2017/01/17 16:15:35
The tests become pretty difficult to read. Changin
Saman Sami
2017/01/17 18:29:05
Neat.
| |
| 295 tmp_refs()[surface_id.frame_sink_id()]); | |
| 296 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).size()); | |
| 297 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id)); | |
| 298 | |
| 299 // Add a real reference to surface_id. | |
| 300 const SurfaceId parent_id = CreateSurface(1, 1, 1); | |
| 301 manager().AddSurfaceReference(parent_id, surface_id); | |
| 302 | |
| 303 // Real reference is added and temporary reference to surface_id is removed. | |
| 304 EXPECT_EQ(1u, tmp_refs().size()); | |
| 305 EXPECT_EQ(std::vector<LocalFrameId>{parent_id.local_frame_id()}, | |
| 306 tmp_refs()[parent_id.frame_sink_id()]); | |
| 307 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).size()); | |
| 308 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(parent_id)); | |
| 309 EXPECT_EQ(1u, refs(parent_id).size()); | |
| 310 EXPECT_EQ(1u, refs(parent_id).count(surface_id)); | |
| 311 } | |
| 312 | |
| 313 TEST_F(SurfaceManagerRefTest, AddSurfaceThenRootReference) { | |
| 314 const SurfaceId surface_id = CreateSurface(1, 1, 1); | |
| 315 | |
| 316 // Temporary reference should be added. | |
| 317 EXPECT_EQ(1u, tmp_refs().size()); | |
| 318 EXPECT_EQ(std::vector<LocalFrameId>{surface_id.local_frame_id()}, | |
| 319 tmp_refs()[surface_id.frame_sink_id()]); | |
| 320 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).size()); | |
| 321 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id)); | |
| 322 | |
| 323 // Add a real reference from root to surface_id. | |
| 324 manager().AddSurfaceReference(manager().GetRootSurfaceId(), surface_id); | |
| 325 | |
| 326 // Adding real reference doesn't need to change anything in | |
| 327 // SurfaceReferenceManager does remove the temporary reference marker. | |
| 328 EXPECT_EQ(0u, tmp_refs().size()); | |
| 329 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).size()); | |
| 330 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id)); | |
| 331 } | |
| 332 | |
| 333 TEST_F(SurfaceManagerRefTest, AddTwoSurfacesThenOneReference) { | |
| 334 // Add two surfaces with different FrameSinkIds. | |
| 335 const SurfaceId surface_id1 = CreateSurface(2, 1, 1); | |
| 336 const SurfaceId surface_id2 = CreateSurface(3, 1, 1); | |
| 337 | |
| 338 // Temporary reference should be added for both surfaces. | |
| 339 EXPECT_EQ(2u, tmp_refs().size()); | |
| 340 EXPECT_EQ(std::vector<LocalFrameId>{surface_id1.local_frame_id()}, | |
| 341 tmp_refs()[surface_id1.frame_sink_id()]); | |
| 342 EXPECT_EQ(std::vector<LocalFrameId>{surface_id2.local_frame_id()}, | |
| 343 tmp_refs()[surface_id2.frame_sink_id()]); | |
| 344 EXPECT_EQ(2u, refs(manager().GetRootSurfaceId()).size()); | |
| 345 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id1)); | |
| 346 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id2)); | |
| 347 | |
| 348 // Add a real reference to surface_id1. | |
| 349 const SurfaceId parent_id = CreateSurface(1, 1, 1); | |
| 350 manager().AddSurfaceReference(parent_id, surface_id1); | |
| 351 | |
| 352 // Real reference is added then temporary reference removed for 2:1:1. There | |
| 353 // should still be a temporary reference left to 3:1:1 | |
| 354 EXPECT_EQ(2u, tmp_refs().size()); | |
| 355 EXPECT_EQ(std::vector<LocalFrameId>{surface_id2.local_frame_id()}, | |
| 356 tmp_refs()[surface_id2.frame_sink_id()]); | |
| 357 EXPECT_EQ(std::vector<LocalFrameId>{parent_id.local_frame_id()}, | |
| 358 tmp_refs()[parent_id.frame_sink_id()]); | |
| 359 EXPECT_EQ(2u, refs(manager().GetRootSurfaceId()).size()); | |
| 360 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(parent_id)); | |
| 361 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id2)); | |
| 362 EXPECT_EQ(1u, refs(parent_id).size()); | |
| 363 EXPECT_EQ(1u, refs(parent_id).count(surface_id1)); | |
| 364 } | |
| 365 | |
| 366 TEST_F(SurfaceManagerRefTest, AddSurfacesSkipReference) { | |
| 367 // Add two surfaces that have the same FrameSinkId. This would happen when a | |
| 368 // client submits two CFs before parent submits a new CF. | |
| 369 const SurfaceId surface_id1 = CreateSurface(2, 1, 1); | |
| 370 const SurfaceId surface_id2 = CreateSurface(2, 1, 2); | |
| 371 | |
| 372 // Temporary references should be added for both surfaces. | |
| 373 std::vector<LocalFrameId> expected_ids = {surface_id1.local_frame_id(), | |
| 374 surface_id2.local_frame_id()}; | |
| 375 EXPECT_EQ(1u, tmp_refs().size()); | |
| 376 EXPECT_EQ(expected_ids, tmp_refs()[surface_id1.frame_sink_id()]); | |
| 377 EXPECT_EQ(2u, refs(manager().GetRootSurfaceId()).size()); | |
| 378 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id1)); | |
| 379 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id2)); | |
| 380 | |
| 381 // Add a reference to the surface with the later LocalFrameId. | |
| 382 const SurfaceId parent_id = CreateSurface(1, 1, 1); | |
| 383 manager().AddSurfaceReference(parent_id, surface_id2); | |
| 384 | |
| 385 // The real reference should be added for 2:1:2 and both temporary references | |
| 386 // should be removed. | |
| 387 EXPECT_EQ(1u, tmp_refs().size()); | |
| 388 EXPECT_EQ(std::vector<LocalFrameId>{parent_id.local_frame_id()}, | |
| 389 tmp_refs()[parent_id.frame_sink_id()]); | |
| 390 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).size()); | |
| 391 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(parent_id)); | |
| 392 EXPECT_EQ(1u, refs(parent_id).size()); | |
| 393 EXPECT_EQ(1u, refs(parent_id).count(surface_id2)); | |
| 394 } | |
| 395 | |
| 396 TEST_F(SurfaceManagerRefTest, RemoveFirstTempRefOnly) { | |
| 397 // Add two surfaces that have the same FrameSinkId. This would happen when a | |
| 398 // client submits two CFs before parent submits a new CF. | |
| 399 const SurfaceId surface_id1 = CreateSurface(2, 1, 1); | |
| 400 const SurfaceId surface_id2 = CreateSurface(2, 1, 2); | |
| 401 | |
| 402 // Temporary references should be added for both surfaces. | |
| 403 std::vector<LocalFrameId> expected_ids = {surface_id1.local_frame_id(), | |
| 404 surface_id2.local_frame_id()}; | |
| 405 EXPECT_EQ(1u, tmp_refs().size()); | |
| 406 EXPECT_EQ(expected_ids, tmp_refs()[surface_id1.frame_sink_id()]); | |
| 407 EXPECT_EQ(2u, refs(manager().GetRootSurfaceId()).size()); | |
| 408 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id1)); | |
| 409 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id2)); | |
| 410 | |
| 411 // Add a reference to the surface with the earlier LocalFrameId. | |
| 412 const SurfaceId parent_id = CreateSurface(1, 1, 1); | |
| 413 manager().AddSurfaceReference(parent_id, surface_id1); | |
| 414 | |
| 415 // The real reference should be added for 2:1:1 and temporary reference | |
| 416 // should be removed. The temporary reference for 2:1:2 should remain. | |
| 417 EXPECT_EQ(2u, tmp_refs().size()); | |
| 418 EXPECT_EQ(std::vector<LocalFrameId>{surface_id2.local_frame_id()}, | |
| 419 tmp_refs()[surface_id2.frame_sink_id()]); | |
| 420 EXPECT_EQ(std::vector<LocalFrameId>{parent_id.local_frame_id()}, | |
| 421 tmp_refs()[parent_id.frame_sink_id()]); | |
| 422 EXPECT_EQ(2u, refs(manager().GetRootSurfaceId()).size()); | |
| 423 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(surface_id2)); | |
| 424 EXPECT_EQ(1u, refs(manager().GetRootSurfaceId()).count(parent_id)); | |
| 425 EXPECT_EQ(1u, refs(parent_id).size()); | |
| 426 EXPECT_EQ(1u, refs(parent_id).count(surface_id1)); | |
| 427 } | |
| 428 | |
| 304 } // namespace cc | 429 } // namespace cc |
| OLD | NEW |