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

Unified Diff: cc/surfaces/surface_manager.cc

Issue 2736053004: SurfaceIds must be reusable as soon as their surfaces are marked destroyed (Closed)
Patch Set: Undo changes in surface 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/surfaces/surface_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/surfaces/surface_manager.cc
diff --git a/cc/surfaces/surface_manager.cc b/cc/surfaces/surface_manager.cc
index bf72fce1f3a30bc5497190135fcabe9dcb252791..cc3fa30b3aca27dc91a2620f0570ec142f64e15f 100644
--- a/cc/surfaces/surface_manager.cc
+++ b/cc/surfaces/surface_manager.cc
@@ -88,13 +88,6 @@ void SurfaceManager::RequestSurfaceResolution(Surface* pending_surface) {
dependency_tracker_->RequestSurfaceResolution(pending_surface);
}
-void SurfaceManager::RegisterSurface(Surface* surface) {
- DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK(surface);
- DCHECK(!surface_map_.count(surface->surface_id()));
- surface_map_[surface->surface_id()] = surface;
-}
-
void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) {
DCHECK(thread_checker_.CalledOnValidThread());
SurfaceMap::iterator it = surface_map_.find(surface_id);
@@ -103,7 +96,46 @@ void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) {
RemoveAllSurfaceReferences(surface_id);
}
-void SurfaceManager::Destroy(std::unique_ptr<Surface> surface) {
+std::unique_ptr<Surface> SurfaceManager::CreateSurface(
+ SurfaceId surface_id,
Fady Samuel 2017/03/09 16:30:08 const SurfaceId&
Saman Sami 2017/03/09 20:45:50 Done.
+ base::WeakPtr<SurfaceFactory> surface_factory) {
Fady Samuel 2017/03/09 16:30:08 Does thsi need to be a weakptr?
Saman Sami 2017/03/09 20:45:50 Surface keeps a weak ptr to its factory.
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ if (!surface_id.is_valid() || !surface_factory)
Fady Samuel 2017/03/09 16:30:08 DCHECK instead? It seems like a bug otherwise.
Saman Sami 2017/03/09 20:45:50 Done.
+ return nullptr;
+
+ auto surface_iter = surface_map_.find(surface_id);
+
+ // If the SurfaceId is not registered, simply create the surface and return.
+ if (surface_iter == surface_map_.end()) {
+ auto surface = base::MakeUnique<Surface>(surface_id, surface_factory);
+ surface_map_[surface->surface_id()] = surface.get();
+ return surface;
+ }
+
+ // If the SurfaceId is registered but the registered surface is not
+ // destroyed, we can't create a new surface with the same SurfaceId.
+ if (!surface_iter->second->destroyed())
Fady Samuel 2017/03/09 16:30:08 This is a bug right? DCHECK instead?
Saman Sami 2017/03/09 20:45:50 Done.
+ return nullptr;
+
+ // If the SurfaceId is registered and the registered surface is destroyed,
+ // we can remove it from the garbage collector's queue and reuse it.
+ std::unique_ptr<Surface> surface;
+ for (auto it = surfaces_to_destroy_.begin(); it != surfaces_to_destroy_.end();
Fady Samuel 2017/03/09 16:30:08 Use std::find? http://en.cppreference.com/w/cpp/al
Saman Sami 2017/03/09 20:45:50 Done.
+ it++) {
+ if ((*it)->surface_id() == surface_id) {
+ surface = std::move(*it);
+ surfaces_to_destroy_.erase(it);
+ break;
+ }
+ }
+ DCHECK(surface);
+ DCHECK_EQ(surface_factory.get(), surface->factory().get());
+ surface->set_destroyed(false);
+ return surface;
+}
+
+void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) {
DCHECK(thread_checker_.CalledOnValidThread());
surface->set_destroyed(true);
surfaces_to_destroy_.push_back(std::move(surface));
« 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