Chromium Code Reviews| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 #elif defined(COMPILER_GCC) | 176 #elif defined(COMPILER_GCC) |
| 177 // Pre-standard hash-tables only implement resize, which behaves similarly | 177 // Pre-standard hash-tables only implement resize, which behaves similarly |
| 178 // to reserve for these keys. Resizing to 0 may also be broken (particularly | 178 // to reserve for these keys. Resizing to 0 may also be broken (particularly |
| 179 // on stlport). | 179 // on stlport). |
| 180 // TODO(jbauman): Replace with reserve when C++11 is supported everywhere. | 180 // TODO(jbauman): Replace with reserve when C++11 is supported everywhere. |
| 181 if (reserve_size) | 181 if (reserve_size) |
| 182 referenced_resources.resize(reserve_size); | 182 referenced_resources.resize(reserve_size); |
| 183 #endif | 183 #endif |
| 184 | 184 |
| 185 bool invalid_frame = false; | 185 bool invalid_frame = false; |
| 186 DrawQuad::ResourceIteratorCallback remap = | 186 const ResourceProvider::ResourceIdMap& child_to_parent_map = |
| 187 base::Bind(&ValidateResourceHelper, &invalid_frame, | 187 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) { | 188 for (const auto& render_pass : frame_data->render_pass_list) { |
| 191 for (const auto& quad : render_pass->quad_list) | 189 for (const auto& quad : render_pass->quad_list) { |
| 192 quad->IterateResources(remap); | 190 quad->IterateResources( |
| 191 [&invalid_frame, &child_to_parent_map, &referenced_resources]( | |
| 192 ResourceId resource_id) { | |
| 193 return ValidateResourceHelper(&invalid_frame, child_to_parent_map, | |
| 194 &referenced_resources, resource_id); | |
|
piman
2015/05/28 18:37:59
nit: I would inline ValidateResourceHelper here. I
vmpstr
2015/05/28 19:18:50
Done.
| |
| 195 }); | |
| 196 } | |
| 193 } | 197 } |
| 194 | 198 |
| 195 if (!invalid_frame) | 199 if (!invalid_frame) |
| 196 provider_->DeclareUsedResourcesFromChild(child_id, referenced_resources); | 200 provider_->DeclareUsedResourcesFromChild(child_id, referenced_resources); |
| 197 | 201 |
| 198 return invalid_frame; | 202 return invalid_frame; |
| 199 } | 203 } |
| 200 | 204 |
| 201 gfx::Rect SurfaceAggregator::DamageRectForSurface(const Surface* surface, | 205 gfx::Rect SurfaceAggregator::DamageRectForSurface(const Surface* surface, |
| 202 const RenderPass& source, | 206 const RenderPass& source, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 bool invalid_frame = ValidateResources(surface, frame_data); | 243 bool invalid_frame = ValidateResources(surface, frame_data); |
| 240 if (invalid_frame) { | 244 if (invalid_frame) { |
| 241 for (auto& request : copy_requests) { | 245 for (auto& request : copy_requests) { |
| 242 request.second->SendEmptyResult(); | 246 request.second->SendEmptyResult(); |
| 243 delete request.second; | 247 delete request.second; |
| 244 } | 248 } |
| 245 return; | 249 return; |
| 246 } | 250 } |
| 247 | 251 |
| 248 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 252 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; |
| 249 DrawQuad::ResourceIteratorCallback remap; | 253 const ResourceProvider::ResourceIdMap& child_to_parent_map = |
| 250 if (provider_) { | 254 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) |
| 251 int child_id = ChildIdForSurface(surface); | 255 : 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(); | 256 bool merge_pass = surface_quad->opacity() == 1.f && copy_requests.empty(); |
| 258 | 257 |
| 259 gfx::Rect surface_damage = DamageRectForSurface( | 258 gfx::Rect surface_damage = DamageRectForSurface( |
| 260 surface, *render_pass_list.back(), surface_quad->visible_rect); | 259 surface, *render_pass_list.back(), surface_quad->visible_rect); |
| 261 const RenderPassList& referenced_passes = render_pass_list; | 260 const RenderPassList& referenced_passes = render_pass_list; |
| 262 size_t passes_to_copy = | 261 size_t passes_to_copy = |
| 263 merge_pass ? referenced_passes.size() - 1 : referenced_passes.size(); | 262 merge_pass ? referenced_passes.size() - 1 : referenced_passes.size(); |
| 264 for (size_t j = 0; j < passes_to_copy; ++j) { | 263 for (size_t j = 0; j < passes_to_copy; ++j) { |
| 265 const RenderPass& source = *referenced_passes[j]; | 264 const RenderPass& source = *referenced_passes[j]; |
| 266 | 265 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 278 | 277 |
| 279 // Contributing passes aggregated in to the pass list need to take the | 278 // 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 | 279 // transform of the surface quad into account to update their transform to |
| 281 // the root surface. | 280 // the root surface. |
| 282 copy_pass->transform_to_root_target.ConcatTransform( | 281 copy_pass->transform_to_root_target.ConcatTransform( |
| 283 surface_quad->quadTransform()); | 282 surface_quad->quadTransform()); |
| 284 copy_pass->transform_to_root_target.ConcatTransform(target_transform); | 283 copy_pass->transform_to_root_target.ConcatTransform(target_transform); |
| 285 copy_pass->transform_to_root_target.ConcatTransform( | 284 copy_pass->transform_to_root_target.ConcatTransform( |
| 286 dest_pass->transform_to_root_target); | 285 dest_pass->transform_to_root_target); |
| 287 | 286 |
| 288 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, remap, | 287 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, |
| 289 gfx::Transform(), ClipData(), copy_pass.get(), surface_id); | 288 child_to_parent_map, gfx::Transform(), ClipData(), |
| 289 copy_pass.get(), surface_id); | |
| 290 | 290 |
| 291 if (j == referenced_passes.size() - 1) | 291 if (j == referenced_passes.size() - 1) |
| 292 surface_damage = gfx::UnionRects(surface_damage, copy_pass->damage_rect); | 292 surface_damage = gfx::UnionRects(surface_damage, copy_pass->damage_rect); |
| 293 | 293 |
| 294 dest_pass_list_->push_back(copy_pass.Pass()); | 294 dest_pass_list_->push_back(copy_pass.Pass()); |
| 295 } | 295 } |
| 296 | 296 |
| 297 const RenderPass& last_pass = *render_pass_list.back(); | 297 const RenderPass& last_pass = *render_pass_list.back(); |
| 298 if (merge_pass) { | 298 if (merge_pass) { |
| 299 // TODO(jamesr): Clean up last pass special casing. | 299 // TODO(jamesr): Clean up last pass special casing. |
| 300 const QuadList& quads = last_pass.quad_list; | 300 const QuadList& quads = last_pass.quad_list; |
| 301 | 301 |
| 302 gfx::Transform surface_transform = surface_quad->quadTransform(); | 302 gfx::Transform surface_transform = surface_quad->quadTransform(); |
| 303 surface_transform.ConcatTransform(target_transform); | 303 surface_transform.ConcatTransform(target_transform); |
| 304 | 304 |
| 305 // Intersect the transformed visible rect and the clip rect to create a | 305 // Intersect the transformed visible rect and the clip rect to create a |
| 306 // smaller cliprect for the quad. | 306 // smaller cliprect for the quad. |
| 307 ClipData surface_quad_clip_rect( | 307 ClipData surface_quad_clip_rect( |
| 308 true, MathUtil::MapEnclosingClippedRect(surface_quad->quadTransform(), | 308 true, MathUtil::MapEnclosingClippedRect(surface_quad->quadTransform(), |
| 309 surface_quad->visible_rect)); | 309 surface_quad->visible_rect)); |
| 310 if (surface_quad->isClipped()) | 310 if (surface_quad->isClipped()) |
| 311 surface_quad_clip_rect.rect.Intersect(surface_quad->clipRect()); | 311 surface_quad_clip_rect.rect.Intersect(surface_quad->clipRect()); |
| 312 | 312 |
| 313 ClipData quads_clip = | 313 ClipData quads_clip = |
| 314 CalculateClipRect(clip_rect, surface_quad_clip_rect, target_transform); | 314 CalculateClipRect(clip_rect, surface_quad_clip_rect, target_transform); |
| 315 | 315 |
| 316 CopyQuadsToPass(quads, last_pass.shared_quad_state_list, remap, | 316 CopyQuadsToPass(quads, last_pass.shared_quad_state_list, |
| 317 surface_transform, quads_clip, dest_pass, surface_id); | 317 child_to_parent_map, surface_transform, quads_clip, |
| 318 dest_pass, surface_id); | |
| 318 } else { | 319 } else { |
| 319 RenderPassId remapped_pass_id = RemapPassId(last_pass.id, surface_id); | 320 RenderPassId remapped_pass_id = RemapPassId(last_pass.id, surface_id); |
| 320 | 321 |
| 321 CopySharedQuadState(surface_quad->shared_quad_state, target_transform, | 322 CopySharedQuadState(surface_quad->shared_quad_state, target_transform, |
| 322 clip_rect, dest_pass); | 323 clip_rect, dest_pass); |
| 323 | 324 |
| 324 SharedQuadState* shared_quad_state = | 325 SharedQuadState* shared_quad_state = |
| 325 dest_pass->shared_quad_state_list.back(); | 326 dest_pass->shared_quad_state_list.back(); |
| 326 RenderPassDrawQuad* quad = | 327 RenderPassDrawQuad* quad = |
| 327 dest_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); | 328 dest_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 ClipData new_clip_rect = CalculateClipRect( | 365 ClipData new_clip_rect = CalculateClipRect( |
| 365 clip_rect, ClipData(source_sqs->is_clipped, source_sqs->clip_rect), | 366 clip_rect, ClipData(source_sqs->is_clipped, source_sqs->clip_rect), |
| 366 target_transform); | 367 target_transform); |
| 367 copy_shared_quad_state->is_clipped = new_clip_rect.is_clipped; | 368 copy_shared_quad_state->is_clipped = new_clip_rect.is_clipped; |
| 368 copy_shared_quad_state->clip_rect = new_clip_rect.rect; | 369 copy_shared_quad_state->clip_rect = new_clip_rect.rect; |
| 369 } | 370 } |
| 370 | 371 |
| 371 void SurfaceAggregator::CopyQuadsToPass( | 372 void SurfaceAggregator::CopyQuadsToPass( |
| 372 const QuadList& source_quad_list, | 373 const QuadList& source_quad_list, |
| 373 const SharedQuadStateList& source_shared_quad_state_list, | 374 const SharedQuadStateList& source_shared_quad_state_list, |
| 374 const DrawQuad::ResourceIteratorCallback& remap, | 375 const ResourceProvider::ResourceIdMap& child_to_parent_map, |
| 375 const gfx::Transform& target_transform, | 376 const gfx::Transform& target_transform, |
| 376 const ClipData& clip_rect, | 377 const ClipData& clip_rect, |
| 377 RenderPass* dest_pass, | 378 RenderPass* dest_pass, |
| 378 SurfaceId surface_id) { | 379 SurfaceId surface_id) { |
| 379 const SharedQuadState* last_copied_source_shared_quad_state = NULL; | 380 const SharedQuadState* last_copied_source_shared_quad_state = NULL; |
| 380 | 381 |
| 381 SharedQuadStateList::ConstIterator sqs_iter = | 382 SharedQuadStateList::ConstIterator sqs_iter = |
| 382 source_shared_quad_state_list.begin(); | 383 source_shared_quad_state_list.begin(); |
| 383 for (const auto& quad : source_quad_list) { | 384 for (const auto& quad : source_quad_list) { |
| 384 while (quad->shared_quad_state != *sqs_iter) { | 385 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(), | 417 pass_quad, dest_pass->shared_quad_state_list.back(), |
| 417 remapped_pass_id); | 418 remapped_pass_id); |
| 418 dest_pass->damage_rect = | 419 dest_pass->damage_rect = |
| 419 gfx::UnionRects(dest_pass->damage_rect, | 420 gfx::UnionRects(dest_pass->damage_rect, |
| 420 MathUtil::MapEnclosingClippedRect( | 421 MathUtil::MapEnclosingClippedRect( |
| 421 dest_quad->quadTransform(), pass_damage)); | 422 dest_quad->quadTransform(), pass_damage)); |
| 422 } else { | 423 } else { |
| 423 dest_quad = dest_pass->CopyFromAndAppendDrawQuad( | 424 dest_quad = dest_pass->CopyFromAndAppendDrawQuad( |
| 424 quad, dest_pass->shared_quad_state_list.back()); | 425 quad, dest_pass->shared_quad_state_list.back()); |
| 425 } | 426 } |
| 426 if (!remap.is_null()) | 427 if (!child_to_parent_map.empty()) { |
| 427 dest_quad->IterateResources(remap); | 428 dest_quad->IterateResources( |
| 429 [&child_to_parent_map](ResourceId resource_id) { | |
| 430 return ResourceRemapHelper(child_to_parent_map, resource_id); | |
|
piman
2015/05/28 18:37:59
nit: same here, I would probably inline ResourceRe
vmpstr
2015/05/28 19:18:50
Done.
| |
| 431 }); | |
| 432 } | |
| 428 } | 433 } |
| 429 } | 434 } |
| 430 } | 435 } |
| 431 | 436 |
| 432 void SurfaceAggregator::CopyPasses(const DelegatedFrameData* frame_data, | 437 void SurfaceAggregator::CopyPasses(const DelegatedFrameData* frame_data, |
| 433 Surface* surface) { | 438 Surface* surface) { |
| 434 // The root surface is allowed to have copy output requests, so grab them | 439 // The root surface is allowed to have copy output requests, so grab them |
| 435 // off its render passes. | 440 // off its render passes. |
| 436 std::multimap<RenderPassId, CopyOutputRequest*> copy_requests; | 441 std::multimap<RenderPassId, CopyOutputRequest*> copy_requests; |
| 437 surface->TakeCopyOutputRequests(©_requests); | 442 surface->TakeCopyOutputRequests(©_requests); |
| 438 | 443 |
| 439 const RenderPassList& source_pass_list = frame_data->render_pass_list; | 444 const RenderPassList& source_pass_list = frame_data->render_pass_list; |
| 440 bool invalid_frame = ValidateResources(surface, frame_data); | 445 bool invalid_frame = ValidateResources(surface, frame_data); |
| 441 DCHECK(!invalid_frame); | 446 DCHECK(!invalid_frame); |
| 442 if (invalid_frame) | 447 if (invalid_frame) |
| 443 return; | 448 return; |
| 444 | 449 |
| 445 DrawQuad::ResourceIteratorCallback remap; | 450 const ResourceProvider::ResourceIdMap& child_to_parent_map = |
| 446 if (provider_) { | 451 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) |
| 447 int child_id = ChildIdForSurface(surface); | 452 : ResourceProvider::ResourceIdMap(); |
| 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) { | 453 for (size_t i = 0; i < source_pass_list.size(); ++i) { |
| 454 const RenderPass& source = *source_pass_list[i]; | 454 const RenderPass& source = *source_pass_list[i]; |
| 455 | 455 |
| 456 size_t sqs_size = source.shared_quad_state_list.size(); | 456 size_t sqs_size = source.shared_quad_state_list.size(); |
| 457 size_t dq_size = source.quad_list.size(); | 457 size_t dq_size = source.quad_list.size(); |
| 458 scoped_ptr<RenderPass> copy_pass(RenderPass::Create(sqs_size, dq_size)); | 458 scoped_ptr<RenderPass> copy_pass(RenderPass::Create(sqs_size, dq_size)); |
| 459 | 459 |
| 460 MoveMatchingRequests(source.id, ©_requests, ©_pass->copy_requests); | 460 MoveMatchingRequests(source.id, ©_requests, ©_pass->copy_requests); |
| 461 | 461 |
| 462 RenderPassId remapped_pass_id = | 462 RenderPassId remapped_pass_id = |
| 463 RemapPassId(source.id, surface->surface_id()); | 463 RemapPassId(source.id, surface->surface_id()); |
| 464 | 464 |
| 465 gfx::Rect damage_rect = | 465 gfx::Rect damage_rect = |
| 466 (i < source_pass_list.size() - 1) | 466 (i < source_pass_list.size() - 1) |
| 467 ? gfx::Rect() | 467 ? gfx::Rect() |
| 468 : DamageRectForSurface(surface, source, source.output_rect); | 468 : DamageRectForSurface(surface, source, source.output_rect); |
| 469 copy_pass->SetAll(remapped_pass_id, source.output_rect, damage_rect, | 469 copy_pass->SetAll(remapped_pass_id, source.output_rect, damage_rect, |
| 470 source.transform_to_root_target, | 470 source.transform_to_root_target, |
| 471 source.has_transparent_background); | 471 source.has_transparent_background); |
| 472 | 472 |
| 473 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, remap, | 473 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, |
| 474 gfx::Transform(), ClipData(), copy_pass.get(), | 474 child_to_parent_map, gfx::Transform(), ClipData(), |
| 475 surface->surface_id()); | 475 copy_pass.get(), surface->surface_id()); |
| 476 | 476 |
| 477 dest_pass_list_->push_back(copy_pass.Pass()); | 477 dest_pass_list_->push_back(copy_pass.Pass()); |
| 478 } | 478 } |
| 479 } | 479 } |
| 480 | 480 |
| 481 void SurfaceAggregator::RemoveUnreferencedChildren() { | 481 void SurfaceAggregator::RemoveUnreferencedChildren() { |
| 482 for (const auto& surface : previous_contained_surfaces_) { | 482 for (const auto& surface : previous_contained_surfaces_) { |
| 483 if (!contained_surfaces_.count(surface.first)) { | 483 if (!contained_surfaces_.count(surface.first)) { |
| 484 SurfaceToResourceChildIdMap::iterator it = | 484 SurfaceToResourceChildIdMap::iterator it = |
| 485 surface_id_to_resource_child_id_.find(surface.first); | 485 surface_id_to_resource_child_id_.find(surface.first); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 | 552 |
| 553 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { | 553 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { |
| 554 auto it = previous_contained_surfaces_.find(surface_id); | 554 auto it = previous_contained_surfaces_.find(surface_id); |
| 555 if (it == previous_contained_surfaces_.end()) | 555 if (it == previous_contained_surfaces_.end()) |
| 556 return; | 556 return; |
| 557 // Set the last drawn index as 0 to ensure full damage next time it's drawn. | 557 // Set the last drawn index as 0 to ensure full damage next time it's drawn. |
| 558 it->second = 0; | 558 it->second = 0; |
| 559 } | 559 } |
| 560 | 560 |
| 561 } // namespace cc | 561 } // namespace cc |
| OLD | NEW |