Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: cc/surfaces/surface_aggregator.cc

Issue 2826823002: Revert of Use flat_set in SurfaceAggregator. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/surfaces/surface_aggregator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 auto it = surface_id_to_resource_child_id_.find(surface->surface_id()); 147 SurfaceToResourceChildIdMap::iterator it =
148 surface_id_to_resource_child_id_.find(surface->surface_id());
148 if (it == surface_id_to_resource_child_id_.end()) { 149 if (it == surface_id_to_resource_child_id_.end()) {
149 int child_id = 150 int child_id =
150 provider_->CreateChild(base::Bind(&UnrefHelper, surface->factory())); 151 provider_->CreateChild(base::Bind(&UnrefHelper, surface->factory()));
151 if (surface->factory()) { 152 if (surface->factory()) {
152 provider_->SetChildNeedsSyncTokens( 153 provider_->SetChildNeedsSyncTokens(
153 child_id, surface->factory()->needs_sync_points()); 154 child_id, surface->factory()->needs_sync_points());
154 } 155 }
155 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; 156 surface_id_to_resource_child_id_[surface->surface_id()] = child_id;
156 return child_id; 157 return child_id;
157 } else { 158 } else {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests; 232 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests;
232 surface->TakeCopyOutputRequests(&copy_requests); 233 surface->TakeCopyOutputRequests(&copy_requests);
233 234
234 const RenderPassList& render_pass_list = frame.render_pass_list; 235 const RenderPassList& render_pass_list = frame.render_pass_list;
235 if (!valid_surfaces_.count(surface->surface_id())) { 236 if (!valid_surfaces_.count(surface->surface_id())) {
236 for (auto& request : copy_requests) 237 for (auto& request : copy_requests)
237 request.second->SendEmptyResult(); 238 request.second->SendEmptyResult();
238 return; 239 return;
239 } 240 }
240 241
241 referenced_surfaces_.insert(surface_id); 242 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first;
242 // TODO(vmpstr): provider check is a hack for unittests that don't set up a 243 // TODO(vmpstr): provider check is a hack for unittests that don't set up a
243 // resource provider. 244 // resource provider.
244 ResourceProvider::ResourceIdMap empty_map; 245 ResourceProvider::ResourceIdMap empty_map;
245 const ResourceProvider::ResourceIdMap& child_to_parent_map = 246 const ResourceProvider::ResourceIdMap& child_to_parent_map =
246 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface)) 247 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface))
247 : empty_map; 248 : empty_map;
248 bool merge_pass = 249 bool merge_pass =
249 surface_quad->shared_quad_state->opacity == 1.f && copy_requests.empty(); 250 surface_quad->shared_quad_state->opacity == 1.f && copy_requests.empty();
250 251
251 const RenderPassList& referenced_passes = render_pass_list; 252 const RenderPassList& referenced_passes = render_pass_list;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 clip_rect, dest_pass); 330 clip_rect, dest_pass);
330 331
331 RenderPassDrawQuad* quad = 332 RenderPassDrawQuad* quad =
332 dest_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); 333 dest_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
333 quad->SetNew(shared_quad_state, surface_quad->rect, 334 quad->SetNew(shared_quad_state, surface_quad->rect,
334 surface_quad->visible_rect, remapped_pass_id, 0, gfx::RectF(), 335 surface_quad->visible_rect, remapped_pass_id, 0, gfx::RectF(),
335 gfx::Size(), gfx::Vector2dF(), gfx::PointF(), 336 gfx::Size(), gfx::Vector2dF(), gfx::PointF(),
336 gfx::RectF(surface_quad->rect)); 337 gfx::RectF(surface_quad->rect));
337 } 338 }
338 339
339 // Need to re-query since referenced_surfaces_ iterators are not stable. 340 referenced_surfaces_.erase(it);
340 referenced_surfaces_.erase(referenced_surfaces_.find(surface_id));
341 } 341 }
342 342
343 void SurfaceAggregator::AddColorConversionPass() { 343 void SurfaceAggregator::AddColorConversionPass() {
344 if (dest_pass_list_->empty()) 344 if (dest_pass_list_->empty())
345 return; 345 return;
346 346
347 RenderPass* root_render_pass = dest_pass_list_->back().get(); 347 RenderPass* root_render_pass = dest_pass_list_->back().get();
348 if (root_render_pass->color_space == output_color_space_) 348 if (root_render_pass->color_space == output_color_space_)
349 return; 349 return;
350 350
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 } 561 }
562 562
563 dest_pass_list_->push_back(std::move(copy_pass)); 563 dest_pass_list_->push_back(std::move(copy_pass));
564 } 564 }
565 } 565 }
566 566
567 void SurfaceAggregator::ProcessAddedAndRemovedSurfaces() { 567 void SurfaceAggregator::ProcessAddedAndRemovedSurfaces() {
568 for (const auto& surface : previous_contained_surfaces_) { 568 for (const auto& surface : previous_contained_surfaces_) {
569 if (!contained_surfaces_.count(surface.first)) { 569 if (!contained_surfaces_.count(surface.first)) {
570 // Release resources of removed surface. 570 // Release resources of removed surface.
571 auto it = surface_id_to_resource_child_id_.find(surface.first); 571 SurfaceToResourceChildIdMap::iterator it =
572 surface_id_to_resource_child_id_.find(surface.first);
572 if (it != surface_id_to_resource_child_id_.end()) { 573 if (it != surface_id_to_resource_child_id_.end()) {
573 provider_->DestroyChild(it->second); 574 provider_->DestroyChild(it->second);
574 surface_id_to_resource_child_id_.erase(it); 575 surface_id_to_resource_child_id_.erase(it);
575 } 576 }
576 577
577 // Notify client of removed surface. 578 // Notify client of removed surface.
578 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first); 579 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first);
579 if (surface_ptr) { 580 if (surface_ptr) {
580 surface_ptr->RunDrawCallbacks(); 581 surface_ptr->RunDrawCallbacks();
581 } 582 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 parent_pass_id(parent_pass_id), 646 parent_pass_id(parent_pass_id),
646 target_to_surface_transform(target_to_surface_transform) {} 647 target_to_surface_transform(target_to_surface_transform) {}
647 648
648 SurfaceId id; 649 SurfaceId id;
649 bool has_moved_pixels; 650 bool has_moved_pixels;
650 int parent_pass_id; 651 int parent_pass_id;
651 gfx::Transform target_to_surface_transform; 652 gfx::Transform target_to_surface_transform;
652 }; 653 };
653 std::vector<SurfaceInfo> child_surfaces; 654 std::vector<SurfaceInfo> child_surfaces;
654 655
655 // This data is created once and typically small or empty. Collect all items 656 std::unordered_set<int> pixel_moving_background_filter_passes;
656 // and pass to a flat_vector to sort once.
657 std::vector<int> pixel_moving_background_filter_passes_data;
658 for (const auto& render_pass : frame.render_pass_list) { 657 for (const auto& render_pass : frame.render_pass_list) {
659 if (render_pass->background_filters.HasFilterThatMovesPixels()) { 658 if (render_pass->background_filters.HasFilterThatMovesPixels()) {
660 pixel_moving_background_filter_passes_data.push_back( 659 pixel_moving_background_filter_passes.insert(
661 RemapPassId(render_pass->id, surface_id)); 660 RemapPassId(render_pass->id, surface_id));
662 } 661 }
663 } 662 }
664 base::flat_set<int> pixel_moving_background_filter_passes(
665 std::move(pixel_moving_background_filter_passes_data),
666 base::KEEP_FIRST_OF_DUPES);
667 663
668 for (const auto& render_pass : base::Reversed(frame.render_pass_list)) { 664 for (const auto& render_pass : base::Reversed(frame.render_pass_list)) {
669 int remapped_pass_id = RemapPassId(render_pass->id, surface_id); 665 int remapped_pass_id = RemapPassId(render_pass->id, surface_id);
670 bool has_pixel_moving_filter = 666 bool has_pixel_moving_filter =
671 render_pass->filters.HasFilterThatMovesPixels(); 667 render_pass->filters.HasFilterThatMovesPixels();
672 if (has_pixel_moving_filter) 668 if (has_pixel_moving_filter)
673 moved_pixel_passes_.insert(remapped_pass_id); 669 moved_pixel_passes_.insert(remapped_pass_id);
674 bool in_moved_pixel_pass = has_pixel_moving_filter || 670 bool in_moved_pixel_pass = has_pixel_moving_filter ||
675 !!moved_pixel_passes_.count(remapped_pass_id); 671 !!moved_pixel_passes_.count(remapped_pass_id);
676 for (auto* quad : render_pass->quad_list) { 672 for (auto* quad : render_pass->quad_list) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 gfx::Rect full_damage; 721 gfx::Rect full_damage;
726 if (!frame.render_pass_list.empty()) { 722 if (!frame.render_pass_list.empty()) {
727 RenderPass* last_pass = frame.render_pass_list.back().get(); 723 RenderPass* last_pass = frame.render_pass_list.back().get();
728 full_damage = last_pass->output_rect; 724 full_damage = last_pass->output_rect;
729 damage_rect = 725 damage_rect =
730 DamageRectForSurface(surface, *last_pass, last_pass->output_rect); 726 DamageRectForSurface(surface, *last_pass, last_pass->output_rect);
731 } 727 }
732 728
733 // Avoid infinite recursion by adding current surface to 729 // Avoid infinite recursion by adding current surface to
734 // referenced_surfaces_. 730 // referenced_surfaces_.
735 referenced_surfaces_.insert(surface->surface_id()); 731 SurfaceSet::iterator it =
732 referenced_surfaces_.insert(surface->surface_id()).first;
736 for (const auto& surface_info : child_surfaces) { 733 for (const auto& surface_info : child_surfaces) {
737 gfx::Rect surface_damage = 734 gfx::Rect surface_damage =
738 PrewalkTree(surface_info.id, surface_info.has_moved_pixels, 735 PrewalkTree(surface_info.id, surface_info.has_moved_pixels,
739 surface_info.parent_pass_id, result); 736 surface_info.parent_pass_id, result);
740 if (surface_damage.IsEmpty()) 737 if (surface_damage.IsEmpty())
741 continue; 738 continue;
742 if (surface_info.has_moved_pixels) { 739 if (surface_info.has_moved_pixels) {
743 // 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
744 // modified if there is a filter that moves pixels. 741 // modified if there is a filter that moves pixels.
745 damage_rect = full_damage; 742 damage_rect = full_damage;
(...skipping 19 matching lines...) Expand all
765 } 762 }
766 763
767 CHECK(debug_weak_this.get()); 764 CHECK(debug_weak_this.get());
768 for (const auto& render_pass : frame.render_pass_list) { 765 for (const auto& render_pass : frame.render_pass_list) {
769 if (!render_pass->copy_requests.empty()) { 766 if (!render_pass->copy_requests.empty()) {
770 int remapped_pass_id = RemapPassId(render_pass->id, surface_id); 767 int remapped_pass_id = RemapPassId(render_pass->id, surface_id);
771 copy_request_passes_.insert(remapped_pass_id); 768 copy_request_passes_.insert(remapped_pass_id);
772 } 769 }
773 } 770 }
774 771
775 referenced_surfaces_.erase(referenced_surfaces_.find(surface->surface_id())); 772 referenced_surfaces_.erase(it);
776 if (!damage_rect.IsEmpty() && frame.metadata.may_contain_video) 773 if (!damage_rect.IsEmpty() && frame.metadata.may_contain_video)
777 result->may_contain_video = true; 774 result->may_contain_video = true;
778 return damage_rect; 775 return damage_rect;
779 } 776 }
780 777
781 void SurfaceAggregator::CopyUndrawnSurfaces(PrewalkResult* prewalk_result) { 778 void SurfaceAggregator::CopyUndrawnSurfaces(PrewalkResult* prewalk_result) {
782 // undrawn_surfaces are Surfaces that were identified by prewalk as being 779 // undrawn_surfaces are Surfaces that were identified by prewalk as being
783 // 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.
784 // 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
785 // (or on Surfaces they reference) are executed. 782 // (or on Surfaces they reference) are executed.
(...skipping 20 matching lines...) Expand all
806 for (const auto& child_id : frame.metadata.referenced_surfaces) { 803 for (const auto& child_id : frame.metadata.referenced_surfaces) {
807 // 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
808 // 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
809 // recursion. 806 // recursion.
810 if (!prewalk_result->undrawn_surfaces.count(child_id)) { 807 if (!prewalk_result->undrawn_surfaces.count(child_id)) {
811 surfaces_to_copy.push_back(child_id); 808 surfaces_to_copy.push_back(child_id);
812 prewalk_result->undrawn_surfaces.insert(child_id); 809 prewalk_result->undrawn_surfaces.insert(child_id);
813 } 810 }
814 } 811 }
815 } else { 812 } else {
816 auto it = referenced_surfaces_.insert(surface_id).first; 813 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first;
817 CopyPasses(frame, surface); 814 CopyPasses(frame, surface);
818 referenced_surfaces_.erase(it); 815 referenced_surfaces_.erase(it);
819 } 816 }
820 } 817 }
821 } 818 }
822 819
823 void SurfaceAggregator::PropagateCopyRequestPasses() { 820 void SurfaceAggregator::PropagateCopyRequestPasses() {
824 std::vector<int> copy_requests_to_iterate(copy_request_passes_.begin(), 821 std::vector<int> copy_requests_to_iterate(copy_request_passes_.begin(),
825 copy_request_passes_.end()); 822 copy_request_passes_.end());
826 while (!copy_requests_to_iterate.empty()) { 823 while (!copy_requests_to_iterate.empty()) {
(...skipping 29 matching lines...) Expand all
856 dest_pass_list_ = &frame.render_pass_list; 853 dest_pass_list_ = &frame.render_pass_list;
857 854
858 valid_surfaces_.clear(); 855 valid_surfaces_.clear();
859 PrewalkResult prewalk_result; 856 PrewalkResult prewalk_result;
860 root_damage_rect_ = PrewalkTree(surface_id, false, 0, &prewalk_result); 857 root_damage_rect_ = PrewalkTree(surface_id, false, 0, &prewalk_result);
861 PropagateCopyRequestPasses(); 858 PropagateCopyRequestPasses();
862 has_copy_requests_ = !copy_request_passes_.empty(); 859 has_copy_requests_ = !copy_request_passes_.empty();
863 frame.metadata.may_contain_video = prewalk_result.may_contain_video; 860 frame.metadata.may_contain_video = prewalk_result.may_contain_video;
864 861
865 CopyUndrawnSurfaces(&prewalk_result); 862 CopyUndrawnSurfaces(&prewalk_result);
866 auto it = referenced_surfaces_.insert(surface_id).first; 863 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first;
867 CopyPasses(root_surface_frame, surface); 864 CopyPasses(root_surface_frame, surface);
868 referenced_surfaces_.erase(it); 865 referenced_surfaces_.erase(it);
869 AddColorConversionPass(); 866 AddColorConversionPass();
870 867
871 moved_pixel_passes_.clear(); 868 moved_pixel_passes_.clear();
872 copy_request_passes_.clear(); 869 copy_request_passes_.clear();
873 render_pass_dependencies_.clear(); 870 render_pass_dependencies_.clear();
874 871
875 // 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.
876 for (auto it = render_pass_allocator_map_.begin(); 873 for (auto it = render_pass_allocator_map_.begin();
877 it != render_pass_allocator_map_.end();) { 874 it != render_pass_allocator_map_.end();) {
878 if (it->second.in_use) { 875 if (it->second.in_use) {
879 it->second.in_use = false; 876 it->second.in_use = false;
880 it++; 877 it++;
881 } else { 878 } else {
882 it = render_pass_allocator_map_.erase(it); 879 it = render_pass_allocator_map_.erase(it);
883 } 880 }
884 } 881 }
885 882
886 DCHECK(referenced_surfaces_.empty()); 883 DCHECK(referenced_surfaces_.empty());
887 884
888 if (dest_pass_list_->empty()) 885 if (dest_pass_list_->empty())
889 return CompositorFrame(); 886 return CompositorFrame();
890 887
891 dest_pass_list_ = NULL; 888 dest_pass_list_ = NULL;
892 ProcessAddedAndRemovedSurfaces(); 889 ProcessAddedAndRemovedSurfaces();
893 contained_surfaces_.swap(previous_contained_surfaces_); 890 contained_surfaces_.swap(previous_contained_surfaces_);
894 contained_surfaces_.clear(); 891 contained_surfaces_.clear();
895 892
896 for (auto it : previous_contained_surfaces_) { 893 for (SurfaceIndexMap::iterator it = previous_contained_surfaces_.begin();
897 Surface* surface = manager_->GetSurfaceForId(it.first); 894 it != previous_contained_surfaces_.end();
895 ++it) {
896 Surface* surface = manager_->GetSurfaceForId(it->first);
898 if (surface) 897 if (surface)
899 surface->TakeLatencyInfo(&frame.metadata.latency_info); 898 surface->TakeLatencyInfo(&frame.metadata.latency_info);
900 } 899 }
901 900
902 // TODO(jamesr): Aggregate all resource references into the returned frame's 901 // TODO(jamesr): Aggregate all resource references into the returned frame's
903 // resource list. 902 // resource list.
904 903
905 // Log UMA stats for SurfaceDrawQuads on the number of surfaces that were 904 // Log UMA stats for SurfaceDrawQuads on the number of surfaces that were
906 // aggregated together and any failures. 905 // aggregated together and any failures.
907 UMA_HISTOGRAM_EXACT_LINEAR(kUmaValidSurface, uma_stats_.valid_surface, 906 UMA_HISTOGRAM_EXACT_LINEAR(kUmaValidSurface, uma_stats_.valid_surface,
908 kUmaStatMaxSurfaces); 907 kUmaStatMaxSurfaces);
909 UMA_HISTOGRAM_EXACT_LINEAR(kUmaMissingSurface, uma_stats_.missing_surface, 908 UMA_HISTOGRAM_EXACT_LINEAR(kUmaMissingSurface, uma_stats_.missing_surface,
910 kUmaStatMaxSurfaces); 909 kUmaStatMaxSurfaces);
911 UMA_HISTOGRAM_EXACT_LINEAR(kUmaNoActiveFrame, uma_stats_.no_active_frame, 910 UMA_HISTOGRAM_EXACT_LINEAR(kUmaNoActiveFrame, uma_stats_.no_active_frame,
912 kUmaStatMaxSurfaces); 911 kUmaStatMaxSurfaces);
913 912
914 return frame; 913 return frame;
915 } 914 }
916 915
917 void SurfaceAggregator::ReleaseResources(const SurfaceId& surface_id) { 916 void SurfaceAggregator::ReleaseResources(const SurfaceId& surface_id) {
918 auto it = surface_id_to_resource_child_id_.find(surface_id); 917 SurfaceToResourceChildIdMap::iterator it =
918 surface_id_to_resource_child_id_.find(surface_id);
919 if (it != surface_id_to_resource_child_id_.end()) { 919 if (it != surface_id_to_resource_child_id_.end()) {
920 provider_->DestroyChild(it->second); 920 provider_->DestroyChild(it->second);
921 surface_id_to_resource_child_id_.erase(it); 921 surface_id_to_resource_child_id_.erase(it);
922 } 922 }
923 } 923 }
924 924
925 void SurfaceAggregator::SetFullDamageForSurface(const SurfaceId& surface_id) { 925 void SurfaceAggregator::SetFullDamageForSurface(const SurfaceId& surface_id) {
926 auto it = previous_contained_surfaces_.find(surface_id); 926 auto it = previous_contained_surfaces_.find(surface_id);
927 if (it == previous_contained_surfaces_.end()) 927 if (it == previous_contained_surfaces_.end())
928 return; 928 return;
929 // Set the last drawn index as 0 to ensure full damage next time it's drawn. 929 // Set the last drawn index as 0 to ensure full damage next time it's drawn.
930 it->second = 0; 930 it->second = 0;
931 } 931 }
932 932
933 void SurfaceAggregator::SetOutputColorSpace( 933 void SurfaceAggregator::SetOutputColorSpace(
934 const gfx::ColorSpace& blending_color_space, 934 const gfx::ColorSpace& blending_color_space,
935 const gfx::ColorSpace& output_color_space) { 935 const gfx::ColorSpace& output_color_space) {
936 blending_color_space_ = blending_color_space; 936 blending_color_space_ = blending_color_space;
937 output_color_space_ = output_color_space; 937 output_color_space_ = output_color_space;
938 } 938 }
939 939
940 } // namespace cc 940 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_aggregator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698