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

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

Issue 2736053004: SurfaceIds must be reusable as soon as their surfaces are marked destroyed (Closed)
Patch Set: Make deregister private Created 3 years, 9 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') | no next file » | 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // Remove all temporary references on shutdown. 49 // Remove all temporary references on shutdown.
50 temporary_references_.clear(); 50 temporary_references_.clear();
51 temporary_reference_ranges_.clear(); 51 temporary_reference_ranges_.clear();
52 52
53 GarbageCollectSurfaces(); 53 GarbageCollectSurfaces();
54 } 54 }
55 55
56 for (SurfaceDestroyList::iterator it = surfaces_to_destroy_.begin(); 56 for (SurfaceDestroyList::iterator it = surfaces_to_destroy_.begin();
57 it != surfaces_to_destroy_.end(); 57 it != surfaces_to_destroy_.end();
58 ++it) { 58 ++it) {
59 DeregisterSurface((*it)->surface_id()); 59 UnregisterSurface((*it)->surface_id());
60 } 60 }
61 surfaces_to_destroy_.clear(); 61 surfaces_to_destroy_.clear();
62 62
63 // All surface factory clients should be unregistered prior to SurfaceManager 63 // All surface factory clients should be unregistered prior to SurfaceManager
64 // destruction. 64 // destruction.
65 DCHECK_EQ(clients_.size(), 0u); 65 DCHECK_EQ(clients_.size(), 0u);
66 DCHECK_EQ(registered_sources_.size(), 0u); 66 DCHECK_EQ(registered_sources_.size(), 0u);
67 } 67 }
68 68
69 #if DCHECK_IS_ON() 69 #if DCHECK_IS_ON()
(...skipping 11 matching lines...) Expand all
81 void SurfaceManager::SetDependencyTracker( 81 void SurfaceManager::SetDependencyTracker(
82 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker) { 82 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker) {
83 dependency_tracker_ = std::move(dependency_tracker); 83 dependency_tracker_ = std::move(dependency_tracker);
84 } 84 }
85 85
86 void SurfaceManager::RequestSurfaceResolution(Surface* pending_surface) { 86 void SurfaceManager::RequestSurfaceResolution(Surface* pending_surface) {
87 if (dependency_tracker_) 87 if (dependency_tracker_)
88 dependency_tracker_->RequestSurfaceResolution(pending_surface); 88 dependency_tracker_->RequestSurfaceResolution(pending_surface);
89 } 89 }
90 90
91 void SurfaceManager::RegisterSurface(Surface* surface) { 91 std::unique_ptr<Surface> SurfaceManager::CreateSurface(
92 base::WeakPtr<SurfaceFactory> surface_factory,
93 const LocalSurfaceId& local_surface_id) {
92 DCHECK(thread_checker_.CalledOnValidThread()); 94 DCHECK(thread_checker_.CalledOnValidThread());
93 DCHECK(surface); 95 DCHECK(local_surface_id.is_valid() && surface_factory);
94 DCHECK(!surface_map_.count(surface->surface_id())); 96
95 surface_map_[surface->surface_id()] = surface; 97 SurfaceId surface_id(surface_factory->frame_sink_id(), local_surface_id);
98
99 // If no surface with this SurfaceId exists, simply create the surface and
100 // return.
101 auto surface_iter = surface_map_.find(surface_id);
102 if (surface_iter == surface_map_.end()) {
103 auto surface = base::MakeUnique<Surface>(surface_id, surface_factory);
104 surface_map_[surface->surface_id()] = surface.get();
105 return surface;
106 }
107
108 // If a surface with this SurfaceId exists and it's not marked as destroyed,
109 // we should not receive a request to create a new surface with the same
110 // SurfaceId.
111 DCHECK(surface_iter->second->destroyed());
112
113 // If a surface with this SurfaceId exists and it's marked as destroyed,
114 // it means it's in the garbage collector's queue. We simply take it out of
115 // the queue and reuse it.
116 auto it =
117 std::find_if(surfaces_to_destroy_.begin(), surfaces_to_destroy_.end(),
118 [&surface_id](const std::unique_ptr<Surface>& surface) {
119 return surface->surface_id() == surface_id;
120 });
121 DCHECK(it != surfaces_to_destroy_.end());
122 std::unique_ptr<Surface> surface = std::move(*it);
123 surfaces_to_destroy_.erase(it);
124 surface->set_destroyed(false);
125 DCHECK_EQ(surface_factory.get(), surface->factory().get());
126 return surface;
96 } 127 }
97 128
98 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { 129 void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) {
99 DCHECK(thread_checker_.CalledOnValidThread());
100 SurfaceMap::iterator it = surface_map_.find(surface_id);
101 DCHECK(it != surface_map_.end());
102 surface_map_.erase(it);
103 RemoveAllSurfaceReferences(surface_id);
104 }
105
106 void SurfaceManager::Destroy(std::unique_ptr<Surface> surface) {
107 DCHECK(thread_checker_.CalledOnValidThread()); 130 DCHECK(thread_checker_.CalledOnValidThread());
108 surface->set_destroyed(true); 131 surface->set_destroyed(true);
109 surfaces_to_destroy_.push_back(std::move(surface)); 132 surfaces_to_destroy_.push_back(std::move(surface));
110 GarbageCollectSurfaces(); 133 GarbageCollectSurfaces();
111 } 134 }
112 135
113 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, 136 void SurfaceManager::RequireSequence(const SurfaceId& surface_id,
114 const SurfaceSequence& sequence) { 137 const SurfaceSequence& sequence) {
115 auto* surface = GetSurfaceForId(surface_id); 138 auto* surface = GetSurfaceForId(surface_id);
116 if (!surface) { 139 if (!surface) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 ? GetLiveSurfacesForReferences() 227 ? GetLiveSurfacesForReferences()
205 : GetLiveSurfacesForSequences(); 228 : GetLiveSurfacesForSequences();
206 229
207 std::vector<std::unique_ptr<Surface>> surfaces_to_delete; 230 std::vector<std::unique_ptr<Surface>> surfaces_to_delete;
208 231
209 // Delete all destroyed and unreachable surfaces. 232 // Delete all destroyed and unreachable surfaces.
210 for (auto iter = surfaces_to_destroy_.begin(); 233 for (auto iter = surfaces_to_destroy_.begin();
211 iter != surfaces_to_destroy_.end();) { 234 iter != surfaces_to_destroy_.end();) {
212 SurfaceId surface_id = (*iter)->surface_id(); 235 SurfaceId surface_id = (*iter)->surface_id();
213 if (reachable_surfaces.count(surface_id) == 0) { 236 if (reachable_surfaces.count(surface_id) == 0) {
214 DeregisterSurface(surface_id); 237 UnregisterSurface(surface_id);
215 surfaces_to_delete.push_back(std::move(*iter)); 238 surfaces_to_delete.push_back(std::move(*iter));
216 iter = surfaces_to_destroy_.erase(iter); 239 iter = surfaces_to_destroy_.erase(iter);
217 } else { 240 } else {
218 ++iter; 241 ++iter;
219 } 242 }
220 } 243 }
221 244
222 // ~Surface() draw callback could modify |surfaces_to_destroy_|. 245 // ~Surface() draw callback could modify |surfaces_to_destroy_|.
223 surfaces_to_delete.clear(); 246 surfaces_to_delete.clear();
224 } 247 }
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 bool has_real_reference = 632 bool has_real_reference =
610 it != child_to_parent_refs_.end() && !it->second.empty(); 633 it != child_to_parent_refs_.end() && !it->second.empty();
611 if (!has_real_reference) 634 if (!has_real_reference)
612 AddTemporaryReference(surface_info.id()); 635 AddTemporaryReference(surface_info.id());
613 } 636 }
614 637
615 for (auto& observer : observer_list_) 638 for (auto& observer : observer_list_)
616 observer.OnSurfaceCreated(surface_info); 639 observer.OnSurfaceCreated(surface_info);
617 } 640 }
618 641
642 void SurfaceManager::UnregisterSurface(const SurfaceId& surface_id) {
643 DCHECK(thread_checker_.CalledOnValidThread());
644 SurfaceMap::iterator it = surface_map_.find(surface_id);
645 DCHECK(it != surface_map_.end());
646 surface_map_.erase(it);
647 RemoveAllSurfaceReferences(surface_id);
648 }
649
619 #if DCHECK_IS_ON() 650 #if DCHECK_IS_ON()
620 void SurfaceManager::SurfaceReferencesToStringImpl(const SurfaceId& surface_id, 651 void SurfaceManager::SurfaceReferencesToStringImpl(const SurfaceId& surface_id,
621 std::string indent, 652 std::string indent,
622 std::stringstream* str) { 653 std::stringstream* str) {
623 *str << indent; 654 *str << indent;
624 655
625 // Print the current line for |surface_id|. 656 // Print the current line for |surface_id|.
626 Surface* surface = GetSurfaceForId(surface_id); 657 Surface* surface = GetSurfaceForId(surface_id);
627 if (surface) { 658 if (surface) {
628 *str << surface->surface_id().ToString(); 659 *str << surface->surface_id().ToString();
(...skipping 28 matching lines...) Expand all
657 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); 688 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end());
658 std::sort(children.begin(), children.end()); 689 std::sort(children.begin(), children.end());
659 690
660 for (const SurfaceId& child_id : children) 691 for (const SurfaceId& child_id : children)
661 SurfaceReferencesToStringImpl(child_id, indent + " ", str); 692 SurfaceReferencesToStringImpl(child_id, indent + " ", str);
662 } 693 }
663 } 694 }
664 #endif // DCHECK_IS_ON() 695 #endif // DCHECK_IS_ON()
665 696
666 } // namespace cc 697 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698