| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 16 #include "cc/base/math_util.h" | 17 #include "cc/base/math_util.h" |
| 17 #include "cc/output/compositor_frame.h" | 18 #include "cc/output/compositor_frame.h" |
| 18 #include "cc/output/delegated_frame_data.h" | 19 #include "cc/output/delegated_frame_data.h" |
| 19 #include "cc/quads/draw_quad.h" | 20 #include "cc/quads/draw_quad.h" |
| 20 #include "cc/quads/render_pass_draw_quad.h" | 21 #include "cc/quads/render_pass_draw_quad.h" |
| 21 #include "cc/quads/shared_quad_state.h" | 22 #include "cc/quads/shared_quad_state.h" |
| 22 #include "cc/quads/surface_draw_quad.h" | 23 #include "cc/quads/surface_draw_quad.h" |
| 23 #include "cc/surfaces/surface.h" | 24 #include "cc/surfaces/surface.h" |
| 24 #include "cc/surfaces/surface_factory.h" | 25 #include "cc/surfaces/surface_factory.h" |
| 25 #include "cc/surfaces/surface_manager.h" | 26 #include "cc/surfaces/surface_manager.h" |
| 26 #include "cc/trees/blocking_task_runner.h" | 27 #include "cc/trees/blocking_task_runner.h" |
| 27 | 28 |
| 28 namespace cc { | 29 namespace cc { |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 void MoveMatchingRequests( | 32 void MoveMatchingRequests( |
| 32 RenderPassId id, | 33 RenderPassId id, |
| 33 std::multimap<RenderPassId, scoped_ptr<CopyOutputRequest>>* copy_requests, | 34 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>>* |
| 34 std::vector<scoped_ptr<CopyOutputRequest>>* output_requests) { | 35 copy_requests, |
| 36 std::vector<std::unique_ptr<CopyOutputRequest>>* output_requests) { |
| 35 auto request_range = copy_requests->equal_range(id); | 37 auto request_range = copy_requests->equal_range(id); |
| 36 for (auto it = request_range.first; it != request_range.second; ++it) { | 38 for (auto it = request_range.first; it != request_range.second; ++it) { |
| 37 DCHECK(it->second); | 39 DCHECK(it->second); |
| 38 output_requests->push_back(std::move(it->second)); | 40 output_requests->push_back(std::move(it->second)); |
| 39 } | 41 } |
| 40 copy_requests->erase(request_range.first, request_range.second); | 42 copy_requests->erase(request_range.first, request_range.second); |
| 41 } | 43 } |
| 42 | 44 |
| 43 } // namespace | 45 } // namespace |
| 44 | 46 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 115 |
| 114 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory, | 116 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory, |
| 115 const ReturnedResourceArray& resources, | 117 const ReturnedResourceArray& resources, |
| 116 BlockingTaskRunner* main_thread_task_runner) { | 118 BlockingTaskRunner* main_thread_task_runner) { |
| 117 if (surface_factory) | 119 if (surface_factory) |
| 118 surface_factory->UnrefResources(resources); | 120 surface_factory->UnrefResources(resources); |
| 119 } | 121 } |
| 120 | 122 |
| 121 RenderPassId SurfaceAggregator::RemapPassId(RenderPassId surface_local_pass_id, | 123 RenderPassId SurfaceAggregator::RemapPassId(RenderPassId surface_local_pass_id, |
| 122 SurfaceId surface_id) { | 124 SurfaceId surface_id) { |
| 123 scoped_ptr<RenderPassIdAllocator>& allocator = | 125 std::unique_ptr<RenderPassIdAllocator>& allocator = |
| 124 render_pass_allocator_map_[surface_id]; | 126 render_pass_allocator_map_[surface_id]; |
| 125 if (!allocator) | 127 if (!allocator) |
| 126 allocator.reset(new RenderPassIdAllocator(&next_render_pass_id_)); | 128 allocator.reset(new RenderPassIdAllocator(&next_render_pass_id_)); |
| 127 allocator->AddKnownPass(surface_local_pass_id); | 129 allocator->AddKnownPass(surface_local_pass_id); |
| 128 return allocator->Remap(surface_local_pass_id); | 130 return allocator->Remap(surface_local_pass_id); |
| 129 } | 131 } |
| 130 | 132 |
| 131 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { | 133 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { |
| 132 SurfaceToResourceChildIdMap::iterator it = | 134 SurfaceToResourceChildIdMap::iterator it = |
| 133 surface_id_to_resource_child_id_.find(surface->surface_id()); | 135 surface_id_to_resource_child_id_.find(surface->surface_id()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 Surface* surface = manager_->GetSurfaceForId(surface_id); | 176 Surface* surface = manager_->GetSurfaceForId(surface_id); |
| 175 if (!surface) | 177 if (!surface) |
| 176 return; | 178 return; |
| 177 const CompositorFrame* frame = surface->GetEligibleFrame(); | 179 const CompositorFrame* frame = surface->GetEligibleFrame(); |
| 178 if (!frame) | 180 if (!frame) |
| 179 return; | 181 return; |
| 180 const DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); | 182 const DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); |
| 181 if (!frame_data) | 183 if (!frame_data) |
| 182 return; | 184 return; |
| 183 | 185 |
| 184 std::multimap<RenderPassId, scoped_ptr<CopyOutputRequest>> copy_requests; | 186 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>> copy_requests; |
| 185 surface->TakeCopyOutputRequests(©_requests); | 187 surface->TakeCopyOutputRequests(©_requests); |
| 186 | 188 |
| 187 const RenderPassList& render_pass_list = frame_data->render_pass_list; | 189 const RenderPassList& render_pass_list = frame_data->render_pass_list; |
| 188 if (!valid_surfaces_.count(surface->surface_id())) { | 190 if (!valid_surfaces_.count(surface->surface_id())) { |
| 189 for (auto& request : copy_requests) | 191 for (auto& request : copy_requests) |
| 190 request.second->SendEmptyResult(); | 192 request.second->SendEmptyResult(); |
| 191 return; | 193 return; |
| 192 } | 194 } |
| 193 | 195 |
| 194 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 196 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; |
| 195 // TODO(vmpstr): provider check is a hack for unittests that don't set up a | 197 // TODO(vmpstr): provider check is a hack for unittests that don't set up a |
| 196 // resource provider. | 198 // resource provider. |
| 197 ResourceProvider::ResourceIdMap empty_map; | 199 ResourceProvider::ResourceIdMap empty_map; |
| 198 const ResourceProvider::ResourceIdMap& child_to_parent_map = | 200 const ResourceProvider::ResourceIdMap& child_to_parent_map = |
| 199 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) | 201 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) |
| 200 : empty_map; | 202 : empty_map; |
| 201 bool merge_pass = | 203 bool merge_pass = |
| 202 surface_quad->shared_quad_state->opacity == 1.f && copy_requests.empty(); | 204 surface_quad->shared_quad_state->opacity == 1.f && copy_requests.empty(); |
| 203 | 205 |
| 204 const RenderPassList& referenced_passes = render_pass_list; | 206 const RenderPassList& referenced_passes = render_pass_list; |
| 205 size_t passes_to_copy = | 207 size_t passes_to_copy = |
| 206 merge_pass ? referenced_passes.size() - 1 : referenced_passes.size(); | 208 merge_pass ? referenced_passes.size() - 1 : referenced_passes.size(); |
| 207 for (size_t j = 0; j < passes_to_copy; ++j) { | 209 for (size_t j = 0; j < passes_to_copy; ++j) { |
| 208 const RenderPass& source = *referenced_passes[j]; | 210 const RenderPass& source = *referenced_passes[j]; |
| 209 | 211 |
| 210 size_t sqs_size = source.shared_quad_state_list.size(); | 212 size_t sqs_size = source.shared_quad_state_list.size(); |
| 211 size_t dq_size = source.quad_list.size(); | 213 size_t dq_size = source.quad_list.size(); |
| 212 scoped_ptr<RenderPass> copy_pass(RenderPass::Create(sqs_size, dq_size)); | 214 std::unique_ptr<RenderPass> copy_pass( |
| 215 RenderPass::Create(sqs_size, dq_size)); |
| 213 | 216 |
| 214 RenderPassId remapped_pass_id = RemapPassId(source.id, surface_id); | 217 RenderPassId remapped_pass_id = RemapPassId(source.id, surface_id); |
| 215 | 218 |
| 216 copy_pass->SetAll(remapped_pass_id, source.output_rect, gfx::Rect(), | 219 copy_pass->SetAll(remapped_pass_id, source.output_rect, gfx::Rect(), |
| 217 source.transform_to_root_target, | 220 source.transform_to_root_target, |
| 218 source.has_transparent_background); | 221 source.has_transparent_background); |
| 219 | 222 |
| 220 MoveMatchingRequests(source.id, ©_requests, ©_pass->copy_requests); | 223 MoveMatchingRequests(source.id, ©_requests, ©_pass->copy_requests); |
| 221 | 224 |
| 222 // Contributing passes aggregated in to the pass list need to take the | 225 // Contributing passes aggregated in to the pass list need to take the |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 } | 420 } |
| 418 } | 421 } |
| 419 } | 422 } |
| 420 } | 423 } |
| 421 } | 424 } |
| 422 | 425 |
| 423 void SurfaceAggregator::CopyPasses(const DelegatedFrameData* frame_data, | 426 void SurfaceAggregator::CopyPasses(const DelegatedFrameData* frame_data, |
| 424 Surface* surface) { | 427 Surface* surface) { |
| 425 // The root surface is allowed to have copy output requests, so grab them | 428 // The root surface is allowed to have copy output requests, so grab them |
| 426 // off its render passes. | 429 // off its render passes. |
| 427 std::multimap<RenderPassId, scoped_ptr<CopyOutputRequest>> copy_requests; | 430 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>> copy_requests; |
| 428 surface->TakeCopyOutputRequests(©_requests); | 431 surface->TakeCopyOutputRequests(©_requests); |
| 429 | 432 |
| 430 const RenderPassList& source_pass_list = frame_data->render_pass_list; | 433 const RenderPassList& source_pass_list = frame_data->render_pass_list; |
| 431 DCHECK(valid_surfaces_.count(surface->surface_id())); | 434 DCHECK(valid_surfaces_.count(surface->surface_id())); |
| 432 if (!valid_surfaces_.count(surface->surface_id())) | 435 if (!valid_surfaces_.count(surface->surface_id())) |
| 433 return; | 436 return; |
| 434 | 437 |
| 435 // TODO(vmpstr): provider check is a hack for unittests that don't set up a | 438 // TODO(vmpstr): provider check is a hack for unittests that don't set up a |
| 436 // resource provider. | 439 // resource provider. |
| 437 ResourceProvider::ResourceIdMap empty_map; | 440 ResourceProvider::ResourceIdMap empty_map; |
| 438 const ResourceProvider::ResourceIdMap& child_to_parent_map = | 441 const ResourceProvider::ResourceIdMap& child_to_parent_map = |
| 439 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) | 442 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) |
| 440 : empty_map; | 443 : empty_map; |
| 441 for (size_t i = 0; i < source_pass_list.size(); ++i) { | 444 for (size_t i = 0; i < source_pass_list.size(); ++i) { |
| 442 const RenderPass& source = *source_pass_list[i]; | 445 const RenderPass& source = *source_pass_list[i]; |
| 443 | 446 |
| 444 size_t sqs_size = source.shared_quad_state_list.size(); | 447 size_t sqs_size = source.shared_quad_state_list.size(); |
| 445 size_t dq_size = source.quad_list.size(); | 448 size_t dq_size = source.quad_list.size(); |
| 446 scoped_ptr<RenderPass> copy_pass(RenderPass::Create(sqs_size, dq_size)); | 449 std::unique_ptr<RenderPass> copy_pass( |
| 450 RenderPass::Create(sqs_size, dq_size)); |
| 447 | 451 |
| 448 MoveMatchingRequests(source.id, ©_requests, ©_pass->copy_requests); | 452 MoveMatchingRequests(source.id, ©_requests, ©_pass->copy_requests); |
| 449 | 453 |
| 450 RenderPassId remapped_pass_id = | 454 RenderPassId remapped_pass_id = |
| 451 RemapPassId(source.id, surface->surface_id()); | 455 RemapPassId(source.id, surface->surface_id()); |
| 452 | 456 |
| 453 copy_pass->SetAll(remapped_pass_id, source.output_rect, gfx::Rect(), | 457 copy_pass->SetAll(remapped_pass_id, source.output_rect, gfx::Rect(), |
| 454 source.transform_to_root_target, | 458 source.transform_to_root_target, |
| 455 source.has_transparent_background); | 459 source.has_transparent_background); |
| 456 | 460 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 } | 640 } |
| 637 } | 641 } |
| 638 } else { | 642 } else { |
| 639 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 643 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; |
| 640 CopyPasses(surface_frame->delegated_frame_data.get(), surface); | 644 CopyPasses(surface_frame->delegated_frame_data.get(), surface); |
| 641 referenced_surfaces_.erase(it); | 645 referenced_surfaces_.erase(it); |
| 642 } | 646 } |
| 643 } | 647 } |
| 644 } | 648 } |
| 645 | 649 |
| 646 scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(SurfaceId surface_id) { | 650 std::unique_ptr<CompositorFrame> SurfaceAggregator::Aggregate( |
| 651 SurfaceId surface_id) { |
| 647 Surface* surface = manager_->GetSurfaceForId(surface_id); | 652 Surface* surface = manager_->GetSurfaceForId(surface_id); |
| 648 DCHECK(surface); | 653 DCHECK(surface); |
| 649 contained_surfaces_[surface_id] = surface->frame_index(); | 654 contained_surfaces_[surface_id] = surface->frame_index(); |
| 650 const CompositorFrame* root_surface_frame = surface->GetEligibleFrame(); | 655 const CompositorFrame* root_surface_frame = surface->GetEligibleFrame(); |
| 651 if (!root_surface_frame) | 656 if (!root_surface_frame) |
| 652 return nullptr; | 657 return nullptr; |
| 653 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate"); | 658 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate"); |
| 654 | 659 |
| 655 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 660 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); |
| 656 frame->delegated_frame_data = make_scoped_ptr(new DelegatedFrameData); | 661 frame->delegated_frame_data = base::WrapUnique(new DelegatedFrameData); |
| 657 | 662 |
| 658 DCHECK(root_surface_frame->delegated_frame_data); | 663 DCHECK(root_surface_frame->delegated_frame_data); |
| 659 | 664 |
| 660 dest_resource_list_ = &frame->delegated_frame_data->resource_list; | 665 dest_resource_list_ = &frame->delegated_frame_data->resource_list; |
| 661 dest_pass_list_ = &frame->delegated_frame_data->render_pass_list; | 666 dest_pass_list_ = &frame->delegated_frame_data->render_pass_list; |
| 662 | 667 |
| 663 valid_surfaces_.clear(); | 668 valid_surfaces_.clear(); |
| 664 PrewalkResult prewalk_result; | 669 PrewalkResult prewalk_result; |
| 665 root_damage_rect_ = PrewalkTree(surface_id, &prewalk_result); | 670 root_damage_rect_ = PrewalkTree(surface_id, &prewalk_result); |
| 666 has_copy_requests_ = prewalk_result.has_copy_requests; | 671 has_copy_requests_ = prewalk_result.has_copy_requests; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 | 711 |
| 707 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { | 712 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { |
| 708 auto it = previous_contained_surfaces_.find(surface_id); | 713 auto it = previous_contained_surfaces_.find(surface_id); |
| 709 if (it == previous_contained_surfaces_.end()) | 714 if (it == previous_contained_surfaces_.end()) |
| 710 return; | 715 return; |
| 711 // Set the last drawn index as 0 to ensure full damage next time it's drawn. | 716 // Set the last drawn index as 0 to ensure full damage next time it's drawn. |
| 712 it->second = 0; | 717 it->second = 0; |
| 713 } | 718 } |
| 714 | 719 |
| 715 } // namespace cc | 720 } // namespace cc |
| OLD | NEW |