OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/surfaces/frame_sink_manager.h" | 5 #include "cc/surfaces/frame_sink_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "cc/surfaces/frame_sink_manager_client.h" | 11 #include "cc/surfaces/frame_sink_manager_client.h" |
12 #include "cc/surfaces/primary_begin_frame_source.h" | |
13 | 12 |
14 #if DCHECK_IS_ON() | 13 #if DCHECK_IS_ON() |
15 #include <sstream> | 14 #include <sstream> |
16 #endif | 15 #endif |
17 | 16 |
18 namespace cc { | 17 namespace cc { |
19 | 18 |
20 FrameSinkManager::FrameSinkSourceMapping::FrameSinkSourceMapping() = default; | 19 FrameSinkManager::FrameSinkSourceMapping::FrameSinkSourceMapping() |
| 20 : source(nullptr) {} |
21 | 21 |
22 FrameSinkManager::FrameSinkSourceMapping::FrameSinkSourceMapping( | 22 FrameSinkManager::FrameSinkSourceMapping::FrameSinkSourceMapping( |
23 const FrameSinkSourceMapping& other) = default; | 23 const FrameSinkSourceMapping& other) = default; |
24 | 24 |
25 FrameSinkManager::FrameSinkSourceMapping::~FrameSinkSourceMapping() = default; | 25 FrameSinkManager::FrameSinkSourceMapping::~FrameSinkSourceMapping() {} |
26 | 26 |
27 FrameSinkManager::FrameSinkManager() = default; | 27 FrameSinkManager::FrameSinkManager() {} |
28 | 28 |
29 FrameSinkManager::~FrameSinkManager() { | 29 FrameSinkManager::~FrameSinkManager() { |
30 // All CompositorFrameSinks should be unregistered prior to | 30 // All CompositorFrameSinks should be unregistered prior to |
31 // SurfaceManager destruction. | 31 // SurfaceManager destruction. |
32 DCHECK_EQ(clients_.size(), 0u); | 32 DCHECK_EQ(clients_.size(), 0u); |
33 DCHECK_EQ(registered_sources_.size(), 0u); | 33 DCHECK_EQ(registered_sources_.size(), 0u); |
34 } | 34 } |
35 | 35 |
36 void FrameSinkManager::RegisterFrameSinkId(const FrameSinkId& frame_sink_id) { | 36 void FrameSinkManager::RegisterFrameSinkId(const FrameSinkId& frame_sink_id) { |
37 bool inserted = valid_frame_sink_ids_.insert(frame_sink_id).second; | 37 bool inserted = valid_frame_sink_ids_.insert(frame_sink_id).second; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 void FrameSinkManager::RegisterBeginFrameSource( | 76 void FrameSinkManager::RegisterBeginFrameSource( |
77 BeginFrameSource* source, | 77 BeginFrameSource* source, |
78 const FrameSinkId& frame_sink_id) { | 78 const FrameSinkId& frame_sink_id) { |
79 DCHECK(source); | 79 DCHECK(source); |
80 DCHECK_EQ(registered_sources_.count(source), 0u); | 80 DCHECK_EQ(registered_sources_.count(source), 0u); |
81 DCHECK_EQ(valid_frame_sink_ids_.count(frame_sink_id), 1u); | 81 DCHECK_EQ(valid_frame_sink_ids_.count(frame_sink_id), 1u); |
82 | 82 |
83 registered_sources_[source] = frame_sink_id; | 83 registered_sources_[source] = frame_sink_id; |
84 RecursivelyAttachBeginFrameSource(frame_sink_id, source); | 84 RecursivelyAttachBeginFrameSource(frame_sink_id, source); |
85 | |
86 primary_source_.OnBeginFrameSourceAdded(source); | |
87 } | 85 } |
88 | 86 |
89 void FrameSinkManager::UnregisterBeginFrameSource(BeginFrameSource* source) { | 87 void FrameSinkManager::UnregisterBeginFrameSource(BeginFrameSource* source) { |
90 DCHECK(source); | 88 DCHECK(source); |
91 DCHECK_EQ(registered_sources_.count(source), 1u); | 89 DCHECK_EQ(registered_sources_.count(source), 1u); |
92 | 90 |
93 FrameSinkId frame_sink_id = registered_sources_[source]; | 91 FrameSinkId frame_sink_id = registered_sources_[source]; |
94 registered_sources_.erase(source); | 92 registered_sources_.erase(source); |
95 | 93 |
96 primary_source_.OnBeginFrameSourceRemoved(source); | |
97 | |
98 if (frame_sink_source_map_.count(frame_sink_id) == 0u) | 94 if (frame_sink_source_map_.count(frame_sink_id) == 0u) |
99 return; | 95 return; |
100 | 96 |
101 // TODO(enne): these walks could be done in one step. | 97 // TODO(enne): these walks could be done in one step. |
102 // Remove this begin frame source from its subtree. | 98 // Remove this begin frame source from its subtree. |
103 RecursivelyDetachBeginFrameSource(frame_sink_id, source); | 99 RecursivelyDetachBeginFrameSource(frame_sink_id, source); |
104 // Then flush every remaining registered source to fix any sources that | 100 // Then flush every remaining registered source to fix any sources that |
105 // became null because of the previous step but that have an alternative. | 101 // became null because of the previous step but that have an alternative. |
106 for (auto source_iter : registered_sources_) | 102 for (auto source_iter : registered_sources_) |
107 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); | 103 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); |
108 } | 104 } |
109 | 105 |
110 BeginFrameSource* FrameSinkManager::GetPrimaryBeginFrameSource() { | |
111 return &primary_source_; | |
112 } | |
113 | |
114 void FrameSinkManager::RecursivelyAttachBeginFrameSource( | 106 void FrameSinkManager::RecursivelyAttachBeginFrameSource( |
115 const FrameSinkId& frame_sink_id, | 107 const FrameSinkId& frame_sink_id, |
116 BeginFrameSource* source) { | 108 BeginFrameSource* source) { |
117 FrameSinkSourceMapping& mapping = frame_sink_source_map_[frame_sink_id]; | 109 FrameSinkSourceMapping& mapping = frame_sink_source_map_[frame_sink_id]; |
118 if (!mapping.source) { | 110 if (!mapping.source) { |
119 mapping.source = source; | 111 mapping.source = source; |
120 auto client_iter = clients_.find(frame_sink_id); | 112 auto client_iter = clients_.find(frame_sink_id); |
121 if (client_iter != clients_.end()) | 113 if (client_iter != clients_.end()) |
122 client_iter->second->SetBeginFrameSource(source); | 114 client_iter->second->SetBeginFrameSource(source); |
123 } | 115 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 if (!parent_source) | 221 if (!parent_source) |
230 return; | 222 return; |
231 | 223 |
232 // TODO(enne): these walks could be done in one step. | 224 // TODO(enne): these walks could be done in one step. |
233 RecursivelyDetachBeginFrameSource(child_frame_sink_id, parent_source); | 225 RecursivelyDetachBeginFrameSource(child_frame_sink_id, parent_source); |
234 for (auto source_iter : registered_sources_) | 226 for (auto source_iter : registered_sources_) |
235 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); | 227 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); |
236 } | 228 } |
237 | 229 |
238 } // namespace cc | 230 } // namespace cc |
OLD | NEW |