| Index: cc/surfaces/surface_manager.cc
|
| diff --git a/cc/surfaces/surface_manager.cc b/cc/surfaces/surface_manager.cc
|
| index bf72fce1f3a30bc5497190135fcabe9dcb252791..b3db0a691c8682509ee7c4220405d2f41c30c7ec 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,45 @@ void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) {
|
| RemoveAllSurfaceReferences(surface_id);
|
| }
|
|
|
| -void SurfaceManager::Destroy(std::unique_ptr<Surface> surface) {
|
| +std::unique_ptr<Surface> SurfaceManager::CreateSurface(
|
| + base::WeakPtr<SurfaceFactory> surface_factory,
|
| + const LocalSurfaceId& local_surface_id) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + DCHECK(local_surface_id.is_valid() && surface_factory);
|
| +
|
| + SurfaceId surface_id(surface_factory->frame_sink_id(), local_surface_id);
|
| +
|
| + // If no surface with this SurfaceId exists, simply create the surface and
|
| + // return.
|
| + auto surface_iter = surface_map_.find(surface_id);
|
| + 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 a surface with this SurfaceId exists and it's not marked as destroyed,
|
| + // we should not receive a request to create a new surface with the same
|
| + // SurfaceId.
|
| + DCHECK(surface_iter->second->destroyed());
|
| +
|
| + // If a surface with this SurfaceId exists and it's marked as destroyed,
|
| + // it means it's in the garbage collector's queue. We simply take it out of
|
| + // the queue and reuse it.
|
| + auto it =
|
| + std::find_if(surfaces_to_destroy_.begin(), surfaces_to_destroy_.end(),
|
| + [&surface_id](const std::unique_ptr<Surface>& surface) {
|
| + return surface->surface_id() == surface_id;
|
| + });
|
| + DCHECK(it != surfaces_to_destroy_.end());
|
| + std::unique_ptr<Surface> surface = std::move(*it);
|
| + surfaces_to_destroy_.erase(it);
|
| + surface->set_destroyed(false);
|
| + 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));
|
|
|