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_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 EmptySurfaceFactoryClient : public SurfaceFactoryClient { | |
|
danakj
2016/11/12 00:27:22
Stub is the word for this, rather than Empty
Saman Sami
2016/11/14 23:39:01
Done.
| |
| 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()).EvictFrame(); |
| 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 { |
| 60 factories_.clear(); | 68 factories_.clear(); |
| 61 manager_.reset(); | 69 manager_.reset(); |
| 62 } | 70 } |
| 63 | 71 |
| 64 std::unordered_map<FrameSinkId, | 72 std::unordered_map<FrameSinkId, |
| 65 std::unique_ptr<SurfaceFactory>, | 73 std::unique_ptr<SurfaceFactory>, |
| 66 FrameSinkIdHash> | 74 FrameSinkIdHash> |
| 67 factories_; | 75 factories_; |
| 68 std::unique_ptr<SurfaceManager> manager_; | 76 std::unique_ptr<SurfaceManager> manager_; |
| 77 EmptySurfaceFactoryClient client_; | |
| 69 }; | 78 }; |
| 70 | 79 |
| 71 } // namespace | 80 } // namespace |
| 72 | 81 |
| 73 TEST_F(SurfaceManagerRefTest, AddReference) { | 82 TEST_F(SurfaceManagerRefTest, AddReference) { |
| 74 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); | 83 SurfaceId id1 = CreateSurface(kFrameSink1, kLocalFrame1); |
| 75 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id1); | 84 manager().AddSurfaceReference(manager().GetRootSurfaceId(), id1); |
| 76 | 85 |
| 77 EXPECT_EQ(manager().GetSurfaceReferenceCount(id1), 1u); | 86 EXPECT_EQ(manager().GetSurfaceReferenceCount(id1), 1u); |
| 78 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 0u); | 87 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); | 294 SurfaceId id2 = CreateSurface(kFrameSink2, kLocalFrame1); |
| 286 | 295 |
| 287 // Removing non-existent reference should be ignored. | 296 // Removing non-existent reference should be ignored. |
| 288 manager().AddSurfaceReference(id1, id2); | 297 manager().AddSurfaceReference(id1, id2); |
| 289 manager().RemoveSurfaceReference(id2, id1); | 298 manager().RemoveSurfaceReference(id2, id1); |
| 290 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 1u); | 299 EXPECT_EQ(manager().GetReferencedSurfaceCount(id1), 1u); |
| 291 EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u); | 300 EXPECT_EQ(manager().GetSurfaceReferenceCount(id2), 1u); |
| 292 } | 301 } |
| 293 | 302 |
| 294 } // namespace cc | 303 } // namespace cc |
| OLD | NEW |