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_id.h" | 14 #include "cc/surfaces/surface_id.h" |
14 #include "cc/surfaces/surface_manager.h" | 15 #include "cc/surfaces/surface_manager.h" |
15 #include "cc/surfaces/surface_sequence_generator.h" | 16 #include "cc/surfaces/surface_sequence_generator.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
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 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 { |
| 28 public: |
| 29 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| 30 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {} |
| 31 }; |
| 32 |
27 // Tests for reference tracking in SurfaceManager. | 33 // Tests for reference tracking in SurfaceManager. |
28 class SurfaceManagerRefTest : public testing::Test { | 34 class SurfaceManagerRefTest : public testing::Test { |
29 public: | 35 public: |
30 SurfaceManager& manager() { return *manager_; } | 36 SurfaceManager& manager() { return *manager_; } |
31 | 37 |
32 // 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 |
33 // SurfaceFactory for |frame_sink_id| if necessary. | 39 // SurfaceFactory for |frame_sink_id| if necessary. |
34 SurfaceId CreateSurface(const FrameSinkId& frame_sink_id, | 40 SurfaceId CreateSurface(const FrameSinkId& frame_sink_id, |
35 const LocalFrameId& local_frame_id) { | 41 const LocalFrameId& local_frame_id) { |
36 GetFactory(frame_sink_id).Create(local_frame_id); | 42 GetFactory(frame_sink_id) |
| 43 .SubmitCompositorFrame(local_frame_id, CompositorFrame(), |
| 44 SurfaceFactory::DrawCallback()); |
37 return SurfaceId(frame_sink_id, local_frame_id); | 45 return SurfaceId(frame_sink_id, local_frame_id); |
38 } | 46 } |
39 | 47 |
40 // Destroy Surface with |surface_id|. | 48 // Destroy Surface with |surface_id|. |
41 void DestroySurface(const SurfaceId& surface_id) { | 49 void DestroySurface(const SurfaceId& surface_id) { |
42 GetFactory(surface_id.frame_sink_id()).Destroy(surface_id.local_frame_id()); | 50 GetFactory(surface_id.frame_sink_id()).EvictSurface(); |
43 } | 51 } |
44 | 52 |
45 protected: | 53 protected: |
46 SurfaceFactory& GetFactory(const FrameSinkId& frame_sink_id) { | 54 SurfaceFactory& GetFactory(const FrameSinkId& frame_sink_id) { |
47 auto& factory_ptr = factories_[frame_sink_id]; | 55 auto& factory_ptr = factories_[frame_sink_id]; |
48 if (!factory_ptr) | 56 if (!factory_ptr) |
49 factory_ptr = base::MakeUnique<SurfaceFactory>(frame_sink_id, | 57 factory_ptr = base::MakeUnique<SurfaceFactory>(frame_sink_id, |
50 manager_.get(), nullptr); | 58 manager_.get(), &client_); |
51 return *factory_ptr; | 59 return *factory_ptr; |
52 } | 60 } |
53 | 61 |
54 // testing::Test: | 62 // testing::Test: |
55 void SetUp() override { | 63 void SetUp() override { |
56 // Start each test with a fresh SurfaceManager instance. | 64 // Start each test with a fresh SurfaceManager instance. |
57 manager_ = base::MakeUnique<SurfaceManager>(); | 65 manager_ = base::MakeUnique<SurfaceManager>(); |
58 } | 66 } |
59 void TearDown() override { | 67 void TearDown() override { |
| 68 for (auto& factory : factories_) |
| 69 factory.second->EvictSurface(); |
60 factories_.clear(); | 70 factories_.clear(); |
61 manager_.reset(); | 71 manager_.reset(); |
62 } | 72 } |
63 | 73 |
64 std::unordered_map<FrameSinkId, | 74 std::unordered_map<FrameSinkId, |
65 std::unique_ptr<SurfaceFactory>, | 75 std::unique_ptr<SurfaceFactory>, |
66 FrameSinkIdHash> | 76 FrameSinkIdHash> |
67 factories_; | 77 factories_; |
68 std::unique_ptr<SurfaceManager> manager_; | 78 std::unique_ptr<SurfaceManager> manager_; |
| 79 StubSurfaceFactoryClient client_; |
69 }; | 80 }; |
70 | 81 |
71 } // namespace | 82 } // namespace |
72 | 83 |
73 TEST_F(SurfaceManagerRefTest, AddReference) { | 84 TEST_F(SurfaceManagerRefTest, AddReference) { |
74 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); | 85 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); |
75 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id1); | 86 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id1); |
76 | 87 |
77 EXPECT_EQ(manager().GetSurfaceReferenceCount(id1), 1u); | 88 EXPECT_EQ(manager().GetSurfaceReferenceCount(id1), 1u); |
78 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 0u); | 89 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 0u); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1); | 296 SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1); |
286 | 297 |
287 // Removing non-existent reference should be ignored. | 298 // Removing non-existent reference should be ignored. |
288 manager().AddSurfaceReference(id1, id2); | 299 manager().AddSurfaceReference(id1, id2); |
289 manager().RemoveSurfaceReference(id2, id1); | 300 manager().RemoveSurfaceReference(id2, id1); |
290 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 1u); | 301 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 1u); |
291 EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u); | 302 EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u); |
292 } | 303 } |
293 | 304 |
294 } // namespace cc | 305 } // namespace cc |
OLD | NEW |