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

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

Issue 2098953003: Make cc::CompositorFrames movable [Part 2 of 2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed exo unittests Created 4 years, 5 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') | cc/surfaces/surface_aggregator_perftest.cc » ('j') | 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 const ClipData& clip_rect, 181 const ClipData& clip_rect,
182 RenderPass* dest_pass) { 182 RenderPass* dest_pass) {
183 SurfaceId surface_id = surface_quad->surface_id; 183 SurfaceId surface_id = surface_quad->surface_id;
184 // If this surface's id is already in our referenced set then it creates 184 // If this surface's id is already in our referenced set then it creates
185 // a cycle in the graph and should be dropped. 185 // a cycle in the graph and should be dropped.
186 if (referenced_surfaces_.count(surface_id)) 186 if (referenced_surfaces_.count(surface_id))
187 return; 187 return;
188 Surface* surface = manager_->GetSurfaceForId(surface_id); 188 Surface* surface = manager_->GetSurfaceForId(surface_id);
189 if (!surface) 189 if (!surface)
190 return; 190 return;
191 const CompositorFrame* frame = surface->GetEligibleFrame(); 191 const CompositorFrame& frame = surface->GetEligibleFrame();
192 if (!frame) 192 const DelegatedFrameData* frame_data = frame.delegated_frame_data.get();
193 return;
194 const DelegatedFrameData* frame_data = frame->delegated_frame_data.get();
195 if (!frame_data) 193 if (!frame_data)
196 return; 194 return;
197 195
198 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>> copy_requests; 196 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>> copy_requests;
199 surface->TakeCopyOutputRequests(&copy_requests); 197 surface->TakeCopyOutputRequests(&copy_requests);
200 198
201 const RenderPassList& render_pass_list = frame_data->render_pass_list; 199 const RenderPassList& render_pass_list = frame_data->render_pass_list;
202 if (!valid_surfaces_.count(surface->surface_id())) { 200 if (!valid_surfaces_.count(surface->surface_id())) {
203 for (auto& request : copy_requests) 201 for (auto& request : copy_requests)
204 request.second->SendEmptyResult(); 202 request.second->SendEmptyResult();
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 base::WeakPtr<SurfaceAggregator> debug_weak_this = weak_factory_.GetWeakPtr(); 554 base::WeakPtr<SurfaceAggregator> debug_weak_this = weak_factory_.GetWeakPtr();
557 555
558 if (referenced_surfaces_.count(surface_id)) 556 if (referenced_surfaces_.count(surface_id))
559 return gfx::Rect(); 557 return gfx::Rect();
560 Surface* surface = manager_->GetSurfaceForId(surface_id); 558 Surface* surface = manager_->GetSurfaceForId(surface_id);
561 if (!surface) { 559 if (!surface) {
562 contained_surfaces_[surface_id] = 0; 560 contained_surfaces_[surface_id] = 0;
563 return gfx::Rect(); 561 return gfx::Rect();
564 } 562 }
565 contained_surfaces_[surface_id] = surface->frame_index(); 563 contained_surfaces_[surface_id] = surface->frame_index();
566 const CompositorFrame* surface_frame = surface->GetEligibleFrame(); 564 const CompositorFrame& surface_frame = surface->GetEligibleFrame();
567 if (!surface_frame)
568 return gfx::Rect();
569 const DelegatedFrameData* frame_data = 565 const DelegatedFrameData* frame_data =
570 surface_frame->delegated_frame_data.get(); 566 surface_frame.delegated_frame_data.get();
571 if (!frame_data) 567 if (!frame_data)
572 return gfx::Rect(); 568 return gfx::Rect();
573 int child_id = 0; 569 int child_id = 0;
574 // TODO(jbauman): hack for unit tests that don't set up rp 570 // TODO(jbauman): hack for unit tests that don't set up rp
575 if (provider_) { 571 if (provider_) {
576 child_id = ChildIdForSurface(surface); 572 child_id = ChildIdForSurface(surface);
577 if (surface->factory()) 573 if (surface->factory())
578 surface->factory()->RefResources(frame_data->resource_list); 574 surface->factory()->RefResources(frame_data->resource_list);
579 provider_->ReceiveFromChild(child_id, frame_data->resource_list); 575 provider_->ReceiveFromChild(child_id, frame_data->resource_list);
580 } 576 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 // modified if there is a filter that moves pixels. 676 // modified if there is a filter that moves pixels.
681 damage_rect = full_damage; 677 damage_rect = full_damage;
682 continue; 678 continue;
683 } 679 }
684 680
685 damage_rect.Union(MathUtil::MapEnclosingClippedRect( 681 damage_rect.Union(MathUtil::MapEnclosingClippedRect(
686 surface_info.target_to_surface_transform, surface_damage)); 682 surface_info.target_to_surface_transform, surface_damage));
687 } 683 }
688 684
689 CHECK(debug_weak_this.get()); 685 CHECK(debug_weak_this.get());
690 for (const auto& surface_id : surface_frame->metadata.referenced_surfaces) { 686 for (const auto& surface_id : surface_frame.metadata.referenced_surfaces) {
691 if (!contained_surfaces_.count(surface_id)) { 687 if (!contained_surfaces_.count(surface_id)) {
692 result->undrawn_surfaces.insert(surface_id); 688 result->undrawn_surfaces.insert(surface_id);
693 PrewalkTree(surface_id, false, RenderPassId(), result); 689 PrewalkTree(surface_id, false, RenderPassId(), result);
694 } 690 }
695 } 691 }
696 692
697 CHECK(debug_weak_this.get()); 693 CHECK(debug_weak_this.get());
698 if (surface->factory()) 694 if (surface->factory())
699 surface->factory()->WillDrawSurface(surface->surface_id(), damage_rect); 695 surface->factory()->WillDrawSurface(surface->surface_id(), damage_rect);
700 696
(...skipping 16 matching lines...) Expand all
717 // (or on Surfaces they reference) are executed. 713 // (or on Surfaces they reference) are executed.
718 std::vector<SurfaceId> surfaces_to_copy( 714 std::vector<SurfaceId> surfaces_to_copy(
719 prewalk_result->undrawn_surfaces.begin(), 715 prewalk_result->undrawn_surfaces.begin(),
720 prewalk_result->undrawn_surfaces.end()); 716 prewalk_result->undrawn_surfaces.end());
721 717
722 for (size_t i = 0; i < surfaces_to_copy.size(); i++) { 718 for (size_t i = 0; i < surfaces_to_copy.size(); i++) {
723 SurfaceId surface_id = surfaces_to_copy[i]; 719 SurfaceId surface_id = surfaces_to_copy[i];
724 Surface* surface = manager_->GetSurfaceForId(surface_id); 720 Surface* surface = manager_->GetSurfaceForId(surface_id);
725 if (!surface) 721 if (!surface)
726 continue; 722 continue;
727 const CompositorFrame* surface_frame = surface->GetEligibleFrame(); 723 const CompositorFrame& surface_frame = surface->GetEligibleFrame();
728 if (!surface_frame) 724 if (!surface_frame.delegated_frame_data)
729 continue; 725 continue;
730 bool surface_has_copy_requests = false; 726 bool surface_has_copy_requests = false;
731 for (const auto& render_pass : 727 for (const auto& render_pass :
732 surface_frame->delegated_frame_data->render_pass_list) { 728 surface_frame.delegated_frame_data->render_pass_list) {
733 surface_has_copy_requests |= !render_pass->copy_requests.empty(); 729 surface_has_copy_requests |= !render_pass->copy_requests.empty();
734 } 730 }
735 if (!surface_has_copy_requests) { 731 if (!surface_has_copy_requests) {
736 // Children are not necessarily included in undrawn_surfaces (because 732 // Children are not necessarily included in undrawn_surfaces (because
737 // they weren't referenced directly from a drawn surface), but may have 733 // they weren't referenced directly from a drawn surface), but may have
738 // copy requests, so make sure to check them as well. 734 // copy requests, so make sure to check them as well.
739 for (const auto& child_id : surface_frame->metadata.referenced_surfaces) { 735 for (const auto& child_id : surface_frame.metadata.referenced_surfaces) {
740 // Don't iterate over the child Surface if it was already listed as a 736 // Don't iterate over the child Surface if it was already listed as a
741 // child of a different Surface, or in the case where there's infinite 737 // child of a different Surface, or in the case where there's infinite
742 // recursion. 738 // recursion.
743 if (!prewalk_result->undrawn_surfaces.count(child_id)) { 739 if (!prewalk_result->undrawn_surfaces.count(child_id)) {
744 surfaces_to_copy.push_back(child_id); 740 surfaces_to_copy.push_back(child_id);
745 prewalk_result->undrawn_surfaces.insert(child_id); 741 prewalk_result->undrawn_surfaces.insert(child_id);
746 } 742 }
747 } 743 }
748 } else { 744 } else {
749 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; 745 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first;
750 CopyPasses(surface_frame->delegated_frame_data.get(), surface); 746 CopyPasses(surface_frame.delegated_frame_data.get(), surface);
751 referenced_surfaces_.erase(it); 747 referenced_surfaces_.erase(it);
752 } 748 }
753 } 749 }
754 } 750 }
755 751
756 void SurfaceAggregator::PropagateCopyRequestPasses() { 752 void SurfaceAggregator::PropagateCopyRequestPasses() {
757 std::vector<RenderPassId> copy_requests_to_iterate( 753 std::vector<RenderPassId> copy_requests_to_iterate(
758 copy_request_passes_.begin(), copy_request_passes_.end()); 754 copy_request_passes_.begin(), copy_request_passes_.end());
759 while (!copy_requests_to_iterate.empty()) { 755 while (!copy_requests_to_iterate.empty()) {
760 RenderPassId first = copy_requests_to_iterate.back(); 756 RenderPassId first = copy_requests_to_iterate.back();
761 copy_requests_to_iterate.pop_back(); 757 copy_requests_to_iterate.pop_back();
762 auto it = render_pass_dependencies_.find(first); 758 auto it = render_pass_dependencies_.find(first);
763 if (it == render_pass_dependencies_.end()) 759 if (it == render_pass_dependencies_.end())
764 continue; 760 continue;
765 for (auto pass : it->second) { 761 for (auto pass : it->second) {
766 if (copy_request_passes_.insert(pass).second) { 762 if (copy_request_passes_.insert(pass).second) {
767 copy_requests_to_iterate.push_back(pass); 763 copy_requests_to_iterate.push_back(pass);
768 } 764 }
769 } 765 }
770 } 766 }
771 } 767 }
772 768
773 std::unique_ptr<CompositorFrame> SurfaceAggregator::Aggregate( 769 CompositorFrame SurfaceAggregator::Aggregate(SurfaceId surface_id) {
774 SurfaceId surface_id) {
775 Surface* surface = manager_->GetSurfaceForId(surface_id); 770 Surface* surface = manager_->GetSurfaceForId(surface_id);
776 DCHECK(surface); 771 DCHECK(surface);
777 contained_surfaces_[surface_id] = surface->frame_index(); 772 contained_surfaces_[surface_id] = surface->frame_index();
778 const CompositorFrame* root_surface_frame = surface->GetEligibleFrame(); 773 const CompositorFrame& root_surface_frame = surface->GetEligibleFrame();
779 if (!root_surface_frame) 774 if (!root_surface_frame.delegated_frame_data)
780 return nullptr; 775 return CompositorFrame();
781 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate"); 776 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate");
782 777
783 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 778 CompositorFrame frame;
784 frame->delegated_frame_data = base::WrapUnique(new DelegatedFrameData); 779 frame.delegated_frame_data = base::WrapUnique(new DelegatedFrameData);
785 780
786 DCHECK(root_surface_frame->delegated_frame_data); 781 dest_resource_list_ = &frame.delegated_frame_data->resource_list;
787 782 dest_pass_list_ = &frame.delegated_frame_data->render_pass_list;
788 dest_resource_list_ = &frame->delegated_frame_data->resource_list;
789 dest_pass_list_ = &frame->delegated_frame_data->render_pass_list;
790 783
791 valid_surfaces_.clear(); 784 valid_surfaces_.clear();
792 PrewalkResult prewalk_result; 785 PrewalkResult prewalk_result;
793 root_damage_rect_ = 786 root_damage_rect_ =
794 PrewalkTree(surface_id, false, RenderPassId(), &prewalk_result); 787 PrewalkTree(surface_id, false, RenderPassId(), &prewalk_result);
795 PropagateCopyRequestPasses(); 788 PropagateCopyRequestPasses();
796 has_copy_requests_ = !copy_request_passes_.empty(); 789 has_copy_requests_ = !copy_request_passes_.empty();
797 790
798 CopyUndrawnSurfaces(&prewalk_result); 791 CopyUndrawnSurfaces(&prewalk_result);
799 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; 792 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first;
800 CopyPasses(root_surface_frame->delegated_frame_data.get(), surface); 793 CopyPasses(root_surface_frame.delegated_frame_data.get(), surface);
801 referenced_surfaces_.erase(it); 794 referenced_surfaces_.erase(it);
802 795
803 moved_pixel_passes_.clear(); 796 moved_pixel_passes_.clear();
804 copy_request_passes_.clear(); 797 copy_request_passes_.clear();
805 render_pass_dependencies_.clear(); 798 render_pass_dependencies_.clear();
806 799
807 DCHECK(referenced_surfaces_.empty()); 800 DCHECK(referenced_surfaces_.empty());
808 801
809 if (dest_pass_list_->empty()) 802 if (dest_pass_list_->empty())
810 return nullptr; 803 return CompositorFrame();
811 804
812 dest_pass_list_ = NULL; 805 dest_pass_list_ = NULL;
813 ProcessAddedAndRemovedSurfaces(); 806 ProcessAddedAndRemovedSurfaces();
814 contained_surfaces_.swap(previous_contained_surfaces_); 807 contained_surfaces_.swap(previous_contained_surfaces_);
815 contained_surfaces_.clear(); 808 contained_surfaces_.clear();
816 809
817 for (SurfaceIndexMap::iterator it = previous_contained_surfaces_.begin(); 810 for (SurfaceIndexMap::iterator it = previous_contained_surfaces_.begin();
818 it != previous_contained_surfaces_.end(); 811 it != previous_contained_surfaces_.end();
819 ++it) { 812 ++it) {
820 Surface* surface = manager_->GetSurfaceForId(it->first); 813 Surface* surface = manager_->GetSurfaceForId(it->first);
821 if (surface) 814 if (surface)
822 surface->TakeLatencyInfo(&frame->metadata.latency_info); 815 surface->TakeLatencyInfo(&frame.metadata.latency_info);
823 } 816 }
824 817
825 // TODO(jamesr): Aggregate all resource references into the returned frame's 818 // TODO(jamesr): Aggregate all resource references into the returned frame's
826 // resource list. 819 // resource list.
827 820
828 return frame; 821 return frame;
829 } 822 }
830 823
831 void SurfaceAggregator::ReleaseResources(SurfaceId surface_id) { 824 void SurfaceAggregator::ReleaseResources(SurfaceId surface_id) {
832 SurfaceToResourceChildIdMap::iterator it = 825 SurfaceToResourceChildIdMap::iterator it =
833 surface_id_to_resource_child_id_.find(surface_id); 826 surface_id_to_resource_child_id_.find(surface_id);
834 if (it != surface_id_to_resource_child_id_.end()) { 827 if (it != surface_id_to_resource_child_id_.end()) {
835 provider_->DestroyChild(it->second); 828 provider_->DestroyChild(it->second);
836 surface_id_to_resource_child_id_.erase(it); 829 surface_id_to_resource_child_id_.erase(it);
837 } 830 }
838 } 831 }
839 832
840 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { 833 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) {
841 auto it = previous_contained_surfaces_.find(surface_id); 834 auto it = previous_contained_surfaces_.find(surface_id);
842 if (it == previous_contained_surfaces_.end()) 835 if (it == previous_contained_surfaces_.end())
843 return; 836 return;
844 // Set the last drawn index as 0 to ensure full damage next time it's drawn. 837 // Set the last drawn index as 0 to ensure full damage next time it's drawn.
845 it->second = 0; 838 it->second = 0;
846 } 839 }
847 840
848 } // namespace cc 841 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_aggregator.h ('k') | cc/surfaces/surface_aggregator_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698