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 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 void SurfaceFactory::DestroyAll() { | 35 void SurfaceFactory::DestroyAll() { |
36 if (manager_) { | 36 if (manager_) { |
37 for (auto& pair : surface_map_) | 37 for (auto& pair : surface_map_) |
38 manager_->Destroy(std::move(pair.second)); | 38 manager_->Destroy(std::move(pair.second)); |
39 } | 39 } |
40 surface_map_.clear(); | 40 surface_map_.clear(); |
41 } | 41 } |
42 | 42 |
43 void SurfaceFactory::Create(const SurfaceId& surface_id) { | 43 void SurfaceFactory::Create(const LocalFrameId& local_frame_id) { |
44 DCHECK(surface_id.frame_sink_id() == frame_sink_id_); | 44 std::unique_ptr<Surface> surface(base::MakeUnique<Surface>( |
45 std::unique_ptr<Surface> surface(new Surface(surface_id, this)); | 45 SurfaceId(frame_sink_id_, local_frame_id), this)); |
46 manager_->RegisterSurface(surface.get()); | 46 manager_->RegisterSurface(surface.get()); |
47 DCHECK(!surface_map_.count(surface_id)); | 47 DCHECK(!surface_map_.count(local_frame_id)); |
48 surface_map_[surface_id] = std::move(surface); | 48 surface_map_[local_frame_id] = std::move(surface); |
49 } | 49 } |
50 | 50 |
51 void SurfaceFactory::Destroy(const SurfaceId& surface_id) { | 51 void SurfaceFactory::Destroy(const LocalFrameId& local_frame_id) { |
52 DCHECK(surface_id.frame_sink_id() == frame_sink_id_); | 52 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); |
53 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | |
54 DCHECK(it != surface_map_.end()); | 53 DCHECK(it != surface_map_.end()); |
55 DCHECK(it->second->factory().get() == this); | 54 DCHECK(it->second->factory().get() == this); |
56 std::unique_ptr<Surface> surface(std::move(it->second)); | 55 std::unique_ptr<Surface> surface(std::move(it->second)); |
57 surface_map_.erase(it); | 56 surface_map_.erase(it); |
58 if (manager_) | 57 if (manager_) |
59 manager_->Destroy(std::move(surface)); | 58 manager_->Destroy(std::move(surface)); |
60 } | 59 } |
61 | 60 |
62 void SurfaceFactory::SetPreviousFrameSurface(const SurfaceId& new_id, | 61 void SurfaceFactory::SetPreviousFrameSurface(const LocalFrameId& new_id, |
63 const SurfaceId& old_id) { | 62 const LocalFrameId& old_id) { |
64 DCHECK(new_id.frame_sink_id() == frame_sink_id_); | |
65 DCHECK(old_id.frame_sink_id() == frame_sink_id_); | |
66 OwningSurfaceMap::iterator it = surface_map_.find(new_id); | 63 OwningSurfaceMap::iterator it = surface_map_.find(new_id); |
67 DCHECK(it != surface_map_.end()); | 64 DCHECK(it != surface_map_.end()); |
68 Surface* old_surface = manager_->GetSurfaceForId(old_id); | 65 Surface* old_surface = |
| 66 manager_->GetSurfaceForId(SurfaceId(frame_sink_id_, old_id)); |
69 if (old_surface) { | 67 if (old_surface) { |
70 it->second->SetPreviousFrameSurface(old_surface); | 68 it->second->SetPreviousFrameSurface(old_surface); |
71 } | 69 } |
72 } | 70 } |
73 | 71 |
74 void SurfaceFactory::SubmitCompositorFrame(const SurfaceId& surface_id, | 72 void SurfaceFactory::SubmitCompositorFrame(const LocalFrameId& local_frame_id, |
75 CompositorFrame frame, | 73 CompositorFrame frame, |
76 const DrawCallback& callback) { | 74 const DrawCallback& callback) { |
77 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); | 75 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); |
78 DCHECK(surface_id.frame_sink_id() == frame_sink_id_); | 76 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); |
79 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | |
80 DCHECK(it != surface_map_.end()); | 77 DCHECK(it != surface_map_.end()); |
81 DCHECK(it->second->factory().get() == this); | 78 DCHECK(it->second->factory().get() == this); |
82 it->second->QueueFrame(std::move(frame), callback); | 79 it->second->QueueFrame(std::move(frame), callback); |
83 if (!manager_->SurfaceModified(surface_id)) { | 80 if (!manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id))) { |
84 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); | 81 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); |
85 it->second->RunDrawCallbacks(); | 82 it->second->RunDrawCallbacks(); |
86 } | 83 } |
87 } | 84 } |
88 | 85 |
89 void SurfaceFactory::RequestCopyOfSurface( | 86 void SurfaceFactory::RequestCopyOfSurface( |
90 const SurfaceId& surface_id, | 87 const LocalFrameId& local_frame_id, |
91 std::unique_ptr<CopyOutputRequest> copy_request) { | 88 std::unique_ptr<CopyOutputRequest> copy_request) { |
92 DCHECK(surface_id.frame_sink_id() == frame_sink_id_); | 89 OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); |
93 OwningSurfaceMap::iterator it = surface_map_.find(surface_id); | |
94 if (it == surface_map_.end()) { | 90 if (it == surface_map_.end()) { |
95 copy_request->SendEmptyResult(); | 91 copy_request->SendEmptyResult(); |
96 return; | 92 return; |
97 } | 93 } |
98 DCHECK(it->second->factory().get() == this); | 94 DCHECK(it->second->factory().get() == this); |
99 it->second->RequestCopyOfOutput(std::move(copy_request)); | 95 it->second->RequestCopyOfOutput(std::move(copy_request)); |
100 manager_->SurfaceModified(surface_id); | 96 manager_->SurfaceModified(SurfaceId(frame_sink_id_, local_frame_id)); |
101 } | 97 } |
102 | 98 |
103 void SurfaceFactory::WillDrawSurface(const SurfaceId& id, | 99 void SurfaceFactory::WillDrawSurface(const LocalFrameId& id, |
104 const gfx::Rect& damage_rect) { | 100 const gfx::Rect& damage_rect) { |
105 DCHECK(id.frame_sink_id() == frame_sink_id_); | |
106 client_->WillDrawSurface(id, damage_rect); | 101 client_->WillDrawSurface(id, damage_rect); |
107 } | 102 } |
108 | 103 |
109 void SurfaceFactory::ReceiveFromChild( | 104 void SurfaceFactory::ReceiveFromChild( |
110 const TransferableResourceArray& resources) { | 105 const TransferableResourceArray& resources) { |
111 holder_.ReceiveFromChild(resources); | 106 holder_.ReceiveFromChild(resources); |
112 } | 107 } |
113 | 108 |
114 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 109 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |
115 holder_.RefResources(resources); | 110 holder_.RefResources(resources); |
116 } | 111 } |
117 | 112 |
118 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 113 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |
119 holder_.UnrefResources(resources); | 114 holder_.UnrefResources(resources); |
120 } | 115 } |
121 | 116 |
122 } // namespace cc | 117 } // namespace cc |
OLD | NEW |