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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 return it->second.id; | 137 return it->second.id; |
138 } | 138 } |
139 | 139 |
140 RenderPassInfo render_pass_info; | 140 RenderPassInfo render_pass_info; |
141 render_pass_info.id = next_render_pass_id_++; | 141 render_pass_info.id = next_render_pass_id_++; |
142 render_pass_allocator_map_[key] = render_pass_info; | 142 render_pass_allocator_map_[key] = render_pass_info; |
143 return render_pass_info.id; | 143 return render_pass_info.id; |
144 } | 144 } |
145 | 145 |
146 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { | 146 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { |
147 SurfaceToResourceChildIdMap::iterator it = | 147 auto it = surface_id_to_resource_child_id_.find(surface->surface_id()); |
148 surface_id_to_resource_child_id_.find(surface->surface_id()); | |
149 if (it == surface_id_to_resource_child_id_.end()) { | 148 if (it == surface_id_to_resource_child_id_.end()) { |
150 int child_id = | 149 int child_id = |
151 provider_->CreateChild(base::Bind(&UnrefHelper, surface->factory())); | 150 provider_->CreateChild(base::Bind(&UnrefHelper, surface->factory())); |
152 if (surface->factory()) { | 151 if (surface->factory()) { |
153 provider_->SetChildNeedsSyncTokens( | 152 provider_->SetChildNeedsSyncTokens( |
154 child_id, surface->factory()->needs_sync_points()); | 153 child_id, surface->factory()->needs_sync_points()); |
155 } | 154 } |
156 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; | 155 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; |
157 return child_id; | 156 return child_id; |
158 } else { | 157 } else { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests; | 231 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests; |
233 surface->TakeCopyOutputRequests(©_requests); | 232 surface->TakeCopyOutputRequests(©_requests); |
234 | 233 |
235 const RenderPassList& render_pass_list = frame.render_pass_list; | 234 const RenderPassList& render_pass_list = frame.render_pass_list; |
236 if (!valid_surfaces_.count(surface->surface_id())) { | 235 if (!valid_surfaces_.count(surface->surface_id())) { |
237 for (auto& request : copy_requests) | 236 for (auto& request : copy_requests) |
238 request.second->SendEmptyResult(); | 237 request.second->SendEmptyResult(); |
239 return; | 238 return; |
240 } | 239 } |
241 | 240 |
242 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 241 auto it = referenced_surfaces_.insert(surface_id).first; |
243 // TODO(vmpstr): provider check is a hack for unittests that don't set up a | 242 // TODO(vmpstr): provider check is a hack for unittests that don't set up a |
244 // resource provider. | 243 // resource provider. |
245 ResourceProvider::ResourceIdMap empty_map; | 244 ResourceProvider::ResourceIdMap empty_map; |
246 const ResourceProvider::ResourceIdMap& child_to_parent_map = | 245 const ResourceProvider::ResourceIdMap& child_to_parent_map = |
247 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) | 246 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) |
248 : empty_map; | 247 : empty_map; |
249 bool merge_pass = | 248 bool merge_pass = |
250 surface_quad->shared_quad_state->opacity == 1.f && copy_requests.empty(); | 249 surface_quad->shared_quad_state->opacity == 1.f && copy_requests.empty(); |
251 | 250 |
252 const RenderPassList& referenced_passes = render_pass_list; | 251 const RenderPassList& referenced_passes = render_pass_list; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 } | 560 } |
562 | 561 |
563 dest_pass_list_->push_back(std::move(copy_pass)); | 562 dest_pass_list_->push_back(std::move(copy_pass)); |
564 } | 563 } |
565 } | 564 } |
566 | 565 |
567 void SurfaceAggregator::ProcessAddedAndRemovedSurfaces() { | 566 void SurfaceAggregator::ProcessAddedAndRemovedSurfaces() { |
568 for (const auto& surface : previous_contained_surfaces_) { | 567 for (const auto& surface : previous_contained_surfaces_) { |
569 if (!contained_surfaces_.count(surface.first)) { | 568 if (!contained_surfaces_.count(surface.first)) { |
570 // Release resources of removed surface. | 569 // Release resources of removed surface. |
571 SurfaceToResourceChildIdMap::iterator it = | 570 auto it = surface_id_to_resource_child_id_.find(surface.first); |
572 surface_id_to_resource_child_id_.find(surface.first); | |
573 if (it != surface_id_to_resource_child_id_.end()) { | 571 if (it != surface_id_to_resource_child_id_.end()) { |
574 provider_->DestroyChild(it->second); | 572 provider_->DestroyChild(it->second); |
575 surface_id_to_resource_child_id_.erase(it); | 573 surface_id_to_resource_child_id_.erase(it); |
576 } | 574 } |
577 | 575 |
578 // Notify client of removed surface. | 576 // Notify client of removed surface. |
579 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first); | 577 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first); |
580 if (surface_ptr) { | 578 if (surface_ptr) { |
581 surface_ptr->RunDrawCallbacks(); | 579 surface_ptr->RunDrawCallbacks(); |
582 } | 580 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 parent_pass_id(parent_pass_id), | 644 parent_pass_id(parent_pass_id), |
647 target_to_surface_transform(target_to_surface_transform) {} | 645 target_to_surface_transform(target_to_surface_transform) {} |
648 | 646 |
649 SurfaceId id; | 647 SurfaceId id; |
650 bool has_moved_pixels; | 648 bool has_moved_pixels; |
651 int parent_pass_id; | 649 int parent_pass_id; |
652 gfx::Transform target_to_surface_transform; | 650 gfx::Transform target_to_surface_transform; |
653 }; | 651 }; |
654 std::vector<SurfaceInfo> child_surfaces; | 652 std::vector<SurfaceInfo> child_surfaces; |
655 | 653 |
656 std::unordered_set<int> pixel_moving_background_filter_passes; | 654 // This data is created once and typically small or empty. Collect all items |
655 // and pass to a flat_vector to sort once. | |
656 std::vector<int> pixel_moving_background_filter_passes_data; | |
657 for (const auto& render_pass : frame.render_pass_list) { | 657 for (const auto& render_pass : frame.render_pass_list) { |
658 if (render_pass->background_filters.HasFilterThatMovesPixels()) { | 658 if (render_pass->background_filters.HasFilterThatMovesPixels()) { |
659 pixel_moving_background_filter_passes.insert( | 659 pixel_moving_background_filter_passes_data.push_back( |
660 RemapPassId(render_pass->id, surface_id)); | 660 RemapPassId(render_pass->id, surface_id)); |
661 } | 661 } |
662 } | 662 } |
663 base::flat_set<int> pixel_moving_background_filter_passes( | |
664 std::move(pixel_moving_background_filter_passes_data), | |
665 base::KEEP_FIRST_OF_DUPES); | |
663 | 666 |
664 for (const auto& render_pass : base::Reversed(frame.render_pass_list)) { | 667 for (const auto& render_pass : base::Reversed(frame.render_pass_list)) { |
665 int remapped_pass_id = RemapPassId(render_pass->id, surface_id); | 668 int remapped_pass_id = RemapPassId(render_pass->id, surface_id); |
666 bool has_pixel_moving_filter = | 669 bool has_pixel_moving_filter = |
667 render_pass->filters.HasFilterThatMovesPixels(); | 670 render_pass->filters.HasFilterThatMovesPixels(); |
668 if (has_pixel_moving_filter) | 671 if (has_pixel_moving_filter) |
669 moved_pixel_passes_.insert(remapped_pass_id); | 672 moved_pixel_passes_.insert(remapped_pass_id); |
670 bool in_moved_pixel_pass = has_pixel_moving_filter || | 673 bool in_moved_pixel_pass = has_pixel_moving_filter || |
671 !!moved_pixel_passes_.count(remapped_pass_id); | 674 !!moved_pixel_passes_.count(remapped_pass_id); |
672 for (auto* quad : render_pass->quad_list) { | 675 for (auto* quad : render_pass->quad_list) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 gfx::Rect full_damage; | 722 gfx::Rect full_damage; |
720 if (!frame.render_pass_list.empty()) { | 723 if (!frame.render_pass_list.empty()) { |
721 RenderPass* last_pass = frame.render_pass_list.back().get(); | 724 RenderPass* last_pass = frame.render_pass_list.back().get(); |
722 full_damage = last_pass->output_rect; | 725 full_damage = last_pass->output_rect; |
723 damage_rect = | 726 damage_rect = |
724 DamageRectForSurface(surface, *last_pass, last_pass->output_rect); | 727 DamageRectForSurface(surface, *last_pass, last_pass->output_rect); |
725 } | 728 } |
726 | 729 |
727 // Avoid infinite recursion by adding current surface to | 730 // Avoid infinite recursion by adding current surface to |
728 // referenced_surfaces_. | 731 // referenced_surfaces_. |
729 SurfaceSet::iterator it = | 732 referenced_surfaces_.insert(surface->surface_id()); |
730 referenced_surfaces_.insert(surface->surface_id()).first; | |
731 for (const auto& surface_info : child_surfaces) { | 733 for (const auto& surface_info : child_surfaces) { |
732 gfx::Rect surface_damage = | 734 gfx::Rect surface_damage = |
733 PrewalkTree(surface_info.id, surface_info.has_moved_pixels, | 735 PrewalkTree(surface_info.id, surface_info.has_moved_pixels, |
734 surface_info.parent_pass_id, result); | 736 surface_info.parent_pass_id, result); |
735 if (surface_damage.IsEmpty()) | 737 if (surface_damage.IsEmpty()) |
736 continue; | 738 continue; |
737 if (surface_info.has_moved_pixels) { | 739 if (surface_info.has_moved_pixels) { |
738 // Areas outside the rect hit by target_to_surface_transform may be | 740 // Areas outside the rect hit by target_to_surface_transform may be |
739 // modified if there is a filter that moves pixels. | 741 // modified if there is a filter that moves pixels. |
740 damage_rect = full_damage; | 742 damage_rect = full_damage; |
(...skipping 19 matching lines...) Expand all Loading... | |
760 } | 762 } |
761 | 763 |
762 CHECK(debug_weak_this.get()); | 764 CHECK(debug_weak_this.get()); |
763 for (const auto& render_pass : frame.render_pass_list) { | 765 for (const auto& render_pass : frame.render_pass_list) { |
764 if (!render_pass->copy_requests.empty()) { | 766 if (!render_pass->copy_requests.empty()) { |
765 int remapped_pass_id = RemapPassId(render_pass->id, surface_id); | 767 int remapped_pass_id = RemapPassId(render_pass->id, surface_id); |
766 copy_request_passes_.insert(remapped_pass_id); | 768 copy_request_passes_.insert(remapped_pass_id); |
767 } | 769 } |
768 } | 770 } |
769 | 771 |
770 referenced_surfaces_.erase(it); | 772 referenced_surfaces_.erase(referenced_surfaces_.find(surface->surface_id())); |
brettw
2017/04/17 21:10:08
This changed because the set is mutated in between
| |
771 if (!damage_rect.IsEmpty() && frame.metadata.may_contain_video) | 773 if (!damage_rect.IsEmpty() && frame.metadata.may_contain_video) |
772 result->may_contain_video = true; | 774 result->may_contain_video = true; |
773 return damage_rect; | 775 return damage_rect; |
774 } | 776 } |
775 | 777 |
776 void SurfaceAggregator::CopyUndrawnSurfaces(PrewalkResult* prewalk_result) { | 778 void SurfaceAggregator::CopyUndrawnSurfaces(PrewalkResult* prewalk_result) { |
777 // undrawn_surfaces are Surfaces that were identified by prewalk as being | 779 // undrawn_surfaces are Surfaces that were identified by prewalk as being |
778 // referenced by a drawn Surface, but aren't contained in a SurfaceDrawQuad. | 780 // referenced by a drawn Surface, but aren't contained in a SurfaceDrawQuad. |
779 // They need to be iterated over to ensure that any copy requests on them | 781 // They need to be iterated over to ensure that any copy requests on them |
780 // (or on Surfaces they reference) are executed. | 782 // (or on Surfaces they reference) are executed. |
(...skipping 20 matching lines...) Expand all Loading... | |
801 for (const auto& child_id : frame.metadata.referenced_surfaces) { | 803 for (const auto& child_id : frame.metadata.referenced_surfaces) { |
802 // Don't iterate over the child Surface if it was already listed as a | 804 // Don't iterate over the child Surface if it was already listed as a |
803 // child of a different Surface, or in the case where there's infinite | 805 // child of a different Surface, or in the case where there's infinite |
804 // recursion. | 806 // recursion. |
805 if (!prewalk_result->undrawn_surfaces.count(child_id)) { | 807 if (!prewalk_result->undrawn_surfaces.count(child_id)) { |
806 surfaces_to_copy.push_back(child_id); | 808 surfaces_to_copy.push_back(child_id); |
807 prewalk_result->undrawn_surfaces.insert(child_id); | 809 prewalk_result->undrawn_surfaces.insert(child_id); |
808 } | 810 } |
809 } | 811 } |
810 } else { | 812 } else { |
811 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 813 auto it = referenced_surfaces_.insert(surface_id).first; |
812 CopyPasses(frame, surface); | 814 CopyPasses(frame, surface); |
813 referenced_surfaces_.erase(it); | 815 referenced_surfaces_.erase(it); |
814 } | 816 } |
815 } | 817 } |
816 } | 818 } |
817 | 819 |
818 void SurfaceAggregator::PropagateCopyRequestPasses() { | 820 void SurfaceAggregator::PropagateCopyRequestPasses() { |
819 std::vector<int> copy_requests_to_iterate(copy_request_passes_.begin(), | 821 std::vector<int> copy_requests_to_iterate(copy_request_passes_.begin(), |
820 copy_request_passes_.end()); | 822 copy_request_passes_.end()); |
821 while (!copy_requests_to_iterate.empty()) { | 823 while (!copy_requests_to_iterate.empty()) { |
(...skipping 29 matching lines...) Expand all Loading... | |
851 dest_pass_list_ = &frame.render_pass_list; | 853 dest_pass_list_ = &frame.render_pass_list; |
852 | 854 |
853 valid_surfaces_.clear(); | 855 valid_surfaces_.clear(); |
854 PrewalkResult prewalk_result; | 856 PrewalkResult prewalk_result; |
855 root_damage_rect_ = PrewalkTree(surface_id, false, 0, &prewalk_result); | 857 root_damage_rect_ = PrewalkTree(surface_id, false, 0, &prewalk_result); |
856 PropagateCopyRequestPasses(); | 858 PropagateCopyRequestPasses(); |
857 has_copy_requests_ = !copy_request_passes_.empty(); | 859 has_copy_requests_ = !copy_request_passes_.empty(); |
858 frame.metadata.may_contain_video = prewalk_result.may_contain_video; | 860 frame.metadata.may_contain_video = prewalk_result.may_contain_video; |
859 | 861 |
860 CopyUndrawnSurfaces(&prewalk_result); | 862 CopyUndrawnSurfaces(&prewalk_result); |
861 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 863 auto it = referenced_surfaces_.insert(surface_id).first; |
862 CopyPasses(root_surface_frame, surface); | 864 CopyPasses(root_surface_frame, surface); |
863 referenced_surfaces_.erase(it); | 865 referenced_surfaces_.erase(it); |
864 AddColorConversionPass(); | 866 AddColorConversionPass(); |
865 | 867 |
866 moved_pixel_passes_.clear(); | 868 moved_pixel_passes_.clear(); |
867 copy_request_passes_.clear(); | 869 copy_request_passes_.clear(); |
868 render_pass_dependencies_.clear(); | 870 render_pass_dependencies_.clear(); |
869 | 871 |
870 // Remove all render pass mappings that weren't used in the current frame. | 872 // Remove all render pass mappings that weren't used in the current frame. |
871 for (auto it = render_pass_allocator_map_.begin(); | 873 for (auto it = render_pass_allocator_map_.begin(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
905 kUmaStatMaxSurfaces); | 907 kUmaStatMaxSurfaces); |
906 UMA_HISTOGRAM_EXACT_LINEAR(kUmaMissingSurface, uma_stats_.missing_surface, | 908 UMA_HISTOGRAM_EXACT_LINEAR(kUmaMissingSurface, uma_stats_.missing_surface, |
907 kUmaStatMaxSurfaces); | 909 kUmaStatMaxSurfaces); |
908 UMA_HISTOGRAM_EXACT_LINEAR(kUmaNoActiveFrame, uma_stats_.no_active_frame, | 910 UMA_HISTOGRAM_EXACT_LINEAR(kUmaNoActiveFrame, uma_stats_.no_active_frame, |
909 kUmaStatMaxSurfaces); | 911 kUmaStatMaxSurfaces); |
910 | 912 |
911 return frame; | 913 return frame; |
912 } | 914 } |
913 | 915 |
914 void SurfaceAggregator::ReleaseResources(const SurfaceId& surface_id) { | 916 void SurfaceAggregator::ReleaseResources(const SurfaceId& surface_id) { |
915 SurfaceToResourceChildIdMap::iterator it = | 917 auto it = surface_id_to_resource_child_id_.find(surface_id); |
916 surface_id_to_resource_child_id_.find(surface_id); | |
917 if (it != surface_id_to_resource_child_id_.end()) { | 918 if (it != surface_id_to_resource_child_id_.end()) { |
918 provider_->DestroyChild(it->second); | 919 provider_->DestroyChild(it->second); |
919 surface_id_to_resource_child_id_.erase(it); | 920 surface_id_to_resource_child_id_.erase(it); |
920 } | 921 } |
921 } | 922 } |
922 | 923 |
923 void SurfaceAggregator::SetFullDamageForSurface(const SurfaceId& surface_id) { | 924 void SurfaceAggregator::SetFullDamageForSurface(const SurfaceId& surface_id) { |
924 auto it = previous_contained_surfaces_.find(surface_id); | 925 auto it = previous_contained_surfaces_.find(surface_id); |
925 if (it == previous_contained_surfaces_.end()) | 926 if (it == previous_contained_surfaces_.end()) |
926 return; | 927 return; |
927 // Set the last drawn index as 0 to ensure full damage next time it's drawn. | 928 // Set the last drawn index as 0 to ensure full damage next time it's drawn. |
928 it->second = 0; | 929 it->second = 0; |
929 } | 930 } |
930 | 931 |
931 void SurfaceAggregator::SetOutputColorSpace( | 932 void SurfaceAggregator::SetOutputColorSpace( |
932 const gfx::ColorSpace& blending_color_space, | 933 const gfx::ColorSpace& blending_color_space, |
933 const gfx::ColorSpace& output_color_space) { | 934 const gfx::ColorSpace& output_color_space) { |
934 blending_color_space_ = blending_color_space; | 935 blending_color_space_ = blending_color_space; |
935 output_color_space_ = output_color_space; | 936 output_color_space_ = output_color_space; |
936 } | 937 } |
937 | 938 |
938 } // namespace cc | 939 } // namespace cc |
OLD | NEW |