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

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

Issue 2654653004: Remove SurfaceReferenceManager interface. (Closed)
Patch Set: Rebase + fix tests. Created 3 years, 10 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
« no previous file with comments | « cc/surfaces/surface_manager.h ('k') | cc/surfaces/surface_manager_ref_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <queue> 10 #include <queue>
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Check if we have the reference that is requested to be removed. We don't 209 // Check if we have the reference that is requested to be removed. We don't
210 // want to crash on bad input from a compromised client so just return early. 210 // want to crash on bad input from a compromised client so just return early.
211 if (parent_to_child_refs_.count(parent_id) == 0 || 211 if (parent_to_child_refs_.count(parent_id) == 0 ||
212 parent_to_child_refs_[parent_id].count(child_id) == 0) { 212 parent_to_child_refs_[parent_id].count(child_id) == 0) {
213 DLOG(ERROR) << "No reference from " << parent_id.ToString() << " to " 213 DLOG(ERROR) << "No reference from " << parent_id.ToString() << " to "
214 << child_id.ToString(); 214 << child_id.ToString();
215 return; 215 return;
216 } 216 }
217 217
218 RemoveSurfaceReferenceImpl(parent_id, child_id); 218 RemoveSurfaceReferenceImpl(parent_id, child_id);
219 GarbageCollectSurfaces();
220 } 219 }
221 220
222 void SurfaceManager::AddSurfaceReferences( 221 void SurfaceManager::AddSurfaceReferences(
223 const std::vector<SurfaceReference>& references) { 222 const std::vector<SurfaceReference>& references) {
224 DCHECK(thread_checker_.CalledOnValidThread()); 223 DCHECK(thread_checker_.CalledOnValidThread());
225 224
226 for (const auto& reference : references) 225 for (const auto& reference : references)
227 AddSurfaceReference(reference.parent_id(), reference.child_id()); 226 AddSurfaceReference(reference.parent_id(), reference.child_id());
228 } 227 }
229 228
230 void SurfaceManager::RemoveSurfaceReferences( 229 void SurfaceManager::RemoveSurfaceReferences(
231 const std::vector<SurfaceReference>& references) { 230 const std::vector<SurfaceReference>& references) {
232 DCHECK(thread_checker_.CalledOnValidThread()); 231 DCHECK(thread_checker_.CalledOnValidThread());
233 232
234 // TODO(kylechar): Each remove reference can trigger GC, it would be better if
235 // we GC only once if removing multiple references.
236 for (const auto& reference : references) 233 for (const auto& reference : references)
237 RemoveSurfaceReference(reference.parent_id(), reference.child_id()); 234 RemoveSurfaceReference(reference.parent_id(), reference.child_id());
238 }
239 235
240 size_t SurfaceManager::GetSurfaceReferenceCount( 236 GarbageCollectSurfaces();
241 const SurfaceId& surface_id) const {
242 auto iter = child_to_parent_refs_.find(surface_id);
243 if (iter == child_to_parent_refs_.end())
244 return 0;
245 return iter->second.size();
246 }
247
248 size_t SurfaceManager::GetReferencedSurfaceCount(
249 const SurfaceId& surface_id) const {
250 auto iter = parent_to_child_refs_.find(surface_id);
251 if (iter == parent_to_child_refs_.end())
252 return 0;
253 return iter->second.size();
254 } 237 }
255 238
256 void SurfaceManager::GarbageCollectSurfaces() { 239 void SurfaceManager::GarbageCollectSurfaces() {
257 if (surfaces_to_destroy_.empty()) 240 if (surfaces_to_destroy_.empty())
258 return; 241 return;
259 242
260 SurfaceIdSet reachable_surfaces = lifetime_type_ == LifetimeType::REFERENCES 243 SurfaceIdSet reachable_surfaces = lifetime_type_ == LifetimeType::REFERENCES
261 ? GetLiveSurfacesForReferences() 244 ? GetLiveSurfacesForReferences()
262 : GetLiveSurfacesForSequences(); 245 : GetLiveSurfacesForSequences();
263 246
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); 613 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end());
631 std::sort(children.begin(), children.end()); 614 std::sort(children.begin(), children.end());
632 615
633 for (const SurfaceId& child_id : children) 616 for (const SurfaceId& child_id : children)
634 SurfaceReferencesToStringImpl(child_id, indent + " ", str); 617 SurfaceReferencesToStringImpl(child_id, indent + " ", str);
635 } 618 }
636 } 619 }
637 #endif // DCHECK_IS_ON() 620 #endif // DCHECK_IS_ON()
638 621
639 } // namespace cc 622 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_manager.h ('k') | cc/surfaces/surface_manager_ref_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698