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 <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 provider_->SetChildNeedsSyncPoints( | 124 provider_->SetChildNeedsSyncPoints( |
125 child_id, surface->factory()->needs_sync_points()); | 125 child_id, surface->factory()->needs_sync_points()); |
126 } | 126 } |
127 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; | 127 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; |
128 return child_id; | 128 return child_id; |
129 } else { | 129 } else { |
130 return it->second; | 130 return it->second; |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 static ResourceId ResourceRemapHelper( | |
135 const ResourceProvider::ResourceIdMap& child_to_parent_map, | |
136 ResourceId id) { | |
137 ResourceProvider::ResourceIdMap::const_iterator it = | |
138 child_to_parent_map.find(id); | |
139 DCHECK(it != child_to_parent_map.end()); | |
140 | |
141 DCHECK_EQ(it->first, id); | |
142 ResourceId remapped_id = it->second; | |
143 return remapped_id; | |
144 } | |
145 | |
146 static ResourceId ValidateResourceHelper( | |
147 bool* invalid_frame, | |
148 const ResourceProvider::ResourceIdMap& child_to_parent_map, | |
149 ResourceProvider::ResourceIdSet* resources_in_frame, | |
150 ResourceId id) { | |
151 ResourceProvider::ResourceIdMap::const_iterator it = | |
152 child_to_parent_map.find(id); | |
153 if (it == child_to_parent_map.end()) { | |
154 *invalid_frame = true; | |
155 return id; | |
156 } | |
157 resources_in_frame->insert(id); | |
158 return id; | |
159 } | |
160 | |
161 bool SurfaceAggregator::ValidateResources( | 134 bool SurfaceAggregator::ValidateResources( |
162 Surface* surface, | 135 Surface* surface, |
163 const DelegatedFrameData* frame_data) { | 136 const DelegatedFrameData* frame_data) { |
164 if (!provider_) // TODO(jamesr): hack for unit tests that don't set up rp | 137 if (!provider_) // TODO(jamesr): hack for unit tests that don't set up rp |
165 return false; | 138 return false; |
166 | 139 |
167 int child_id = ChildIdForSurface(surface); | 140 int child_id = ChildIdForSurface(surface); |
168 if (surface->factory()) | 141 if (surface->factory()) |
169 surface->factory()->RefResources(frame_data->resource_list); | 142 surface->factory()->RefResources(frame_data->resource_list); |
170 provider_->ReceiveFromChild(child_id, frame_data->resource_list); | 143 provider_->ReceiveFromChild(child_id, frame_data->resource_list); |
171 | 144 |
172 ResourceProvider::ResourceIdSet referenced_resources; | 145 ResourceProvider::ResourceIdSet referenced_resources; |
173 size_t reserve_size = frame_data->resource_list.size(); | 146 size_t reserve_size = frame_data->resource_list.size(); |
174 #if defined(COMPILER_MSVC) | 147 #if defined(COMPILER_MSVC) |
175 referenced_resources.reserve(reserve_size); | 148 referenced_resources.reserve(reserve_size); |
176 #elif defined(COMPILER_GCC) | 149 #elif defined(COMPILER_GCC) |
177 // Pre-standard hash-tables only implement resize, which behaves similarly | 150 // Pre-standard hash-tables only implement resize, which behaves similarly |
178 // to reserve for these keys. Resizing to 0 may also be broken (particularly | 151 // to reserve for these keys. Resizing to 0 may also be broken (particularly |
179 // on stlport). | 152 // on stlport). |
180 // TODO(jbauman): Replace with reserve when C++11 is supported everywhere. | 153 // TODO(jbauman): Replace with reserve when C++11 is supported everywhere. |
181 if (reserve_size) | 154 if (reserve_size) |
182 referenced_resources.resize(reserve_size); | 155 referenced_resources.resize(reserve_size); |
183 #endif | 156 #endif |
184 | 157 |
185 bool invalid_frame = false; | 158 bool invalid_frame = false; |
186 DrawQuad::ResourceIteratorCallback remap = | 159 const ResourceProvider::ResourceIdMap& child_to_parent_map = |
187 base::Bind(&ValidateResourceHelper, &invalid_frame, | 160 provider_->GetChildToParentMap(child_id); |
188 base::ConstRef(provider_->GetChildToParentMap(child_id)), | |
189 &referenced_resources); | |
190 for (const auto& render_pass : frame_data->render_pass_list) { | 161 for (const auto& render_pass : frame_data->render_pass_list) { |
191 for (const auto& quad : render_pass->quad_list) | 162 for (const auto& quad : render_pass->quad_list) { |
192 quad->IterateResources(remap); | 163 for (ResourceId resource_id : quad->resources) { |
164 ResourceProvider::ResourceIdMap::const_iterator it = | |
165 child_to_parent_map.find(resource_id); | |
166 if (it == child_to_parent_map.end()) { | |
167 invalid_frame = true; | |
168 break; | |
169 } | |
170 referenced_resources.insert(resource_id); | |
171 } | |
172 } | |
193 } | 173 } |
194 | 174 |
195 if (!invalid_frame) | 175 if (!invalid_frame) |
196 provider_->DeclareUsedResourcesFromChild(child_id, referenced_resources); | 176 provider_->DeclareUsedResourcesFromChild(child_id, referenced_resources); |
197 | 177 |
198 return invalid_frame; | 178 return invalid_frame; |
199 } | 179 } |
200 | 180 |
201 gfx::Rect SurfaceAggregator::DamageRectForSurface(const Surface* surface, | 181 gfx::Rect SurfaceAggregator::DamageRectForSurface(const Surface* surface, |
202 const RenderPass& source, | 182 const RenderPass& source, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 bool invalid_frame = ValidateResources(surface, frame_data); | 219 bool invalid_frame = ValidateResources(surface, frame_data); |
240 if (invalid_frame) { | 220 if (invalid_frame) { |
241 for (auto& request : copy_requests) { | 221 for (auto& request : copy_requests) { |
242 request.second->SendEmptyResult(); | 222 request.second->SendEmptyResult(); |
243 delete request.second; | 223 delete request.second; |
244 } | 224 } |
245 return; | 225 return; |
246 } | 226 } |
247 | 227 |
248 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 228 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; |
249 DrawQuad::ResourceIteratorCallback remap; | 229 const ResourceProvider::ResourceIdMap& child_to_parent_map = |
250 if (provider_) { | 230 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) |
danakj
2015/05/28 23:00:15
can you // TODO provider check is a hack for unit
vmpstr
2015/05/28 23:35:52
Done.
| |
251 int child_id = ChildIdForSurface(surface); | 231 : ResourceProvider::ResourceIdMap(); |
252 remap = | |
253 base::Bind(&ResourceRemapHelper, | |
254 base::ConstRef(provider_->GetChildToParentMap(child_id))); | |
255 } | |
256 | |
257 bool merge_pass = surface_quad->opacity() == 1.f && copy_requests.empty(); | 232 bool merge_pass = surface_quad->opacity() == 1.f && copy_requests.empty(); |
258 | 233 |
259 gfx::Rect surface_damage = DamageRectForSurface( | 234 gfx::Rect surface_damage = DamageRectForSurface( |
260 surface, *render_pass_list.back(), surface_quad->visible_rect); | 235 surface, *render_pass_list.back(), surface_quad->visible_rect); |
261 const RenderPassList& referenced_passes = render_pass_list; | 236 const RenderPassList& referenced_passes = render_pass_list; |
262 size_t passes_to_copy = | 237 size_t passes_to_copy = |
263 merge_pass ? referenced_passes.size() - 1 : referenced_passes.size(); | 238 merge_pass ? referenced_passes.size() - 1 : referenced_passes.size(); |
264 for (size_t j = 0; j < passes_to_copy; ++j) { | 239 for (size_t j = 0; j < passes_to_copy; ++j) { |
265 const RenderPass& source = *referenced_passes[j]; | 240 const RenderPass& source = *referenced_passes[j]; |
266 | 241 |
(...skipping 11 matching lines...) Expand all Loading... | |
278 | 253 |
279 // Contributing passes aggregated in to the pass list need to take the | 254 // Contributing passes aggregated in to the pass list need to take the |
280 // transform of the surface quad into account to update their transform to | 255 // transform of the surface quad into account to update their transform to |
281 // the root surface. | 256 // the root surface. |
282 copy_pass->transform_to_root_target.ConcatTransform( | 257 copy_pass->transform_to_root_target.ConcatTransform( |
283 surface_quad->quadTransform()); | 258 surface_quad->quadTransform()); |
284 copy_pass->transform_to_root_target.ConcatTransform(target_transform); | 259 copy_pass->transform_to_root_target.ConcatTransform(target_transform); |
285 copy_pass->transform_to_root_target.ConcatTransform( | 260 copy_pass->transform_to_root_target.ConcatTransform( |
286 dest_pass->transform_to_root_target); | 261 dest_pass->transform_to_root_target); |
287 | 262 |
288 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, remap, | 263 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, |
289 gfx::Transform(), ClipData(), copy_pass.get(), surface_id); | 264 child_to_parent_map, gfx::Transform(), ClipData(), |
265 copy_pass.get(), surface_id); | |
290 | 266 |
291 if (j == referenced_passes.size() - 1) | 267 if (j == referenced_passes.size() - 1) |
292 surface_damage = gfx::UnionRects(surface_damage, copy_pass->damage_rect); | 268 surface_damage = gfx::UnionRects(surface_damage, copy_pass->damage_rect); |
293 | 269 |
294 dest_pass_list_->push_back(copy_pass.Pass()); | 270 dest_pass_list_->push_back(copy_pass.Pass()); |
295 } | 271 } |
296 | 272 |
297 const RenderPass& last_pass = *render_pass_list.back(); | 273 const RenderPass& last_pass = *render_pass_list.back(); |
298 if (merge_pass) { | 274 if (merge_pass) { |
299 // TODO(jamesr): Clean up last pass special casing. | 275 // TODO(jamesr): Clean up last pass special casing. |
300 const QuadList& quads = last_pass.quad_list; | 276 const QuadList& quads = last_pass.quad_list; |
301 | 277 |
302 gfx::Transform surface_transform = surface_quad->quadTransform(); | 278 gfx::Transform surface_transform = surface_quad->quadTransform(); |
303 surface_transform.ConcatTransform(target_transform); | 279 surface_transform.ConcatTransform(target_transform); |
304 | 280 |
305 // Intersect the transformed visible rect and the clip rect to create a | 281 // Intersect the transformed visible rect and the clip rect to create a |
306 // smaller cliprect for the quad. | 282 // smaller cliprect for the quad. |
307 ClipData surface_quad_clip_rect( | 283 ClipData surface_quad_clip_rect( |
308 true, MathUtil::MapEnclosingClippedRect(surface_quad->quadTransform(), | 284 true, MathUtil::MapEnclosingClippedRect(surface_quad->quadTransform(), |
309 surface_quad->visible_rect)); | 285 surface_quad->visible_rect)); |
310 if (surface_quad->isClipped()) | 286 if (surface_quad->isClipped()) |
311 surface_quad_clip_rect.rect.Intersect(surface_quad->clipRect()); | 287 surface_quad_clip_rect.rect.Intersect(surface_quad->clipRect()); |
312 | 288 |
313 ClipData quads_clip = | 289 ClipData quads_clip = |
314 CalculateClipRect(clip_rect, surface_quad_clip_rect, target_transform); | 290 CalculateClipRect(clip_rect, surface_quad_clip_rect, target_transform); |
315 | 291 |
316 CopyQuadsToPass(quads, last_pass.shared_quad_state_list, remap, | 292 CopyQuadsToPass(quads, last_pass.shared_quad_state_list, |
317 surface_transform, quads_clip, dest_pass, surface_id); | 293 child_to_parent_map, surface_transform, quads_clip, |
294 dest_pass, surface_id); | |
318 } else { | 295 } else { |
319 RenderPassId remapped_pass_id = RemapPassId(last_pass.id, surface_id); | 296 RenderPassId remapped_pass_id = RemapPassId(last_pass.id, surface_id); |
320 | 297 |
321 CopySharedQuadState(surface_quad->shared_quad_state, target_transform, | 298 CopySharedQuadState(surface_quad->shared_quad_state, target_transform, |
322 clip_rect, dest_pass); | 299 clip_rect, dest_pass); |
323 | 300 |
324 SharedQuadState* shared_quad_state = | 301 SharedQuadState* shared_quad_state = |
325 dest_pass->shared_quad_state_list.back(); | 302 dest_pass->shared_quad_state_list.back(); |
326 RenderPassDrawQuad* quad = | 303 RenderPassDrawQuad* quad = |
327 dest_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); | 304 dest_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 ClipData new_clip_rect = CalculateClipRect( | 341 ClipData new_clip_rect = CalculateClipRect( |
365 clip_rect, ClipData(source_sqs->is_clipped, source_sqs->clip_rect), | 342 clip_rect, ClipData(source_sqs->is_clipped, source_sqs->clip_rect), |
366 target_transform); | 343 target_transform); |
367 copy_shared_quad_state->is_clipped = new_clip_rect.is_clipped; | 344 copy_shared_quad_state->is_clipped = new_clip_rect.is_clipped; |
368 copy_shared_quad_state->clip_rect = new_clip_rect.rect; | 345 copy_shared_quad_state->clip_rect = new_clip_rect.rect; |
369 } | 346 } |
370 | 347 |
371 void SurfaceAggregator::CopyQuadsToPass( | 348 void SurfaceAggregator::CopyQuadsToPass( |
372 const QuadList& source_quad_list, | 349 const QuadList& source_quad_list, |
373 const SharedQuadStateList& source_shared_quad_state_list, | 350 const SharedQuadStateList& source_shared_quad_state_list, |
374 const DrawQuad::ResourceIteratorCallback& remap, | 351 const ResourceProvider::ResourceIdMap& child_to_parent_map, |
375 const gfx::Transform& target_transform, | 352 const gfx::Transform& target_transform, |
376 const ClipData& clip_rect, | 353 const ClipData& clip_rect, |
377 RenderPass* dest_pass, | 354 RenderPass* dest_pass, |
378 SurfaceId surface_id) { | 355 SurfaceId surface_id) { |
379 const SharedQuadState* last_copied_source_shared_quad_state = NULL; | 356 const SharedQuadState* last_copied_source_shared_quad_state = NULL; |
380 | 357 |
381 SharedQuadStateList::ConstIterator sqs_iter = | 358 SharedQuadStateList::ConstIterator sqs_iter = |
382 source_shared_quad_state_list.begin(); | 359 source_shared_quad_state_list.begin(); |
383 for (const auto& quad : source_quad_list) { | 360 for (const auto& quad : source_quad_list) { |
384 while (quad->shared_quad_state != *sqs_iter) { | 361 while (quad->shared_quad_state != *sqs_iter) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 pass_quad, dest_pass->shared_quad_state_list.back(), | 393 pass_quad, dest_pass->shared_quad_state_list.back(), |
417 remapped_pass_id); | 394 remapped_pass_id); |
418 dest_pass->damage_rect = | 395 dest_pass->damage_rect = |
419 gfx::UnionRects(dest_pass->damage_rect, | 396 gfx::UnionRects(dest_pass->damage_rect, |
420 MathUtil::MapEnclosingClippedRect( | 397 MathUtil::MapEnclosingClippedRect( |
421 dest_quad->quadTransform(), pass_damage)); | 398 dest_quad->quadTransform(), pass_damage)); |
422 } else { | 399 } else { |
423 dest_quad = dest_pass->CopyFromAndAppendDrawQuad( | 400 dest_quad = dest_pass->CopyFromAndAppendDrawQuad( |
424 quad, dest_pass->shared_quad_state_list.back()); | 401 quad, dest_pass->shared_quad_state_list.back()); |
425 } | 402 } |
426 if (!remap.is_null()) | 403 if (!child_to_parent_map.empty()) { |
427 dest_quad->IterateResources(remap); | 404 for (ResourceId& resource_id : dest_quad->resources) { |
405 ResourceProvider::ResourceIdMap::const_iterator it = | |
406 child_to_parent_map.find(resource_id); | |
407 DCHECK(it != child_to_parent_map.end()); | |
408 | |
409 DCHECK_EQ(it->first, resource_id); | |
410 ResourceId remapped_id = it->second; | |
411 resource_id = remapped_id; | |
412 } | |
413 } | |
428 } | 414 } |
429 } | 415 } |
430 } | 416 } |
431 | 417 |
432 void SurfaceAggregator::CopyPasses(const DelegatedFrameData* frame_data, | 418 void SurfaceAggregator::CopyPasses(const DelegatedFrameData* frame_data, |
433 Surface* surface) { | 419 Surface* surface) { |
434 // The root surface is allowed to have copy output requests, so grab them | 420 // The root surface is allowed to have copy output requests, so grab them |
435 // off its render passes. | 421 // off its render passes. |
436 std::multimap<RenderPassId, CopyOutputRequest*> copy_requests; | 422 std::multimap<RenderPassId, CopyOutputRequest*> copy_requests; |
437 surface->TakeCopyOutputRequests(©_requests); | 423 surface->TakeCopyOutputRequests(©_requests); |
438 | 424 |
439 const RenderPassList& source_pass_list = frame_data->render_pass_list; | 425 const RenderPassList& source_pass_list = frame_data->render_pass_list; |
440 bool invalid_frame = ValidateResources(surface, frame_data); | 426 bool invalid_frame = ValidateResources(surface, frame_data); |
441 DCHECK(!invalid_frame); | 427 DCHECK(!invalid_frame); |
442 if (invalid_frame) | 428 if (invalid_frame) |
443 return; | 429 return; |
444 | 430 |
445 DrawQuad::ResourceIteratorCallback remap; | 431 const ResourceProvider::ResourceIdMap& child_to_parent_map = |
446 if (provider_) { | 432 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) |
danakj
2015/05/28 23:00:15
todo-o
vmpstr
2015/05/28 23:35:52
Done.
| |
447 int child_id = ChildIdForSurface(surface); | 433 : ResourceProvider::ResourceIdMap(); |
danakj
2015/05/28 23:00:15
I'm kinda surprised this doesn't cause the tests t
vmpstr
2015/05/28 23:35:52
It's because of l403, we only run the loop when th
| |
448 remap = | |
449 base::Bind(&ResourceRemapHelper, | |
450 base::ConstRef(provider_->GetChildToParentMap(child_id))); | |
451 } | |
452 | |
453 for (size_t i = 0; i < source_pass_list.size(); ++i) { | 434 for (size_t i = 0; i < source_pass_list.size(); ++i) { |
454 const RenderPass& source = *source_pass_list[i]; | 435 const RenderPass& source = *source_pass_list[i]; |
455 | 436 |
456 size_t sqs_size = source.shared_quad_state_list.size(); | 437 size_t sqs_size = source.shared_quad_state_list.size(); |
457 size_t dq_size = source.quad_list.size(); | 438 size_t dq_size = source.quad_list.size(); |
458 scoped_ptr<RenderPass> copy_pass(RenderPass::Create(sqs_size, dq_size)); | 439 scoped_ptr<RenderPass> copy_pass(RenderPass::Create(sqs_size, dq_size)); |
459 | 440 |
460 MoveMatchingRequests(source.id, ©_requests, ©_pass->copy_requests); | 441 MoveMatchingRequests(source.id, ©_requests, ©_pass->copy_requests); |
461 | 442 |
462 RenderPassId remapped_pass_id = | 443 RenderPassId remapped_pass_id = |
463 RemapPassId(source.id, surface->surface_id()); | 444 RemapPassId(source.id, surface->surface_id()); |
464 | 445 |
465 gfx::Rect damage_rect = | 446 gfx::Rect damage_rect = |
466 (i < source_pass_list.size() - 1) | 447 (i < source_pass_list.size() - 1) |
467 ? gfx::Rect() | 448 ? gfx::Rect() |
468 : DamageRectForSurface(surface, source, source.output_rect); | 449 : DamageRectForSurface(surface, source, source.output_rect); |
469 copy_pass->SetAll(remapped_pass_id, source.output_rect, damage_rect, | 450 copy_pass->SetAll(remapped_pass_id, source.output_rect, damage_rect, |
470 source.transform_to_root_target, | 451 source.transform_to_root_target, |
471 source.has_transparent_background); | 452 source.has_transparent_background); |
472 | 453 |
473 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, remap, | 454 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, |
474 gfx::Transform(), ClipData(), copy_pass.get(), | 455 child_to_parent_map, gfx::Transform(), ClipData(), |
475 surface->surface_id()); | 456 copy_pass.get(), surface->surface_id()); |
476 | 457 |
477 dest_pass_list_->push_back(copy_pass.Pass()); | 458 dest_pass_list_->push_back(copy_pass.Pass()); |
478 } | 459 } |
479 } | 460 } |
480 | 461 |
481 void SurfaceAggregator::RemoveUnreferencedChildren() { | 462 void SurfaceAggregator::RemoveUnreferencedChildren() { |
482 for (const auto& surface : previous_contained_surfaces_) { | 463 for (const auto& surface : previous_contained_surfaces_) { |
483 if (!contained_surfaces_.count(surface.first)) { | 464 if (!contained_surfaces_.count(surface.first)) { |
484 SurfaceToResourceChildIdMap::iterator it = | 465 SurfaceToResourceChildIdMap::iterator it = |
485 surface_id_to_resource_child_id_.find(surface.first); | 466 surface_id_to_resource_child_id_.find(surface.first); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 | 533 |
553 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { | 534 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { |
554 auto it = previous_contained_surfaces_.find(surface_id); | 535 auto it = previous_contained_surfaces_.find(surface_id); |
555 if (it == previous_contained_surfaces_.end()) | 536 if (it == previous_contained_surfaces_.end()) |
556 return; | 537 return; |
557 // Set the last drawn index as 0 to ensure full damage next time it's drawn. | 538 // Set the last drawn index as 0 to ensure full damage next time it's drawn. |
558 it->second = 0; | 539 it->second = 0; |
559 } | 540 } |
560 | 541 |
561 } // namespace cc | 542 } // namespace cc |
OLD | NEW |