Index: cc/surfaces/surface_manager.cc |
diff --git a/cc/surfaces/surface_manager.cc b/cc/surfaces/surface_manager.cc |
index 753191d7460be547e751b117afe584ad3734c89b..dbeb15279d5822e4122c669ac279c627b2ad4228 100644 |
--- a/cc/surfaces/surface_manager.cc |
+++ b/cc/surfaces/surface_manager.cc |
@@ -122,12 +122,24 @@ std::unique_ptr<Surface> SurfaceManager::CreateSurface( |
std::unique_ptr<Surface> surface = std::move(*it); |
surfaces_to_destroy_.erase(it); |
surface->set_destroyed(false); |
+ // If the surface was used by another factory, we should update its factory. |
+ // The old frames must be evicted because the new factory is not capable of |
+ // returning their resources. |
+ // TODO(samans): This should not be necessary once crbug.com/701988 is fixed. |
+ if (surface->factory() == nullptr) { |
+ DLOG(ERROR) << "Surface is being reused by another factory. " |
+ "Resources can potentially leak. id=" |
+ << surface_id; |
+ surface->Reset(); |
+ surface->set_factory(surface_factory); |
+ } |
DCHECK_EQ(surface_factory.get(), surface->factory().get()); |
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)); |
GarbageCollectSurfaces(); |