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

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

Issue 2716553004: Add temporary reference ownership to SurfaceManager. (Closed)
Patch Set: Rebase 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') | 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 GarbageCollectSurfaces(); 129 GarbageCollectSurfaces();
130 } 130 }
131 131
132 void SurfaceManager::RegisterFrameSinkId(const FrameSinkId& frame_sink_id) { 132 void SurfaceManager::RegisterFrameSinkId(const FrameSinkId& frame_sink_id) {
133 bool inserted = valid_frame_sink_ids_.insert(frame_sink_id).second; 133 bool inserted = valid_frame_sink_ids_.insert(frame_sink_id).second;
134 DCHECK(inserted); 134 DCHECK(inserted);
135 } 135 }
136 136
137 void SurfaceManager::InvalidateFrameSinkId(const FrameSinkId& frame_sink_id) { 137 void SurfaceManager::InvalidateFrameSinkId(const FrameSinkId& frame_sink_id) {
138 valid_frame_sink_ids_.erase(frame_sink_id); 138 valid_frame_sink_ids_.erase(frame_sink_id);
139
140 if (using_surface_references()) {
141 // Remove any temporary references owned by |frame_sink_id|.
142 std::vector<SurfaceId> temp_refs_to_clear;
143 for (auto& map_entry : temporary_references_) {
144 base::Optional<FrameSinkId>& owner = map_entry.second;
145 if (owner.has_value() && owner.value() == frame_sink_id)
146 temp_refs_to_clear.push_back(map_entry.first);
147 }
148
149 for (auto& surface_id : temp_refs_to_clear)
150 RemoveTemporaryReference(surface_id, false);
151 }
152
139 GarbageCollectSurfaces(); 153 GarbageCollectSurfaces();
140 } 154 }
141 155
142 const SurfaceId& SurfaceManager::GetRootSurfaceId() const { 156 const SurfaceId& SurfaceManager::GetRootSurfaceId() const {
143 return root_surface_id_; 157 return root_surface_id_;
144 } 158 }
145 159
146 void SurfaceManager::AddSurfaceReferences( 160 void SurfaceManager::AddSurfaceReferences(
147 const std::vector<SurfaceReference>& references) { 161 const std::vector<SurfaceReference>& references) {
148 DCHECK(thread_checker_.CalledOnValidThread()); 162 DCHECK(thread_checker_.CalledOnValidThread());
149 DCHECK(using_surface_references()); 163 DCHECK(using_surface_references());
150 164
151 for (const auto& reference : references) 165 for (const auto& reference : references)
152 AddSurfaceReferenceImpl(reference.parent_id(), reference.child_id()); 166 AddSurfaceReferenceImpl(reference.parent_id(), reference.child_id());
153 } 167 }
154 168
155 void SurfaceManager::RemoveSurfaceReferences( 169 void SurfaceManager::RemoveSurfaceReferences(
156 const std::vector<SurfaceReference>& references) { 170 const std::vector<SurfaceReference>& references) {
157 DCHECK(thread_checker_.CalledOnValidThread()); 171 DCHECK(thread_checker_.CalledOnValidThread());
158 DCHECK(using_surface_references()); 172 DCHECK(using_surface_references());
159 173
160 for (const auto& reference : references) 174 for (const auto& reference : references)
161 RemoveSurfaceReferenceImpl(reference.parent_id(), reference.child_id()); 175 RemoveSurfaceReferenceImpl(reference.parent_id(), reference.child_id());
162 176
163 GarbageCollectSurfaces(); 177 GarbageCollectSurfaces();
164 } 178 }
165 179
180 void SurfaceManager::AssignTemporaryReference(const SurfaceId& surface_id,
181 const FrameSinkId& owner) {
182 DCHECK(thread_checker_.CalledOnValidThread());
183 DCHECK_EQ(lifetime_type_, LifetimeType::REFERENCES);
184
185 if (!HasTemporaryReference(surface_id))
186 return;
187
188 temporary_references_[surface_id] = owner;
189 }
190
191 void SurfaceManager::DropTemporaryReference(const SurfaceId& surface_id) {
192 DCHECK(thread_checker_.CalledOnValidThread());
193 DCHECK_EQ(lifetime_type_, LifetimeType::REFERENCES);
194
195 if (!HasTemporaryReference(surface_id))
196 return;
197
198 RemoveTemporaryReference(surface_id, false);
199 }
200
166 void SurfaceManager::GarbageCollectSurfaces() { 201 void SurfaceManager::GarbageCollectSurfaces() {
167 if (surfaces_to_destroy_.empty()) 202 if (surfaces_to_destroy_.empty())
168 return; 203 return;
169 204
170 SurfaceIdSet reachable_surfaces = using_surface_references() 205 SurfaceIdSet reachable_surfaces = using_surface_references()
171 ? GetLiveSurfacesForReferences() 206 ? GetLiveSurfacesForReferences()
172 : GetLiveSurfacesForSequences(); 207 : GetLiveSurfacesForSequences();
173 208
174 std::vector<std::unique_ptr<Surface>> surfaces_to_delete; 209 std::vector<std::unique_ptr<Surface>> surfaces_to_delete;
175 210
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); 660 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end());
626 std::sort(children.begin(), children.end()); 661 std::sort(children.begin(), children.end());
627 662
628 for (const SurfaceId& child_id : children) 663 for (const SurfaceId& child_id : children)
629 SurfaceReferencesToStringImpl(child_id, indent + " ", str); 664 SurfaceReferencesToStringImpl(child_id, indent + " ", str);
630 } 665 }
631 } 666 }
632 #endif // DCHECK_IS_ON() 667 #endif // DCHECK_IS_ON()
633 668
634 } // namespace cc 669 } // 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