| OLD | NEW |
| 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_factory.h" | 5 #include "cc/surfaces/surface_factory.h" |
| 6 | 6 |
| 7 #include "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
| 8 #include "cc/output/copy_output_request.h" | 8 #include "cc/output/copy_output_request.h" |
| 9 #include "cc/surfaces/surface.h" | 9 #include "cc/surfaces/surface.h" |
| 10 #include "cc/surfaces/surface_manager.h" | 10 #include "cc/surfaces/surface_manager.h" |
| 11 #include "ui/gfx/geometry/size.h" | 11 #include "ui/gfx/geometry/size.h" |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 SurfaceFactory::SurfaceFactory(SurfaceManager* manager, | 14 SurfaceFactory::SurfaceFactory(SurfaceManager* manager, |
| 15 SurfaceFactoryClient* client) | 15 SurfaceFactoryClient* client) |
| 16 : manager_(manager), client_(client), holder_(client) { | 16 : manager_(manager), client_(client), holder_(client) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 SurfaceFactory::~SurfaceFactory() { | 19 SurfaceFactory::~SurfaceFactory() { |
| 20 if (!surface_map_.empty()) { | 20 if (!surface_map_.empty()) { |
| 21 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() | 21 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() |
| 22 << " entries in map on destruction."; | 22 << " entries in map on destruction."; |
| 23 } | 23 } |
| 24 DestroyAll(); | 24 DestroyAll(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void SurfaceFactory::DestroyAll() { | 27 void SurfaceFactory::DestroyAll() { |
| 28 for (auto& surface : surface_map_) | 28 for (auto it = surface_map_.begin(); it != surface_map_.end(); ++it) |
| 29 manager_->DeregisterSurface(surface.first); | 29 manager_->Destroy(surface_map_.take(it)); |
| 30 surface_map_.clear(); | 30 surface_map_.clear(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void SurfaceFactory::Create(SurfaceId surface_id, const gfx::Size& size) { | 33 void SurfaceFactory::Create(SurfaceId surface_id, const gfx::Size& size) { |
| 34 scoped_ptr<Surface> surface(new Surface(surface_id, size, this)); | 34 scoped_ptr<Surface> surface(new Surface(surface_id, size, this)); |
| 35 manager_->RegisterSurface(surface.get()); | 35 manager_->RegisterSurface(surface.get()); |
| 36 DCHECK(!surface_map_.count(surface_id)); | 36 DCHECK(!surface_map_.count(surface_id)); |
| 37 surface_map_.add(surface_id, surface.Pass()); | 37 surface_map_.add(surface_id, surface.Pass()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void SurfaceFactory::Destroy(SurfaceId surface_id) { | 40 void SurfaceFactory::Destroy(SurfaceId surface_id) { |
| 41 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 41 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
| 42 DCHECK(it != surface_map_.end()); | 42 DCHECK(it != surface_map_.end()); |
| 43 DCHECK(it->second->factory().get() == this); | 43 DCHECK(it->second->factory().get() == this); |
| 44 manager_->DeregisterSurface(surface_id); | 44 manager_->Destroy(surface_map_.take_and_erase(it)); |
| 45 surface_map_.erase(it); | |
| 46 } | |
| 47 | |
| 48 void SurfaceFactory::DestroyOnSequence( | |
| 49 SurfaceId surface_id, | |
| 50 const std::set<SurfaceSequence>& dependency_set) { | |
| 51 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | |
| 52 DCHECK(it != surface_map_.end()); | |
| 53 DCHECK(it->second->factory().get() == this); | |
| 54 manager_->DestroyOnSequence(surface_map_.take_and_erase(it), dependency_set); | |
| 55 } | 45 } |
| 56 | 46 |
| 57 void SurfaceFactory::SubmitFrame(SurfaceId surface_id, | 47 void SurfaceFactory::SubmitFrame(SurfaceId surface_id, |
| 58 scoped_ptr<CompositorFrame> frame, | 48 scoped_ptr<CompositorFrame> frame, |
| 59 const base::Closure& callback) { | 49 const base::Closure& callback) { |
| 60 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 50 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
| 61 DCHECK(it != surface_map_.end()); | 51 DCHECK(it != surface_map_.end()); |
| 62 DCHECK(it->second->factory().get() == this); | 52 DCHECK(it->second->factory().get() == this); |
| 63 it->second->QueueFrame(frame.Pass(), callback); | 53 it->second->QueueFrame(frame.Pass(), callback); |
| 64 manager_->SurfaceModified(surface_id); | 54 manager_->SurfaceModified(surface_id); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 84 | 74 |
| 85 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 75 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |
| 86 holder_.RefResources(resources); | 76 holder_.RefResources(resources); |
| 87 } | 77 } |
| 88 | 78 |
| 89 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 79 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |
| 90 holder_.UnrefResources(resources); | 80 holder_.UnrefResources(resources); |
| 91 } | 81 } |
| 92 | 82 |
| 93 } // namespace cc | 83 } // namespace cc |
| OLD | NEW |