| 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 "cc/scheduler/begin_frame_source.h" | 7 #include "cc/scheduler/begin_frame_source.h" |
| 8 #include "cc/surfaces/surface_factory_client.h" | 8 #include "cc/surfaces/surface_factory_client.h" |
| 9 #include "cc/surfaces/surface_manager.h" | 9 #include "cc/surfaces/surface_manager.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 DCHECK(!source_ || !begin_frame_source); | 49 DCHECK(!source_ || !begin_frame_source); |
| 50 source_ = begin_frame_source; | 50 source_ = begin_frame_source; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 BeginFrameSource* source_; | 54 BeginFrameSource* source_; |
| 55 SurfaceManager* manager_; | 55 SurfaceManager* manager_; |
| 56 uint32_t id_namespace_; | 56 uint32_t id_namespace_; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 class EmptyBeginFrameSource : public BeginFrameSource { | |
| 60 public: | |
| 61 void DidFinishFrame(BeginFrameObserver* obs, | |
| 62 size_t remaining_frames) override {} | |
| 63 void AddObserver(BeginFrameObserver* obs) override {} | |
| 64 void RemoveObserver(BeginFrameObserver* obs) override {} | |
| 65 }; | |
| 66 | |
| 67 class SurfaceManagerTest : public testing::Test { | 59 class SurfaceManagerTest : public testing::Test { |
| 68 public: | 60 public: |
| 69 // These tests don't care about namespace registration, so just preregister | 61 // These tests don't care about namespace registration, so just preregister |
| 70 // a set of namespaces that tests can use freely without worrying if they're | 62 // a set of namespaces that tests can use freely without worrying if they're |
| 71 // valid or not. | 63 // valid or not. |
| 72 enum { MAX_NAMESPACE = 10 }; | 64 enum { MAX_NAMESPACE = 10 }; |
| 73 | 65 |
| 74 SurfaceManagerTest() { | 66 SurfaceManagerTest() { |
| 75 for (size_t i = 0; i < MAX_NAMESPACE; ++i) | 67 for (size_t i = 0; i < MAX_NAMESPACE; ++i) |
| 76 manager_.RegisterSurfaceClientId(i); | 68 manager_.RegisterSurfaceClientId(i); |
| 77 } | 69 } |
| 78 | 70 |
| 79 ~SurfaceManagerTest() override { | 71 ~SurfaceManagerTest() override { |
| 80 for (size_t i = 0; i < MAX_NAMESPACE; ++i) | 72 for (size_t i = 0; i < MAX_NAMESPACE; ++i) |
| 81 manager_.InvalidateSurfaceClientId(i); | 73 manager_.InvalidateSurfaceClientId(i); |
| 82 } | 74 } |
| 83 | 75 |
| 84 protected: | 76 protected: |
| 85 SurfaceManager manager_; | 77 SurfaceManager manager_; |
| 86 }; | 78 }; |
| 87 | 79 |
| 88 TEST_F(SurfaceManagerTest, SingleClients) { | 80 TEST_F(SurfaceManagerTest, SingleClients) { |
| 89 FakeSurfaceFactoryClient client(1); | 81 FakeSurfaceFactoryClient client(1); |
| 90 FakeSurfaceFactoryClient other_client(2); | 82 FakeSurfaceFactoryClient other_client(2); |
| 91 EmptyBeginFrameSource source; | 83 StubBeginFrameSource source; |
| 92 | 84 |
| 93 EXPECT_EQ(client.source(), nullptr); | 85 EXPECT_EQ(client.source(), nullptr); |
| 94 EXPECT_EQ(other_client.source(), nullptr); | 86 EXPECT_EQ(other_client.source(), nullptr); |
| 95 client.Register(&manager_); | 87 client.Register(&manager_); |
| 96 other_client.Register(&manager_); | 88 other_client.Register(&manager_); |
| 97 EXPECT_EQ(client.source(), nullptr); | 89 EXPECT_EQ(client.source(), nullptr); |
| 98 EXPECT_EQ(other_client.source(), nullptr); | 90 EXPECT_EQ(other_client.source(), nullptr); |
| 99 | 91 |
| 100 // Test setting unsetting BFS | 92 // Test setting unsetting BFS |
| 101 manager_.RegisterBeginFrameSource(&source, client.id_namespace()); | 93 manager_.RegisterBeginFrameSource(&source, client.id_namespace()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 EXPECT_EQ(other_client.source(), nullptr); | 106 EXPECT_EQ(other_client.source(), nullptr); |
| 115 | 107 |
| 116 // Re-set BFS for original | 108 // Re-set BFS for original |
| 117 manager_.RegisterBeginFrameSource(&source, client.id_namespace()); | 109 manager_.RegisterBeginFrameSource(&source, client.id_namespace()); |
| 118 EXPECT_EQ(client.source(), &source); | 110 EXPECT_EQ(client.source(), &source); |
| 119 manager_.UnregisterBeginFrameSource(&source); | 111 manager_.UnregisterBeginFrameSource(&source); |
| 120 EXPECT_EQ(client.source(), nullptr); | 112 EXPECT_EQ(client.source(), nullptr); |
| 121 } | 113 } |
| 122 | 114 |
| 123 TEST_F(SurfaceManagerTest, MultipleDisplays) { | 115 TEST_F(SurfaceManagerTest, MultipleDisplays) { |
| 124 EmptyBeginFrameSource root1_source; | 116 StubBeginFrameSource root1_source; |
| 125 EmptyBeginFrameSource root2_source; | 117 StubBeginFrameSource root2_source; |
| 126 | 118 |
| 127 // root1 -> A -> B | 119 // root1 -> A -> B |
| 128 // root2 -> C | 120 // root2 -> C |
| 129 FakeSurfaceFactoryClient root1(1, &manager_); | 121 FakeSurfaceFactoryClient root1(1, &manager_); |
| 130 FakeSurfaceFactoryClient root2(2, &manager_); | 122 FakeSurfaceFactoryClient root2(2, &manager_); |
| 131 FakeSurfaceFactoryClient client_a(3, &manager_); | 123 FakeSurfaceFactoryClient client_a(3, &manager_); |
| 132 FakeSurfaceFactoryClient client_b(4, &manager_); | 124 FakeSurfaceFactoryClient client_b(4, &manager_); |
| 133 FakeSurfaceFactoryClient client_c(5, &manager_); | 125 FakeSurfaceFactoryClient client_c(5, &manager_); |
| 134 | 126 |
| 135 manager_.RegisterBeginFrameSource(&root1_source, root1.id_namespace()); | 127 manager_.RegisterBeginFrameSource(&root1_source, root1.id_namespace()); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // A valid but not attached to anything. | 276 // A valid but not attached to anything. |
| 285 EXPECT_EQ(client_a_.source(), &source_); | 277 EXPECT_EQ(client_a_.source(), &source_); |
| 286 EXPECT_EQ(client_b_.source(), nullptr); | 278 EXPECT_EQ(client_b_.source(), nullptr); |
| 287 EXPECT_EQ(client_c_.source(), nullptr); | 279 EXPECT_EQ(client_c_.source(), nullptr); |
| 288 return; | 280 return; |
| 289 } | 281 } |
| 290 | 282 |
| 291 AssertAllValidBFS(); | 283 AssertAllValidBFS(); |
| 292 } | 284 } |
| 293 | 285 |
| 294 EmptyBeginFrameSource source_; | 286 StubBeginFrameSource source_; |
| 295 // A -> B -> C hierarchy, with A always having the BFS. | 287 // A -> B -> C hierarchy, with A always having the BFS. |
| 296 FakeSurfaceFactoryClient client_a_; | 288 FakeSurfaceFactoryClient client_a_; |
| 297 FakeSurfaceFactoryClient client_b_; | 289 FakeSurfaceFactoryClient client_b_; |
| 298 FakeSurfaceFactoryClient client_c_; | 290 FakeSurfaceFactoryClient client_c_; |
| 299 | 291 |
| 300 bool hierarchy_registered_; | 292 bool hierarchy_registered_; |
| 301 bool clients_registered_; | 293 bool clients_registered_; |
| 302 bool bfs_registered_; | 294 bool bfs_registered_; |
| 303 }; | 295 }; |
| 304 | 296 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 364 } |
| 373 | 365 |
| 374 INSTANTIATE_TEST_CASE_P( | 366 INSTANTIATE_TEST_CASE_P( |
| 375 SurfaceManagerOrderingParamTestInstantiation, | 367 SurfaceManagerOrderingParamTestInstantiation, |
| 376 SurfaceManagerOrderingParamTest, | 368 SurfaceManagerOrderingParamTest, |
| 377 ::testing::Combine(::testing::ValuesIn(kRegisterOrderList), | 369 ::testing::Combine(::testing::ValuesIn(kRegisterOrderList), |
| 378 ::testing::ValuesIn(kUnregisterOrderList), | 370 ::testing::ValuesIn(kUnregisterOrderList), |
| 379 ::testing::ValuesIn(kBFSOrderList))); | 371 ::testing::ValuesIn(kBFSOrderList))); |
| 380 | 372 |
| 381 } // namespace cc | 373 } // namespace cc |
| OLD | NEW |