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> |
| 8 |
7 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
8 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
9 #include "cc/output/copy_output_request.h" | 11 #include "cc/output/copy_output_request.h" |
10 #include "cc/surfaces/surface.h" | 12 #include "cc/surfaces/surface.h" |
11 #include "cc/surfaces/surface_factory_client.h" | 13 #include "cc/surfaces/surface_factory_client.h" |
12 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
13 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
14 | 16 |
15 namespace cc { | 17 namespace cc { |
16 SurfaceFactory::SurfaceFactory(SurfaceManager* manager, | 18 SurfaceFactory::SurfaceFactory(SurfaceManager* manager, |
17 SurfaceFactoryClient* client) | 19 SurfaceFactoryClient* client) |
18 : manager_(manager), | 20 : manager_(manager), |
19 client_(client), | 21 client_(client), |
20 holder_(client), | 22 holder_(client), |
21 needs_sync_points_(true) { | 23 needs_sync_points_(true) { |
22 } | 24 } |
23 | 25 |
24 SurfaceFactory::~SurfaceFactory() { | 26 SurfaceFactory::~SurfaceFactory() { |
25 if (!surface_map_.empty()) { | 27 if (!surface_map_.empty()) { |
26 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() | 28 LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() |
27 << " entries in map on destruction."; | 29 << " entries in map on destruction."; |
28 } | 30 } |
29 DestroyAll(); | 31 DestroyAll(); |
30 client_->SetBeginFrameSource(SurfaceId(), nullptr); | 32 client_->SetBeginFrameSource(SurfaceId(), nullptr); |
31 } | 33 } |
32 | 34 |
33 void SurfaceFactory::DestroyAll() { | 35 void SurfaceFactory::DestroyAll() { |
34 for (auto it = surface_map_.begin(); it != surface_map_.end(); ++it) | 36 for (auto it = surface_map_.begin(); it != surface_map_.end(); ++it) |
35 manager_->Destroy(surface_map_.take(it)); | 37 manager_->Destroy(std::move(it->second)); |
36 surface_map_.clear(); | 38 surface_map_.clear(); |
37 } | 39 } |
38 | 40 |
39 void SurfaceFactory::Create(SurfaceId surface_id) { | 41 void SurfaceFactory::Create(SurfaceId surface_id) { |
40 scoped_ptr<Surface> surface(new Surface(surface_id, this)); | 42 scoped_ptr<Surface> surface(new Surface(surface_id, this)); |
41 manager_->RegisterSurface(surface.get()); | 43 manager_->RegisterSurface(surface.get()); |
42 DCHECK(!surface_map_.count(surface_id)); | 44 DCHECK(!surface_map_.count(surface_id)); |
43 surface_map_.add(surface_id, std::move(surface)); | 45 surface_map_[surface_id] = std::move(surface); |
44 } | 46 } |
45 | 47 |
46 void SurfaceFactory::Destroy(SurfaceId surface_id) { | 48 void SurfaceFactory::Destroy(SurfaceId surface_id) { |
47 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | 49 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); |
48 DCHECK(it != surface_map_.end()); | 50 DCHECK(it != surface_map_.end()); |
49 DCHECK(it->second->factory().get() == this); | 51 DCHECK(it->second->factory().get() == this); |
50 manager_->Destroy(surface_map_.take_and_erase(it)); | 52 manager_->Destroy(std::move(it->second)); |
| 53 surface_map_.erase(it); |
51 } | 54 } |
52 | 55 |
53 void SurfaceFactory::SetBeginFrameSource(SurfaceId surface_id, | 56 void SurfaceFactory::SetBeginFrameSource(SurfaceId surface_id, |
54 BeginFrameSource* begin_frame_source) { | 57 BeginFrameSource* begin_frame_source) { |
55 client_->SetBeginFrameSource(surface_id, begin_frame_source); | 58 client_->SetBeginFrameSource(surface_id, begin_frame_source); |
56 } | 59 } |
57 | 60 |
58 void SurfaceFactory::SubmitCompositorFrame(SurfaceId surface_id, | 61 void SurfaceFactory::SubmitCompositorFrame(SurfaceId surface_id, |
59 scoped_ptr<CompositorFrame> frame, | 62 scoped_ptr<CompositorFrame> frame, |
60 const DrawCallback& callback) { | 63 const DrawCallback& callback) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 97 |
95 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 98 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |
96 holder_.RefResources(resources); | 99 holder_.RefResources(resources); |
97 } | 100 } |
98 | 101 |
99 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 102 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |
100 holder_.UnrefResources(resources); | 103 holder_.UnrefResources(resources); |
101 } | 104 } |
102 | 105 |
103 } // namespace cc | 106 } // namespace cc |
OLD | NEW |