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_aggregator.h" | 5 #include "cc/surfaces/surface_aggregator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 return 0; | 90 return 0; |
91 } | 91 } |
92 | 92 |
93 DCHECK_EQ(it->first, id); | 93 DCHECK_EQ(it->first, id); |
94 ResourceProvider::ResourceId remapped_id = it->second; | 94 ResourceProvider::ResourceId remapped_id = it->second; |
95 resources_in_frame->push_back(id); | 95 resources_in_frame->push_back(id); |
96 return remapped_id; | 96 return remapped_id; |
97 } | 97 } |
98 | 98 |
99 bool SurfaceAggregator::TakeResources(Surface* surface, | 99 bool SurfaceAggregator::TakeResources(Surface* surface, |
100 DelegatedFrameData* frame_data) { | 100 const DelegatedFrameData* frame_data, |
101 RenderPassList* render_pass_list) { | |
102 RenderPass::CopyAll(frame_data->render_pass_list, render_pass_list); | |
jamesr
2014/07/24 19:55:47
why do we need this copy?
| |
101 if (!provider_) // TODO(jamesr): hack for unit tests that don't set up rp | 103 if (!provider_) // TODO(jamesr): hack for unit tests that don't set up rp |
102 return false; | 104 return false; |
103 | 105 |
104 int child_id = ChildIdForSurface(surface); | 106 int child_id = ChildIdForSurface(surface); |
105 provider_->ReceiveFromChild(child_id, frame_data->resource_list); | 107 provider_->ReceiveFromChild(child_id, frame_data->resource_list); |
106 surface->factory()->RefResources(frame_data->resource_list); | 108 surface->factory()->RefResources(frame_data->resource_list); |
107 | 109 |
108 typedef ResourceProvider::ResourceIdArray IdArray; | 110 typedef ResourceProvider::ResourceIdArray IdArray; |
109 IdArray referenced_resources; | 111 IdArray referenced_resources; |
110 | 112 |
111 bool invalid_frame = false; | 113 bool invalid_frame = false; |
112 DrawQuad::ResourceIteratorCallback remap = | 114 DrawQuad::ResourceIteratorCallback remap = |
113 base::Bind(&ResourceRemapHelper, | 115 base::Bind(&ResourceRemapHelper, |
114 &invalid_frame, | 116 &invalid_frame, |
115 provider_->GetChildToParentMap(child_id), | 117 provider_->GetChildToParentMap(child_id), |
116 &referenced_resources); | 118 &referenced_resources); |
117 const RenderPassList& referenced_passes = frame_data->render_pass_list; | 119 for (RenderPassList::iterator it = render_pass_list->begin(); |
118 for (RenderPassList::const_iterator it = referenced_passes.begin(); | 120 it != render_pass_list->end(); |
119 it != referenced_passes.end(); | |
120 ++it) { | 121 ++it) { |
121 const QuadList& quad_list = (*it)->quad_list; | 122 QuadList& quad_list = (*it)->quad_list; |
122 for (QuadList::const_iterator quad_it = quad_list.begin(); | 123 for (QuadList::iterator quad_it = quad_list.begin(); |
123 quad_it != quad_list.end(); | 124 quad_it != quad_list.end(); |
124 ++quad_it) { | 125 ++quad_it) { |
125 (*quad_it)->IterateResources(remap); | 126 (*quad_it)->IterateResources(remap); |
126 } | 127 } |
127 } | 128 } |
128 if (!invalid_frame) | 129 if (!invalid_frame) |
129 provider_->DeclareUsedResourcesFromChild(child_id, referenced_resources); | 130 provider_->DeclareUsedResourcesFromChild(child_id, referenced_resources); |
130 | 131 |
131 return invalid_frame; | 132 return invalid_frame; |
132 } | 133 } |
133 | 134 |
134 void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad, | 135 void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad, |
135 RenderPass* dest_pass) { | 136 RenderPass* dest_pass) { |
136 SurfaceId surface_id = surface_quad->surface_id; | 137 SurfaceId surface_id = surface_quad->surface_id; |
137 // If this surface's id is already in our referenced set then it creates | 138 // If this surface's id is already in our referenced set then it creates |
138 // a cycle in the graph and should be dropped. | 139 // a cycle in the graph and should be dropped. |
139 if (referenced_surfaces_.count(surface_id)) | 140 if (referenced_surfaces_.count(surface_id)) |
140 return; | 141 return; |
141 Surface* surface = manager_->GetSurfaceForId(surface_id); | 142 Surface* surface = manager_->GetSurfaceForId(surface_id); |
142 if (!surface) | 143 if (!surface) |
143 return; | 144 return; |
144 CompositorFrame* frame = surface->GetEligibleFrame(); | 145 const CompositorFrame* frame = surface->GetEligibleFrame(); |
145 if (!frame) | 146 if (!frame) |
146 return; | 147 return; |
147 DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); | 148 const DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); |
148 if (!frame_data) | 149 if (!frame_data) |
149 return; | 150 return; |
150 | 151 |
151 bool invalid_frame = TakeResources(surface, frame_data); | 152 RenderPassList render_pass_list; |
153 bool invalid_frame = TakeResources(surface, frame_data, &render_pass_list); | |
152 if (invalid_frame) | 154 if (invalid_frame) |
153 return; | 155 return; |
154 | 156 |
155 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 157 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; |
156 | 158 |
157 const RenderPassList& referenced_passes = frame_data->render_pass_list; | 159 const RenderPassList& referenced_passes = render_pass_list; |
158 for (size_t j = 0; j + 1 < referenced_passes.size(); ++j) { | 160 for (size_t j = 0; j + 1 < referenced_passes.size(); ++j) { |
159 const RenderPass& source = *referenced_passes[j]; | 161 const RenderPass& source = *referenced_passes[j]; |
160 | 162 |
161 scoped_ptr<RenderPass> copy_pass(RenderPass::Create()); | 163 scoped_ptr<RenderPass> copy_pass(RenderPass::Create()); |
162 | 164 |
163 RenderPass::Id remapped_pass_id = RemapPassId(source.id, surface_id); | 165 RenderPass::Id remapped_pass_id = RemapPassId(source.id, surface_id); |
164 | 166 |
165 copy_pass->SetAll(remapped_pass_id, | 167 copy_pass->SetAll(remapped_pass_id, |
166 source.output_rect, | 168 source.output_rect, |
167 source.damage_rect, | 169 source.damage_rect, |
(...skipping 11 matching lines...) Expand all Loading... | |
179 CopyQuadsToPass(source.quad_list, | 181 CopyQuadsToPass(source.quad_list, |
180 source.shared_quad_state_list, | 182 source.shared_quad_state_list, |
181 gfx::Transform(), | 183 gfx::Transform(), |
182 copy_pass.get(), | 184 copy_pass.get(), |
183 surface_id); | 185 surface_id); |
184 | 186 |
185 dest_pass_list_->push_back(copy_pass.Pass()); | 187 dest_pass_list_->push_back(copy_pass.Pass()); |
186 } | 188 } |
187 | 189 |
188 // TODO(jamesr): Clean up last pass special casing. | 190 // TODO(jamesr): Clean up last pass special casing. |
189 const RenderPass& last_pass = *frame_data->render_pass_list.back(); | 191 const RenderPass& last_pass = *render_pass_list.back(); |
190 const QuadList& quads = last_pass.quad_list; | 192 const QuadList& quads = last_pass.quad_list; |
191 | 193 |
192 // TODO(jamesr): Make sure clipping is enforced. | 194 // TODO(jamesr): Make sure clipping is enforced. |
193 CopyQuadsToPass(quads, | 195 CopyQuadsToPass(quads, |
194 last_pass.shared_quad_state_list, | 196 last_pass.shared_quad_state_list, |
195 surface_quad->quadTransform(), | 197 surface_quad->quadTransform(), |
196 dest_pass, | 198 dest_pass, |
197 surface_id); | 199 surface_id); |
198 | 200 |
199 referenced_surfaces_.erase(it); | 201 referenced_surfaces_.erase(it); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 copy_pass.get(), | 283 copy_pass.get(), |
282 surface_id); | 284 surface_id); |
283 | 285 |
284 dest_pass_list_->push_back(copy_pass.Pass()); | 286 dest_pass_list_->push_back(copy_pass.Pass()); |
285 } | 287 } |
286 } | 288 } |
287 | 289 |
288 scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(SurfaceId surface_id) { | 290 scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(SurfaceId surface_id) { |
289 Surface* surface = manager_->GetSurfaceForId(surface_id); | 291 Surface* surface = manager_->GetSurfaceForId(surface_id); |
290 DCHECK(surface); | 292 DCHECK(surface); |
291 CompositorFrame* root_surface_frame = surface->GetEligibleFrame(); | 293 const CompositorFrame* root_surface_frame = surface->GetEligibleFrame(); |
292 if (!root_surface_frame) | 294 if (!root_surface_frame) |
293 return scoped_ptr<CompositorFrame>(); | 295 return scoped_ptr<CompositorFrame>(); |
294 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate"); | 296 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate"); |
295 | 297 |
296 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 298 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
297 frame->delegated_frame_data = make_scoped_ptr(new DelegatedFrameData); | 299 frame->delegated_frame_data = make_scoped_ptr(new DelegatedFrameData); |
298 | 300 |
299 DCHECK(root_surface_frame->delegated_frame_data); | 301 DCHECK(root_surface_frame->delegated_frame_data); |
300 | 302 |
301 const RenderPassList& source_pass_list = | 303 RenderPassList source_pass_list; |
302 root_surface_frame->delegated_frame_data->render_pass_list; | |
303 | 304 |
304 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 305 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; |
305 | 306 |
306 dest_resource_list_ = &frame->delegated_frame_data->resource_list; | 307 dest_resource_list_ = &frame->delegated_frame_data->resource_list; |
307 dest_pass_list_ = &frame->delegated_frame_data->render_pass_list; | 308 dest_pass_list_ = &frame->delegated_frame_data->render_pass_list; |
308 | 309 |
309 bool invalid_frame = | 310 bool invalid_frame = |
310 TakeResources(surface, root_surface_frame->delegated_frame_data.get()); | 311 TakeResources(surface, |
312 root_surface_frame->delegated_frame_data.get(), | |
313 &source_pass_list); | |
311 DCHECK(!invalid_frame); | 314 DCHECK(!invalid_frame); |
312 | 315 |
313 CopyPasses(source_pass_list, surface_id); | 316 CopyPasses(source_pass_list, surface_id); |
314 | 317 |
315 referenced_surfaces_.erase(it); | 318 referenced_surfaces_.erase(it); |
316 DCHECK(referenced_surfaces_.empty()); | 319 DCHECK(referenced_surfaces_.empty()); |
317 | 320 |
318 dest_pass_list_ = NULL; | 321 dest_pass_list_ = NULL; |
319 | 322 |
320 // TODO(jamesr): Aggregate all resource references into the returned frame's | 323 // TODO(jamesr): Aggregate all resource references into the returned frame's |
321 // resource list. | 324 // resource list. |
322 | 325 |
323 return frame.Pass(); | 326 return frame.Pass(); |
324 } | 327 } |
325 | 328 |
326 } // namespace cc | 329 } // namespace cc |
OLD | NEW |