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 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 }; | 117 }; |
118 | 118 |
119 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory, | 119 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory, |
120 const ReturnedResourceArray& resources, | 120 const ReturnedResourceArray& resources, |
121 BlockingTaskRunner* main_thread_task_runner) { | 121 BlockingTaskRunner* main_thread_task_runner) { |
122 if (surface_factory) | 122 if (surface_factory) |
123 surface_factory->UnrefResources(resources); | 123 surface_factory->UnrefResources(resources); |
124 } | 124 } |
125 | 125 |
126 RenderPassId SurfaceAggregator::RemapPassId(RenderPassId surface_local_pass_id, | 126 RenderPassId SurfaceAggregator::RemapPassId(RenderPassId surface_local_pass_id, |
127 SurfaceId surface_id) { | 127 const SurfaceId& surface_id) { |
128 std::unique_ptr<RenderPassIdAllocator>& allocator = | 128 std::unique_ptr<RenderPassIdAllocator>& allocator = |
129 render_pass_allocator_map_[surface_id]; | 129 render_pass_allocator_map_[surface_id]; |
130 if (!allocator) | 130 if (!allocator) |
131 allocator.reset(new RenderPassIdAllocator(&next_render_pass_id_)); | 131 allocator.reset(new RenderPassIdAllocator(&next_render_pass_id_)); |
132 allocator->AddKnownPass(surface_local_pass_id); | 132 allocator->AddKnownPass(surface_local_pass_id); |
133 return allocator->Remap(surface_local_pass_id); | 133 return allocator->Remap(surface_local_pass_id); |
134 } | 134 } |
135 | 135 |
136 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { | 136 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { |
137 SurfaceToResourceChildIdMap::iterator it = | 137 SurfaceToResourceChildIdMap::iterator it = |
(...skipping 15 matching lines...) Expand all Loading... |
153 gfx::Rect SurfaceAggregator::DamageRectForSurface( | 153 gfx::Rect SurfaceAggregator::DamageRectForSurface( |
154 const Surface* surface, | 154 const Surface* surface, |
155 const RenderPass& source, | 155 const RenderPass& source, |
156 const gfx::Rect& full_rect) const { | 156 const gfx::Rect& full_rect) const { |
157 auto it = previous_contained_surfaces_.find(surface->surface_id()); | 157 auto it = previous_contained_surfaces_.find(surface->surface_id()); |
158 if (it != previous_contained_surfaces_.end()) { | 158 if (it != previous_contained_surfaces_.end()) { |
159 int previous_index = it->second; | 159 int previous_index = it->second; |
160 if (previous_index == surface->frame_index()) | 160 if (previous_index == surface->frame_index()) |
161 return gfx::Rect(); | 161 return gfx::Rect(); |
162 } | 162 } |
163 SurfaceId previous_surface_id = surface->previous_frame_surface_id(); | 163 const SurfaceId& previous_surface_id = surface->previous_frame_surface_id(); |
164 | 164 |
165 if (surface->surface_id() != previous_surface_id) { | 165 if (surface->surface_id() != previous_surface_id) { |
166 it = previous_contained_surfaces_.find(previous_surface_id); | 166 it = previous_contained_surfaces_.find(previous_surface_id); |
167 } | 167 } |
168 if (it != previous_contained_surfaces_.end()) { | 168 if (it != previous_contained_surfaces_.end()) { |
169 int previous_index = it->second; | 169 int previous_index = it->second; |
170 if (previous_index == surface->frame_index() - 1) | 170 if (previous_index == surface->frame_index() - 1) |
171 return source.damage_rect; | 171 return source.damage_rect; |
172 } | 172 } |
173 | 173 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 return true; | 351 return true; |
352 } | 352 } |
353 | 353 |
354 void SurfaceAggregator::CopyQuadsToPass( | 354 void SurfaceAggregator::CopyQuadsToPass( |
355 const QuadList& source_quad_list, | 355 const QuadList& source_quad_list, |
356 const SharedQuadStateList& source_shared_quad_state_list, | 356 const SharedQuadStateList& source_shared_quad_state_list, |
357 const ResourceProvider::ResourceIdMap& child_to_parent_map, | 357 const ResourceProvider::ResourceIdMap& child_to_parent_map, |
358 const gfx::Transform& target_transform, | 358 const gfx::Transform& target_transform, |
359 const ClipData& clip_rect, | 359 const ClipData& clip_rect, |
360 RenderPass* dest_pass, | 360 RenderPass* dest_pass, |
361 SurfaceId surface_id) { | 361 const SurfaceId& surface_id) { |
362 const SharedQuadState* last_copied_source_shared_quad_state = nullptr; | 362 const SharedQuadState* last_copied_source_shared_quad_state = nullptr; |
363 const SharedQuadState* dest_shared_quad_state = nullptr; | 363 const SharedQuadState* dest_shared_quad_state = nullptr; |
364 // If the current frame has copy requests then aggregate the entire | 364 // If the current frame has copy requests then aggregate the entire |
365 // thing, as otherwise parts of the copy requests may be ignored. | 365 // thing, as otherwise parts of the copy requests may be ignored. |
366 const bool ignore_undamaged = aggregate_only_damaged_ && | 366 const bool ignore_undamaged = aggregate_only_damaged_ && |
367 !has_copy_requests_ && | 367 !has_copy_requests_ && |
368 !moved_pixel_passes_.count(dest_pass->id); | 368 !moved_pixel_passes_.count(dest_pass->id); |
369 // Damage rect in the quad space of the current shared quad state. | 369 // Damage rect in the quad space of the current shared quad state. |
370 // TODO(jbauman): This rect may contain unnecessary area if | 370 // TODO(jbauman): This rect may contain unnecessary area if |
371 // transform isn't axis-aligned. | 371 // transform isn't axis-aligned. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 if (surface_ptr) { | 536 if (surface_ptr) { |
537 surface_ptr->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED); | 537 surface_ptr->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED); |
538 } | 538 } |
539 } | 539 } |
540 } | 540 } |
541 } | 541 } |
542 | 542 |
543 // Walk the Surface tree from surface_id. Validate the resources of the current | 543 // Walk the Surface tree from surface_id. Validate the resources of the current |
544 // surface and its descendants, check if there are any copy requests, and | 544 // surface and its descendants, check if there are any copy requests, and |
545 // return the combined damage rect. | 545 // return the combined damage rect. |
546 gfx::Rect SurfaceAggregator::PrewalkTree(SurfaceId surface_id, | 546 gfx::Rect SurfaceAggregator::PrewalkTree(const SurfaceId& surface_id, |
547 bool in_moved_pixel_pass, | 547 bool in_moved_pixel_pass, |
548 RenderPassId parent_pass, | 548 RenderPassId parent_pass, |
549 PrewalkResult* result) { | 549 PrewalkResult* result) { |
550 // This is for debugging a possible use after free. | 550 // This is for debugging a possible use after free. |
551 // TODO(jbauman): Remove this once we have enough information. | 551 // TODO(jbauman): Remove this once we have enough information. |
552 // http://crbug.com/560181 | 552 // http://crbug.com/560181 |
553 base::WeakPtr<SurfaceAggregator> debug_weak_this = weak_factory_.GetWeakPtr(); | 553 base::WeakPtr<SurfaceAggregator> debug_weak_this = weak_factory_.GetWeakPtr(); |
554 | 554 |
555 if (referenced_surfaces_.count(surface_id)) | 555 if (referenced_surfaces_.count(surface_id)) |
556 return gfx::Rect(); | 556 return gfx::Rect(); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 if (it == render_pass_dependencies_.end()) | 758 if (it == render_pass_dependencies_.end()) |
759 continue; | 759 continue; |
760 for (auto pass : it->second) { | 760 for (auto pass : it->second) { |
761 if (copy_request_passes_.insert(pass).second) { | 761 if (copy_request_passes_.insert(pass).second) { |
762 copy_requests_to_iterate.push_back(pass); | 762 copy_requests_to_iterate.push_back(pass); |
763 } | 763 } |
764 } | 764 } |
765 } | 765 } |
766 } | 766 } |
767 | 767 |
768 CompositorFrame SurfaceAggregator::Aggregate(SurfaceId surface_id) { | 768 CompositorFrame SurfaceAggregator::Aggregate(const SurfaceId& surface_id) { |
769 Surface* surface = manager_->GetSurfaceForId(surface_id); | 769 Surface* surface = manager_->GetSurfaceForId(surface_id); |
770 DCHECK(surface); | 770 DCHECK(surface); |
771 contained_surfaces_[surface_id] = surface->frame_index(); | 771 contained_surfaces_[surface_id] = surface->frame_index(); |
772 const CompositorFrame& root_surface_frame = surface->GetEligibleFrame(); | 772 const CompositorFrame& root_surface_frame = surface->GetEligibleFrame(); |
773 if (!root_surface_frame.delegated_frame_data) | 773 if (!root_surface_frame.delegated_frame_data) |
774 return CompositorFrame(); | 774 return CompositorFrame(); |
775 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate"); | 775 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate"); |
776 | 776 |
777 CompositorFrame frame; | 777 CompositorFrame frame; |
778 frame.delegated_frame_data = base::WrapUnique(new DelegatedFrameData); | 778 frame.delegated_frame_data = base::WrapUnique(new DelegatedFrameData); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 if (surface) | 813 if (surface) |
814 surface->TakeLatencyInfo(&frame.metadata.latency_info); | 814 surface->TakeLatencyInfo(&frame.metadata.latency_info); |
815 } | 815 } |
816 | 816 |
817 // TODO(jamesr): Aggregate all resource references into the returned frame's | 817 // TODO(jamesr): Aggregate all resource references into the returned frame's |
818 // resource list. | 818 // resource list. |
819 | 819 |
820 return frame; | 820 return frame; |
821 } | 821 } |
822 | 822 |
823 void SurfaceAggregator::ReleaseResources(SurfaceId surface_id) { | 823 void SurfaceAggregator::ReleaseResources(const SurfaceId& surface_id) { |
824 SurfaceToResourceChildIdMap::iterator it = | 824 SurfaceToResourceChildIdMap::iterator it = |
825 surface_id_to_resource_child_id_.find(surface_id); | 825 surface_id_to_resource_child_id_.find(surface_id); |
826 if (it != surface_id_to_resource_child_id_.end()) { | 826 if (it != surface_id_to_resource_child_id_.end()) { |
827 provider_->DestroyChild(it->second); | 827 provider_->DestroyChild(it->second); |
828 surface_id_to_resource_child_id_.erase(it); | 828 surface_id_to_resource_child_id_.erase(it); |
829 } | 829 } |
830 } | 830 } |
831 | 831 |
832 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { | 832 void SurfaceAggregator::SetFullDamageForSurface(const SurfaceId& surface_id) { |
833 auto it = previous_contained_surfaces_.find(surface_id); | 833 auto it = previous_contained_surfaces_.find(surface_id); |
834 if (it == previous_contained_surfaces_.end()) | 834 if (it == previous_contained_surfaces_.end()) |
835 return; | 835 return; |
836 // Set the last drawn index as 0 to ensure full damage next time it's drawn. | 836 // Set the last drawn index as 0 to ensure full damage next time it's drawn. |
837 it->second = 0; | 837 it->second = 0; |
838 } | 838 } |
839 | 839 |
840 } // namespace cc | 840 } // namespace cc |
OLD | NEW |