Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: cc/surfaces/frame_sink_manager.cc

Issue 2880023002: cc::SurfaceDependencyTracker should not crash when a Display goes away (Closed)
Patch Set: StrictMock => NiceMock Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
12 13
13 #if DCHECK_IS_ON() 14 #if DCHECK_IS_ON()
14 #include <sstream> 15 #include <sstream>
15 #endif 16 #endif
16 17
17 namespace cc { 18 namespace cc {
18 19
19 FrameSinkManager::FrameSinkSourceMapping::FrameSinkSourceMapping() 20 FrameSinkManager::FrameSinkSourceMapping::FrameSinkSourceMapping() = default;
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() {} 25 FrameSinkManager::FrameSinkSourceMapping::~FrameSinkSourceMapping() = default;
26 26
27 FrameSinkManager::FrameSinkManager() {} 27 FrameSinkManager::FrameSinkManager() = default;
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 28 matching lines...) Expand all
66 auto source_iter = frame_sink_source_map_.find(frame_sink_id); 66 auto source_iter = frame_sink_source_map_.find(frame_sink_id);
67 if (source_iter != frame_sink_source_map_.end()) { 67 if (source_iter != frame_sink_source_map_.end()) {
68 if (source_iter->second.source) 68 if (source_iter->second.source)
69 client_iter->second->SetBeginFrameSource(nullptr); 69 client_iter->second->SetBeginFrameSource(nullptr);
70 if (!source_iter->second.has_children()) 70 if (!source_iter->second.has_children())
71 frame_sink_source_map_.erase(source_iter); 71 frame_sink_source_map_.erase(source_iter);
72 } 72 }
73 clients_.erase(client_iter); 73 clients_.erase(client_iter);
74 } 74 }
75 75
76 std::unique_ptr<BeginFrameSource>
77 FrameSinkManager::CreatePrimaryBeginFrameSource() {
78 std::unique_ptr<PrimaryBeginFrameSource> begin_frame_source =
79 base::MakeUnique<PrimaryBeginFrameSource>();
80 begin_frame_source->Init(this);
81 return std::move(begin_frame_source);
82 }
83
76 void FrameSinkManager::RegisterBeginFrameSource( 84 void FrameSinkManager::RegisterBeginFrameSource(
77 BeginFrameSource* source, 85 BeginFrameSource* source,
78 const FrameSinkId& frame_sink_id) { 86 const FrameSinkId& frame_sink_id) {
79 DCHECK(source); 87 DCHECK(source);
80 DCHECK_EQ(registered_sources_.count(source), 0u); 88 DCHECK_EQ(registered_sources_.count(source), 0u);
81 DCHECK_EQ(valid_frame_sink_ids_.count(frame_sink_id), 1u); 89 DCHECK_EQ(valid_frame_sink_ids_.count(frame_sink_id), 1u);
82 90
83 registered_sources_[source] = frame_sink_id; 91 registered_sources_[source] = frame_sink_id;
84 RecursivelyAttachBeginFrameSource(frame_sink_id, source); 92 RecursivelyAttachBeginFrameSource(frame_sink_id, source);
93
94 for (auto& observer : observer_list_)
95 observer.OnBeginFrameSourceAdded(source);
85 } 96 }
86 97
87 void FrameSinkManager::UnregisterBeginFrameSource(BeginFrameSource* source) { 98 void FrameSinkManager::UnregisterBeginFrameSource(BeginFrameSource* source) {
88 DCHECK(source); 99 DCHECK(source);
89 DCHECK_EQ(registered_sources_.count(source), 1u); 100 DCHECK_EQ(registered_sources_.count(source), 1u);
90 101
91 FrameSinkId frame_sink_id = registered_sources_[source]; 102 FrameSinkId frame_sink_id = registered_sources_[source];
92 registered_sources_.erase(source); 103 registered_sources_.erase(source);
93 104
105 for (auto& observer : observer_list_)
106 observer.OnBeginFrameSourceRemoved(source);
107
94 if (frame_sink_source_map_.count(frame_sink_id) == 0u) 108 if (frame_sink_source_map_.count(frame_sink_id) == 0u)
95 return; 109 return;
96 110
97 // TODO(enne): these walks could be done in one step. 111 // TODO(enne): these walks could be done in one step.
98 // Remove this begin frame source from its subtree. 112 // Remove this begin frame source from its subtree.
99 RecursivelyDetachBeginFrameSource(frame_sink_id, source); 113 RecursivelyDetachBeginFrameSource(frame_sink_id, source);
100 // Then flush every remaining registered source to fix any sources that 114 // Then flush every remaining registered source to fix any sources that
101 // became null because of the previous step but that have an alternative. 115 // became null because of the previous step but that have an alternative.
102 for (auto source_iter : registered_sources_) 116 for (auto source_iter : registered_sources_)
103 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); 117 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first);
104 } 118 }
105 119
120 BeginFrameSource* FrameSinkManager::GetPrimaryBeginFrameSource() {
121 if (registered_sources_.empty())
122 return nullptr;
123 return registered_sources_.begin()->first;
124 }
125
106 void FrameSinkManager::RecursivelyAttachBeginFrameSource( 126 void FrameSinkManager::RecursivelyAttachBeginFrameSource(
107 const FrameSinkId& frame_sink_id, 127 const FrameSinkId& frame_sink_id,
108 BeginFrameSource* source) { 128 BeginFrameSource* source) {
109 FrameSinkSourceMapping& mapping = frame_sink_source_map_[frame_sink_id]; 129 FrameSinkSourceMapping& mapping = frame_sink_source_map_[frame_sink_id];
110 if (!mapping.source) { 130 if (!mapping.source) {
111 mapping.source = source; 131 mapping.source = source;
112 auto client_iter = clients_.find(frame_sink_id); 132 auto client_iter = clients_.find(frame_sink_id);
113 if (client_iter != clients_.end()) 133 if (client_iter != clients_.end())
114 client_iter->second->SetBeginFrameSource(source); 134 client_iter->second->SetBeginFrameSource(source);
115 } 135 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (!parent_source) 241 if (!parent_source)
222 return; 242 return;
223 243
224 // TODO(enne): these walks could be done in one step. 244 // TODO(enne): these walks could be done in one step.
225 RecursivelyDetachBeginFrameSource(child_frame_sink_id, parent_source); 245 RecursivelyDetachBeginFrameSource(child_frame_sink_id, parent_source);
226 for (auto source_iter : registered_sources_) 246 for (auto source_iter : registered_sources_)
227 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); 247 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first);
228 } 248 }
229 249
230 } // namespace cc 250 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698