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

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, 2 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_sequence.h » ('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 "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 thread_checker_.DetachFromThread(); 14 thread_checker_.DetachFromThread();
14 } 15 }
15 16
16 SurfaceManager::~SurfaceManager() { 17 SurfaceManager::~SurfaceManager() {
17 DCHECK(thread_checker_.CalledOnValidThread()); 18 DCHECK(thread_checker_.CalledOnValidThread());
19 for (SurfaceDestroyList::iterator it = surfaces_to_destroy_.begin();
20 it != surfaces_to_destroy_.end();
21 ++it) {
22 DeregisterSurface(it->first->surface_id());
23 delete it->first;
24 }
18 } 25 }
19 26
20 void SurfaceManager::RegisterSurface(Surface* surface) { 27 void SurfaceManager::RegisterSurface(Surface* surface) {
21 DCHECK(thread_checker_.CalledOnValidThread()); 28 DCHECK(thread_checker_.CalledOnValidThread());
22 DCHECK(surface); 29 DCHECK(surface);
23 DCHECK(!surface_map_.count(surface->surface_id())); 30 DCHECK(!surface_map_.count(surface->surface_id()));
24 surface_map_[surface->surface_id()] = surface; 31 surface_map_[surface->surface_id()] = surface;
25 } 32 }
26 33
27 void SurfaceManager::DeregisterSurface(SurfaceId surface_id) { 34 void SurfaceManager::DeregisterSurface(SurfaceId surface_id) {
28 DCHECK(thread_checker_.CalledOnValidThread()); 35 DCHECK(thread_checker_.CalledOnValidThread());
29 SurfaceMap::iterator it = surface_map_.find(surface_id); 36 SurfaceMap::iterator it = surface_map_.find(surface_id);
30 DCHECK(it != surface_map_.end()); 37 DCHECK(it != surface_map_.end());
31 surface_map_.erase(it); 38 surface_map_.erase(it);
32 } 39 }
33 40
41 void SurfaceManager::DestroyOnSequence(
42 scoped_ptr<Surface> surface,
43 const std::set<SurfaceSequence>& dependency_set) {
44 surfaces_to_destroy_.push_back(make_pair(surface.release(), dependency_set));
45 SearchForSatisfaction();
46 }
47
48 void SurfaceManager::DidSatisfySequences(SurfaceId id,
49 std::vector<uint32_t>* sequence) {
50 for (std::vector<uint32_t>::iterator it = sequence->begin();
51 it != sequence->end();
52 ++it) {
53 satisfied_sequences_.insert(
54 SurfaceSequence(SurfaceIdAllocator::NamespaceForId(id), *it));
55 }
56 sequence->clear();
57 SearchForSatisfaction();
58 }
59
60 void SurfaceManager::SearchForSatisfaction() {
61 for (SurfaceDestroyList::iterator dest_it = surfaces_to_destroy_.begin();
62 dest_it != surfaces_to_destroy_.end();) {
63 std::set<SurfaceSequence>& dependency_set = dest_it->second;
64
65 for (std::set<SurfaceSequence>::iterator it = dependency_set.begin();
66 it != dependency_set.end();) {
67 if (satisfied_sequences_.count(*it) > 0) {
68 satisfied_sequences_.erase(*it);
69 std::set<SurfaceSequence>::iterator old_it = it;
70 ++it;
71 dependency_set.erase(old_it);
72 } else {
73 ++it;
74 }
75 }
76 if (dependency_set.empty()) {
77 scoped_ptr<Surface> surf(dest_it->first);
78 DeregisterSurface(surf->surface_id());
79 dest_it = surfaces_to_destroy_.erase(dest_it);
80 } else {
81 ++dest_it;
82 }
83 }
84 }
85
34 Surface* SurfaceManager::GetSurfaceForId(SurfaceId surface_id) { 86 Surface* SurfaceManager::GetSurfaceForId(SurfaceId surface_id) {
35 DCHECK(thread_checker_.CalledOnValidThread()); 87 DCHECK(thread_checker_.CalledOnValidThread());
36 SurfaceMap::iterator it = surface_map_.find(surface_id); 88 SurfaceMap::iterator it = surface_map_.find(surface_id);
37 if (it == surface_map_.end()) 89 if (it == surface_map_.end())
38 return NULL; 90 return NULL;
39 return it->second; 91 return it->second;
40 } 92 }
41 93
42 void SurfaceManager::SurfaceModified(SurfaceId surface_id) { 94 void SurfaceManager::SurfaceModified(SurfaceId surface_id) {
43 DCHECK(thread_checker_.CalledOnValidThread()); 95 DCHECK(thread_checker_.CalledOnValidThread());
44 FOR_EACH_OBSERVER( 96 FOR_EACH_OBSERVER(
45 SurfaceDamageObserver, observer_list_, OnSurfaceDamaged(surface_id)); 97 SurfaceDamageObserver, observer_list_, OnSurfaceDamaged(surface_id));
46 } 98 }
47 99
48 } // namespace cc 100 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_manager.h ('k') | cc/surfaces/surface_sequence.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698