| 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_id.h" | 13 #include "cc/surfaces/surface_id.h" |
| 14 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
| 15 #include "cc/surfaces/surface_sequence_generator.h" | 15 #include "cc/surfaces/surface_sequence_generator.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 constexpr FrameSinkId kFrameSink1(1, 0); | 21 constexpr FrameSinkId kFrameSink1(1, 0); |
| 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 constexpr LocalFrameId kLocalFrame1(1, 0); |
| 25 const LocalFrameId kLocalFrame2(2, base::UnguessableToken::Create()); | 25 constexpr LocalFrameId kLocalFrame2(2, 0); |
| 26 | 26 |
| 27 // Tests for reference tracking in SurfaceManager. | 27 // Tests for reference tracking in SurfaceManager. |
| 28 class SurfaceManagerRefTest : public testing::Test { | 28 class SurfaceManagerRefTest : public testing::Test { |
| 29 public: | 29 public: |
| 30 SurfaceManager& manager() { return *manager_; } | 30 SurfaceManager& manager() { return *manager_; } |
| 31 | 31 |
| 32 // Creates a new Surface with the provided SurfaceId. Will first create the | 32 // Creates a new Surface with the provided SurfaceId. Will first create the |
| 33 // SurfaceFactory for |frame_sink_id| if necessary. | 33 // SurfaceFactory for |frame_sink_id| if necessary. |
| 34 SurfaceId CreateSurface(const FrameSinkId& frame_sink_id, | 34 SurfaceId CreateSurface(const FrameSinkId& frame_sink_id, |
| 35 const LocalFrameId& local_frame_id) { | 35 const LocalFrameId& local_frame_id) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 manager().DidSatisfySequences(kFrameSink2, &satisfied); | 240 manager().DidSatisfySequences(kFrameSink2, &satisfied); |
| 241 EXPECT_EQ(manager().GetSurfaceForId(id3), nullptr); | 241 EXPECT_EQ(manager().GetSurfaceForId(id3), nullptr); |
| 242 | 242 |
| 243 // Remove ref on |id2| and delete during GC. | 243 // Remove ref on |id2| and delete during GC. |
| 244 manager().RemoveSurfaceReference(id1, id2); | 244 manager().RemoveSurfaceReference(id1, id2); |
| 245 EXPECT_EQ(manager().GetSurfaceForId(id2), nullptr); | 245 EXPECT_EQ(manager().GetSurfaceForId(id2), nullptr); |
| 246 } | 246 } |
| 247 | 247 |
| 248 TEST_F(SurfaceManagerRefTest, TryAddReferenceToBadSurface) { | 248 TEST_F(SurfaceManagerRefTest, TryAddReferenceToBadSurface) { |
| 249 // Not creating an accompanying Surface and SurfaceFactory. | 249 // Not creating an accompanying Surface and SurfaceFactory. |
| 250 SurfaceId id(FrameSinkId(100u, 200u), | 250 SurfaceId id(FrameSinkId(100u, 200u), LocalFrameId(1u, 123123u)); |
| 251 LocalFrameId(1u, base::UnguessableToken::Create())); | |
| 252 | 251 |
| 253 // Adding reference from root to the Surface should do nothing because | 252 // Adding reference from root to the Surface should do nothing because |
| 254 // SurfaceManager doesn't know Surface for |id| exists. | 253 // SurfaceManager doesn't know Surface for |id| exists. |
| 255 manager().AddSurfaceReference(SurfaceManager::kRootSurfaceId, id); | 254 manager().AddSurfaceReference(SurfaceManager::kRootSurfaceId, id); |
| 256 EXPECT_EQ(manager().GetSurfaceReferenceCount(id), 0u); | 255 EXPECT_EQ(manager().GetSurfaceReferenceCount(id), 0u); |
| 257 } | 256 } |
| 258 | 257 |
| 259 TEST_F(SurfaceManagerRefTest, TryDoubleAddReference) { | 258 TEST_F(SurfaceManagerRefTest, TryDoubleAddReference) { |
| 260 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); | 259 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); |
| 261 SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1); | 260 SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 285 SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1); | 284 SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1); |
| 286 | 285 |
| 287 // Removing non-existent reference should be ignored. | 286 // Removing non-existent reference should be ignored. |
| 288 manager().AddSurfaceReference(id1, id2); | 287 manager().AddSurfaceReference(id1, id2); |
| 289 manager().RemoveSurfaceReference(id2, id1); | 288 manager().RemoveSurfaceReference(id2, id1); |
| 290 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 1u); | 289 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 1u); |
| 291 EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u); | 290 EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u); |
| 292 } | 291 } |
| 293 | 292 |
| 294 } // namespace cc | 293 } // namespace cc |
| OLD | NEW |