Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / cc / surfaces / surface_factory.cc
index ab7186a..574f5d1 100644 (file)
@@ -17,6 +17,17 @@ SurfaceFactory::SurfaceFactory(SurfaceManager* manager,
 }
 
 SurfaceFactory::~SurfaceFactory() {
+  if (!surface_map_.empty()) {
+    LOG(ERROR) << "SurfaceFactory has " << surface_map_.size()
+               << " entries in map on destruction.";
+  }
+  DestroyAll();
+}
+
+void SurfaceFactory::DestroyAll() {
+  for (auto it = surface_map_.begin(); it != surface_map_.end(); ++it)
+    manager_->Destroy(surface_map_.take(it));
+  surface_map_.clear();
 }
 
 void SurfaceFactory::Create(SurfaceId surface_id, const gfx::Size& size) {
@@ -29,9 +40,8 @@ void SurfaceFactory::Create(SurfaceId surface_id, const gfx::Size& size) {
 void SurfaceFactory::Destroy(SurfaceId surface_id) {
   OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
   DCHECK(it != surface_map_.end());
-  DCHECK(it->second->factory() == this);
-  manager_->DeregisterSurface(surface_id);
-  surface_map_.erase(it);
+  DCHECK(it->second->factory().get() == this);
+  manager_->Destroy(surface_map_.take_and_erase(it));
 }
 
 void SurfaceFactory::SubmitFrame(SurfaceId surface_id,
@@ -39,7 +49,7 @@ void SurfaceFactory::SubmitFrame(SurfaceId surface_id,
                                  const base::Closure& callback) {
   OwningSurfaceMap::iterator it = surface_map_.find(surface_id);
   DCHECK(it != surface_map_.end());
-  DCHECK(it->second->factory() == this);
+  DCHECK(it->second->factory().get() == this);
   it->second->QueueFrame(frame.Pass(), callback);
   manager_->SurfaceModified(surface_id);
 }
@@ -52,7 +62,7 @@ void SurfaceFactory::RequestCopyOfSurface(
     copy_request->SendEmptyResult();
     return;
   }
-  DCHECK(it->second->factory() == this);
+  DCHECK(it->second->factory().get() == this);
   it->second->RequestCopyOfOutput(copy_request.Pass());
   manager_->SurfaceModified(surface_id);
 }