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

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

Issue 2136413002: Update Surface ID Terminology (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed webkit_unit_tests Created 4 years, 5 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/surface_manager.h" 5 #include "cc/surfaces/surface_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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 surface_map_.erase(it); 58 surface_map_.erase(it);
59 } 59 }
60 60
61 void SurfaceManager::Destroy(std::unique_ptr<Surface> surface) { 61 void SurfaceManager::Destroy(std::unique_ptr<Surface> surface) {
62 DCHECK(thread_checker_.CalledOnValidThread()); 62 DCHECK(thread_checker_.CalledOnValidThread());
63 surface->set_destroyed(true); 63 surface->set_destroyed(true);
64 surfaces_to_destroy_.push_back(std::move(surface)); 64 surfaces_to_destroy_.push_back(std::move(surface));
65 GarbageCollectSurfaces(); 65 GarbageCollectSurfaces();
66 } 66 }
67 67
68 void SurfaceManager::DidSatisfySequences(uint32_t id_namespace, 68 void SurfaceManager::DidSatisfySequences(uint32_t client_id,
69 std::vector<uint32_t>* sequence) { 69 std::vector<uint32_t>* sequence) {
70 DCHECK(thread_checker_.CalledOnValidThread()); 70 DCHECK(thread_checker_.CalledOnValidThread());
71 for (std::vector<uint32_t>::iterator it = sequence->begin(); 71 for (std::vector<uint32_t>::iterator it = sequence->begin();
72 it != sequence->end(); 72 it != sequence->end();
73 ++it) { 73 ++it) {
74 satisfied_sequences_.insert(SurfaceSequence(id_namespace, *it)); 74 satisfied_sequences_.insert(SurfaceSequence(client_id, *it));
75 } 75 }
76 sequence->clear(); 76 sequence->clear();
77 GarbageCollectSurfaces(); 77 GarbageCollectSurfaces();
78 } 78 }
79 79
80 void SurfaceManager::RegisterSurfaceIdNamespace(uint32_t id_namespace) { 80 void SurfaceManager::RegisterSurfaceClientId(uint32_t client_id) {
81 bool inserted = valid_surface_id_namespaces_.insert(id_namespace).second; 81 bool inserted = valid_surface_client_ids_.insert(client_id).second;
82 DCHECK(inserted); 82 DCHECK(inserted);
83 } 83 }
84 84
85 void SurfaceManager::InvalidateSurfaceIdNamespace(uint32_t id_namespace) { 85 void SurfaceManager::InvalidateSurfaceClientId(uint32_t client_id) {
86 valid_surface_id_namespaces_.erase(id_namespace); 86 valid_surface_client_ids_.erase(client_id);
87 GarbageCollectSurfaces(); 87 GarbageCollectSurfaces();
88 } 88 }
89 89
90 void SurfaceManager::GarbageCollectSurfaces() { 90 void SurfaceManager::GarbageCollectSurfaces() {
91 // Simple mark and sweep GC. 91 // Simple mark and sweep GC.
92 // TODO(jbauman): Reduce the amount of work when nothing needs to be 92 // TODO(jbauman): Reduce the amount of work when nothing needs to be
93 // destroyed. 93 // destroyed.
94 std::vector<SurfaceId> live_surfaces; 94 std::vector<SurfaceId> live_surfaces;
95 std::set<SurfaceId> live_surfaces_set; 95 std::set<SurfaceId> live_surfaces_set;
96 96
97 // GC roots are surfaces that have not been destroyed, or have not had all 97 // GC roots are surfaces that have not been destroyed, or have not had all
98 // their destruction dependencies satisfied. 98 // their destruction dependencies satisfied.
99 for (auto& map_entry : surface_map_) { 99 for (auto& map_entry : surface_map_) {
100 map_entry.second->SatisfyDestructionDependencies( 100 map_entry.second->SatisfyDestructionDependencies(
101 &satisfied_sequences_, &valid_surface_id_namespaces_); 101 &satisfied_sequences_, &valid_surface_client_ids_);
102 if (!map_entry.second->destroyed() || 102 if (!map_entry.second->destroyed() ||
103 map_entry.second->GetDestructionDependencyCount()) { 103 map_entry.second->GetDestructionDependencyCount()) {
104 live_surfaces_set.insert(map_entry.first); 104 live_surfaces_set.insert(map_entry.first);
105 live_surfaces.push_back(map_entry.first); 105 live_surfaces.push_back(map_entry.first);
106 } 106 }
107 } 107 }
108 108
109 // Mark all surfaces reachable from live surfaces by adding them to 109 // Mark all surfaces reachable from live surfaces by adding them to
110 // live_surfaces and live_surfaces_set. 110 // live_surfaces and live_surfaces_set.
111 for (size_t i = 0; i < live_surfaces.size(); i++) { 111 for (size_t i = 0; i < live_surfaces.size(); i++) {
(...skipping 24 matching lines...) Expand all
136 to_destroy.push_back(std::move(surf)); 136 to_destroy.push_back(std::move(surf));
137 } else { 137 } else {
138 ++dest_it; 138 ++dest_it;
139 } 139 }
140 } 140 }
141 141
142 to_destroy.clear(); 142 to_destroy.clear();
143 } 143 }
144 144
145 void SurfaceManager::RegisterSurfaceFactoryClient( 145 void SurfaceManager::RegisterSurfaceFactoryClient(
146 uint32_t id_namespace, 146 uint32_t client_id,
147 SurfaceFactoryClient* client) { 147 SurfaceFactoryClient* client) {
148 DCHECK(client); 148 DCHECK(client);
149 DCHECK(!namespace_client_map_[id_namespace].client); 149 DCHECK(!namespace_client_map_[client_id].client);
150 DCHECK_EQ(valid_surface_id_namespaces_.count(id_namespace), 1u); 150 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u);
151 151
152 auto iter = namespace_client_map_.find(id_namespace); 152 auto iter = namespace_client_map_.find(client_id);
153 if (iter == namespace_client_map_.end()) { 153 if (iter == namespace_client_map_.end()) {
154 auto insert_result = namespace_client_map_.insert( 154 auto insert_result = namespace_client_map_.insert(
155 std::make_pair(id_namespace, ClientSourceMapping())); 155 std::make_pair(client_id, ClientSourceMapping()));
156 DCHECK(insert_result.second); 156 DCHECK(insert_result.second);
157 iter = insert_result.first; 157 iter = insert_result.first;
158 } 158 }
159 iter->second.client = client; 159 iter->second.client = client;
160 160
161 // Propagate any previously set sources to the new client. 161 // Propagate any previously set sources to the new client.
162 if (iter->second.source) 162 if (iter->second.source)
163 client->SetBeginFrameSource(iter->second.source); 163 client->SetBeginFrameSource(iter->second.source);
164 } 164 }
165 165
166 void SurfaceManager::UnregisterSurfaceFactoryClient(uint32_t id_namespace) { 166 void SurfaceManager::UnregisterSurfaceFactoryClient(uint32_t client_id) {
167 DCHECK_EQ(valid_surface_id_namespaces_.count(id_namespace), 1u); 167 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u);
168 DCHECK_EQ(namespace_client_map_.count(id_namespace), 1u); 168 DCHECK_EQ(namespace_client_map_.count(client_id), 1u);
169 169
170 auto iter = namespace_client_map_.find(id_namespace); 170 auto iter = namespace_client_map_.find(client_id);
171 if (iter->second.source) 171 if (iter->second.source)
172 iter->second.client->SetBeginFrameSource(nullptr); 172 iter->second.client->SetBeginFrameSource(nullptr);
173 iter->second.client = nullptr; 173 iter->second.client = nullptr;
174 174
175 // The SurfaceFactoryClient and hierarchy can be registered/unregistered 175 // The SurfaceFactoryClient and hierarchy can be registered/unregistered
176 // in either order, so empty namespace_client_map entries need to be 176 // in either order, so empty namespace_client_map entries need to be
177 // checked when removing either clients or relationships. 177 // checked when removing either clients or relationships.
178 if (iter->second.is_empty()) 178 if (iter->second.is_empty())
179 namespace_client_map_.erase(iter); 179 namespace_client_map_.erase(iter);
180 } 180 }
181 181
182 void SurfaceManager::RegisterBeginFrameSource(BeginFrameSource* source, 182 void SurfaceManager::RegisterBeginFrameSource(BeginFrameSource* source,
183 uint32_t id_namespace) { 183 uint32_t client_id) {
184 DCHECK(source); 184 DCHECK(source);
185 DCHECK_EQ(registered_sources_.count(source), 0u); 185 DCHECK_EQ(registered_sources_.count(source), 0u);
186 DCHECK_EQ(valid_surface_id_namespaces_.count(id_namespace), 1u); 186 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u);
187 187
188 registered_sources_[source] = id_namespace; 188 registered_sources_[source] = client_id;
189 RecursivelyAttachBeginFrameSource(id_namespace, source); 189 RecursivelyAttachBeginFrameSource(client_id, source);
190 } 190 }
191 191
192 void SurfaceManager::UnregisterBeginFrameSource(BeginFrameSource* source) { 192 void SurfaceManager::UnregisterBeginFrameSource(BeginFrameSource* source) {
193 DCHECK(source); 193 DCHECK(source);
194 DCHECK_EQ(registered_sources_.count(source), 1u); 194 DCHECK_EQ(registered_sources_.count(source), 1u);
195 195
196 uint32_t id_namespace = registered_sources_[source]; 196 uint32_t client_id = registered_sources_[source];
197 registered_sources_.erase(source); 197 registered_sources_.erase(source);
198 198
199 if (namespace_client_map_.count(id_namespace) == 0u) 199 if (namespace_client_map_.count(client_id) == 0u)
200 return; 200 return;
201 201
202 // TODO(enne): these walks could be done in one step. 202 // TODO(enne): these walks could be done in one step.
203 // Remove this begin frame source from its subtree. 203 // Remove this begin frame source from its subtree.
204 RecursivelyDetachBeginFrameSource(id_namespace, source); 204 RecursivelyDetachBeginFrameSource(client_id, source);
205 // Then flush every remaining registered source to fix any sources that 205 // Then flush every remaining registered source to fix any sources that
206 // became null because of the previous step but that have an alternative. 206 // became null because of the previous step but that have an alternative.
207 for (auto source_iter : registered_sources_) 207 for (auto source_iter : registered_sources_)
208 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); 208 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first);
209 } 209 }
210 210
211 void SurfaceManager::RecursivelyAttachBeginFrameSource( 211 void SurfaceManager::RecursivelyAttachBeginFrameSource(
212 uint32_t id_namespace, 212 uint32_t client_id,
213 BeginFrameSource* source) { 213 BeginFrameSource* source) {
214 ClientSourceMapping& mapping = namespace_client_map_[id_namespace]; 214 ClientSourceMapping& mapping = namespace_client_map_[client_id];
215 if (!mapping.source) { 215 if (!mapping.source) {
216 mapping.source = source; 216 mapping.source = source;
217 if (mapping.client) 217 if (mapping.client)
218 mapping.client->SetBeginFrameSource(source); 218 mapping.client->SetBeginFrameSource(source);
219 } 219 }
220 for (size_t i = 0; i < mapping.children.size(); ++i) 220 for (size_t i = 0; i < mapping.children.size(); ++i)
221 RecursivelyAttachBeginFrameSource(mapping.children[i], source); 221 RecursivelyAttachBeginFrameSource(mapping.children[i], source);
222 } 222 }
223 223
224 void SurfaceManager::RecursivelyDetachBeginFrameSource( 224 void SurfaceManager::RecursivelyDetachBeginFrameSource(
225 uint32_t id_namespace, 225 uint32_t client_id,
226 BeginFrameSource* source) { 226 BeginFrameSource* source) {
227 auto iter = namespace_client_map_.find(id_namespace); 227 auto iter = namespace_client_map_.find(client_id);
228 if (iter == namespace_client_map_.end()) 228 if (iter == namespace_client_map_.end())
229 return; 229 return;
230 if (iter->second.source == source) { 230 if (iter->second.source == source) {
231 iter->second.source = nullptr; 231 iter->second.source = nullptr;
232 if (iter->second.client) 232 if (iter->second.client)
233 iter->second.client->SetBeginFrameSource(nullptr); 233 iter->second.client->SetBeginFrameSource(nullptr);
234 } 234 }
235 235
236 if (iter->second.is_empty()) { 236 if (iter->second.is_empty()) {
237 namespace_client_map_.erase(iter); 237 namespace_client_map_.erase(iter);
(...skipping 18 matching lines...) Expand all
256 return true; 256 return true;
257 if (ChildContains(children[i], search_namespace)) 257 if (ChildContains(children[i], search_namespace))
258 return true; 258 return true;
259 } 259 }
260 return false; 260 return false;
261 } 261 }
262 262
263 void SurfaceManager::RegisterSurfaceNamespaceHierarchy( 263 void SurfaceManager::RegisterSurfaceNamespaceHierarchy(
264 uint32_t parent_namespace, 264 uint32_t parent_namespace,
265 uint32_t child_namespace) { 265 uint32_t child_namespace) {
266 DCHECK_EQ(valid_surface_id_namespaces_.count(parent_namespace), 1u); 266 DCHECK_EQ(valid_surface_client_ids_.count(parent_namespace), 1u);
267 DCHECK_EQ(valid_surface_id_namespaces_.count(child_namespace), 1u); 267 DCHECK_EQ(valid_surface_client_ids_.count(child_namespace), 1u);
268 268
269 // If it's possible to reach the parent through the child's descendant chain, 269 // If it's possible to reach the parent through the child's descendant chain,
270 // then this will create an infinite loop. Might as well just crash here. 270 // then this will create an infinite loop. Might as well just crash here.
271 CHECK(!ChildContains(child_namespace, parent_namespace)); 271 CHECK(!ChildContains(child_namespace, parent_namespace));
272 272
273 std::vector<uint32_t>& children = 273 std::vector<uint32_t>& children =
274 namespace_client_map_[parent_namespace].children; 274 namespace_client_map_[parent_namespace].children;
275 for (size_t i = 0; i < children.size(); ++i) 275 for (size_t i = 0; i < children.size(); ++i)
276 DCHECK_NE(children[i], child_namespace); 276 DCHECK_NE(children[i], child_namespace);
277 children.push_back(child_namespace); 277 children.push_back(child_namespace);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 341
342 bool SurfaceManager::SurfaceModified(SurfaceId surface_id) { 342 bool SurfaceManager::SurfaceModified(SurfaceId surface_id) {
343 CHECK(thread_checker_.CalledOnValidThread()); 343 CHECK(thread_checker_.CalledOnValidThread());
344 bool changed = false; 344 bool changed = false;
345 FOR_EACH_OBSERVER(SurfaceDamageObserver, observer_list_, 345 FOR_EACH_OBSERVER(SurfaceDamageObserver, observer_list_,
346 OnSurfaceDamaged(surface_id, &changed)); 346 OnSurfaceDamaged(surface_id, &changed));
347 return changed; 347 return changed;
348 } 348 }
349 349
350 } // namespace cc 350 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698