| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 SurfaceFactory::~SurfaceFactory() { | 26 SurfaceFactory::~SurfaceFactory() { |
| 27 if (!surface_map_.empty()) { | 27 if (!surface_map_.empty()) { |
| 28 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() | 28 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() |
| 29 << " entries in map on destruction."; | 29 << " entries in map on destruction."; |
| 30 } | 30 } |
| 31 DestroyAll(); | 31 DestroyAll(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void SurfaceFactory::DestroyAll() { | 34 void SurfaceFactory::DestroyAll() { |
| 35 for (auto& pair : surface_map_) | 35 if (manager_) { |
| 36 manager_->Destroy(std::move(pair.second)); | 36 for (auto& pair : surface_map_) |
| 37 manager_->Destroy(std::move(pair.second)); |
| 38 } |
| 37 surface_map_.clear(); | 39 surface_map_.clear(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 void SurfaceFactory::Create(SurfaceId surface_id) { | 42 void SurfaceFactory::Create(SurfaceId surface_id) { |
| 41 std::unique_ptr<Surface> surface(new Surface(surface_id, this)); | 43 std::unique_ptr<Surface> surface(new Surface(surface_id, this)); |
| 42 manager_->RegisterSurface(surface.get()); | 44 manager_->RegisterSurface(surface.get()); |
| 43 DCHECK(!surface_map_.count(surface_id)); | 45 DCHECK(!surface_map_.count(surface_id)); |
| 44 surface_map_[surface_id] = std::move(surface); | 46 surface_map_[surface_id] = std::move(surface); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void SurfaceFactory::Destroy(SurfaceId surface_id) { | 49 void SurfaceFactory::Destroy(SurfaceId surface_id) { |
| 48 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 50 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
| 49 DCHECK(it != surface_map_.end()); | 51 DCHECK(it != surface_map_.end()); |
| 50 DCHECK(it->second->factory().get() == this); | 52 DCHECK(it->second->factory().get() == this); |
| 51 std::unique_ptr<Surface> surface(std::move(it->second)); | 53 std::unique_ptr<Surface> surface(std::move(it->second)); |
| 52 surface_map_.erase(it); | 54 surface_map_.erase(it); |
| 53 manager_->Destroy(std::move(surface)); | 55 if (manager_) |
| 56 manager_->Destroy(std::move(surface)); |
| 54 } | 57 } |
| 55 | 58 |
| 56 void SurfaceFactory::SetPreviousFrameSurface(SurfaceId new_id, | 59 void SurfaceFactory::SetPreviousFrameSurface(SurfaceId new_id, |
| 57 SurfaceId old_id) { | 60 SurfaceId old_id) { |
| 58 OwningSurfaceMap::iterator it = surface_map_.find(new_id); | 61 OwningSurfaceMap::iterator it = surface_map_.find(new_id); |
| 59 DCHECK(it != surface_map_.end()); | 62 DCHECK(it != surface_map_.end()); |
| 60 Surface* old_surface = manager_->GetSurfaceForId(old_id); | 63 Surface* old_surface = manager_->GetSurfaceForId(old_id); |
| 61 if (old_surface) { | 64 if (old_surface) { |
| 62 it->second->SetPreviousFrameSurface(old_surface); | 65 it->second->SetPreviousFrameSurface(old_surface); |
| 63 } | 66 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 114 |
| 112 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 115 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |
| 113 holder_.RefResources(resources); | 116 holder_.RefResources(resources); |
| 114 } | 117 } |
| 115 | 118 |
| 116 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 119 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |
| 117 holder_.UnrefResources(resources); | 120 holder_.UnrefResources(resources); |
| 118 } | 121 } |
| 119 | 122 |
| 120 } // namespace cc | 123 } // namespace cc |
| OLD | NEW |