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

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

Issue 553213003: Avoid destroying surface before the parent surface stops referencing it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "cc/surfaces/surface.h" 8 #include "cc/surfaces/surface.h"
9 #include "cc/surfaces/surface_id_allocator.h"
9 10
10 namespace cc { 11 namespace cc {
11 12
12 SurfaceManager::SurfaceManager() { 13 SurfaceManager::SurfaceManager() {
13 } 14 }
14 15
15 SurfaceManager::~SurfaceManager() { 16 SurfaceManager::~SurfaceManager() {
17 for (SurfaceDestroyList::iterator it = surfaces_to_destroy_.begin();
18 it != surfaces_to_destroy_.end();
19 ++it) {
20 DeregisterSurface(it->first->surface_id());
21 delete it->first;
22 }
16 DCHECK_EQ(0u, surface_map_.size()); 23 DCHECK_EQ(0u, surface_map_.size());
17 } 24 }
18 25
19 void SurfaceManager::RegisterSurface(Surface* surface) { 26 void SurfaceManager::RegisterSurface(Surface* surface) {
20 DCHECK(surface); 27 DCHECK(surface);
21 DCHECK(!surface_map_.count(surface->surface_id())); 28 DCHECK(!surface_map_.count(surface->surface_id()));
22 surface_map_[surface->surface_id()] = surface; 29 surface_map_[surface->surface_id()] = surface;
23 } 30 }
24 31
25 void SurfaceManager::DeregisterSurface(SurfaceId surface_id) { 32 void SurfaceManager::DeregisterSurface(SurfaceId surface_id) {
26 SurfaceMap::iterator it = surface_map_.find(surface_id); 33 SurfaceMap::iterator it = surface_map_.find(surface_id);
27 DCHECK(it != surface_map_.end()); 34 DCHECK(it != surface_map_.end());
28 surface_map_.erase(it); 35 surface_map_.erase(it);
29 } 36 }
30 37
38 void SurfaceManager::DestroyOnSequence(
39 scoped_ptr<Surface> surface,
40 const std::set<SurfaceSequence>& dependency_set) {
41 surfaces_to_destroy_.push_back(make_pair(surface.release(), dependency_set));
42 AttemptSatisfyDestroy();
43 }
44
45 void SurfaceManager::SatisfiesSequence(SurfaceId id,
46 std::vector<uint32_t>* sequence) {
47 for (std::vector<uint32_t>::iterator it = sequence->begin();
48 it != sequence->end();
49 ++it) {
50 satisfied_sequences_.insert(
51 SurfaceSequence(SurfaceIdAllocator::NamespaceForId(id), *it));
52 }
53 sequence->clear();
54 AttemptSatisfyDestroy();
55 }
56
57 void SurfaceManager::AttemptSatisfyDestroy() {
58 for (SurfaceDestroyList::iterator dest_it = surfaces_to_destroy_.begin();
59 dest_it != surfaces_to_destroy_.end();) {
60 std::set<SurfaceSequence>& dependency_set = dest_it->second;
61
62 for (std::set<SurfaceSequence>::iterator it = dependency_set.begin();
63 it != dependency_set.end();) {
64 if (satisfied_sequences_.count(*it) > 0) {
65 satisfied_sequences_.erase(*it);
66 std::set<SurfaceSequence>::iterator old_it = it;
67 ++it;
68 dependency_set.erase(old_it);
69 } else {
70 ++it;
71 }
72 }
73 if (dependency_set.empty()) {
74 scoped_ptr<Surface> surf(dest_it->first);
75 DeregisterSurface(surf->surface_id());
76 dest_it = surfaces_to_destroy_.erase(dest_it);
77 } else {
78 ++dest_it;
79 }
80 }
81 }
82
31 Surface* SurfaceManager::GetSurfaceForId(SurfaceId surface_id) { 83 Surface* SurfaceManager::GetSurfaceForId(SurfaceId surface_id) {
32 SurfaceMap::iterator it = surface_map_.find(surface_id); 84 SurfaceMap::iterator it = surface_map_.find(surface_id);
33 if (it == surface_map_.end()) 85 if (it == surface_map_.end())
34 return NULL; 86 return NULL;
35 return it->second; 87 return it->second;
36 } 88 }
37 89
38 void SurfaceManager::SurfaceModified(SurfaceId surface_id) { 90 void SurfaceManager::SurfaceModified(SurfaceId surface_id) {
39 FOR_EACH_OBSERVER( 91 FOR_EACH_OBSERVER(
40 SurfaceDamageObserver, observer_list_, OnSurfaceDamaged(surface_id)); 92 SurfaceDamageObserver, observer_list_, OnSurfaceDamaged(surface_id));
41 } 93 }
42 94
43 } // namespace cc 95 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698