| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (out_clip.is_clipped) | 86 if (out_clip.is_clipped) |
| 87 out_clip.rect.Intersect(final_clip); | 87 out_clip.rect.Intersect(final_clip); |
| 88 else | 88 else |
| 89 out_clip.rect = final_clip; | 89 out_clip.rect = final_clip; |
| 90 out_clip.is_clipped = true; | 90 out_clip.is_clipped = true; |
| 91 } | 91 } |
| 92 | 92 |
| 93 return out_clip; | 93 return out_clip; |
| 94 } | 94 } |
| 95 | 95 |
| 96 class SurfaceAggregator::RenderPassIdAllocator { | |
| 97 public: | |
| 98 explicit RenderPassIdAllocator(int* next_index) : next_index_(next_index) {} | |
| 99 ~RenderPassIdAllocator() {} | |
| 100 | |
| 101 void AddKnownPass(RenderPassId id) { | |
| 102 if (id_to_index_map_.find(id) != id_to_index_map_.end()) | |
| 103 return; | |
| 104 id_to_index_map_[id] = (*next_index_)++; | |
| 105 } | |
| 106 | |
| 107 RenderPassId Remap(RenderPassId id) { | |
| 108 DCHECK(id_to_index_map_.find(id) != id_to_index_map_.end()); | |
| 109 return RenderPassId(1, id_to_index_map_[id]); | |
| 110 } | |
| 111 | |
| 112 private: | |
| 113 std::unordered_map<RenderPassId, int, RenderPassIdHash> id_to_index_map_; | |
| 114 int* next_index_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(RenderPassIdAllocator); | |
| 117 }; | |
| 118 | |
| 119 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory, | 96 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory, |
| 120 const ReturnedResourceArray& resources, | 97 const ReturnedResourceArray& resources, |
| 121 BlockingTaskRunner* main_thread_task_runner) { | 98 BlockingTaskRunner* main_thread_task_runner) { |
| 122 if (surface_factory) | 99 if (surface_factory) |
| 123 surface_factory->UnrefResources(resources); | 100 surface_factory->UnrefResources(resources); |
| 124 } | 101 } |
| 125 | 102 |
| 126 RenderPassId SurfaceAggregator::RemapPassId(RenderPassId surface_local_pass_id, | 103 RenderPassId SurfaceAggregator::RemapPassId(RenderPassId surface_local_pass_id, |
| 127 const SurfaceId& surface_id) { | 104 const SurfaceId& surface_id) { |
| 128 std::unique_ptr<RenderPassIdAllocator>& allocator = | 105 auto key = std::make_pair(surface_id, surface_local_pass_id); |
| 129 render_pass_allocator_map_[surface_id]; | 106 auto it = render_pass_allocator_map_.find(key); |
| 130 if (!allocator) | 107 if (it != render_pass_allocator_map_.end()) { |
| 131 allocator.reset(new RenderPassIdAllocator(&next_render_pass_id_)); | 108 it->second.in_use = true; |
| 132 allocator->AddKnownPass(surface_local_pass_id); | 109 return it->second.id; |
| 133 return allocator->Remap(surface_local_pass_id); | 110 } |
| 111 |
| 112 RenderPassInfo render_pass_info; |
| 113 render_pass_info.id = RenderPassId(1, next_render_pass_id_++); |
| 114 render_pass_allocator_map_[key] = render_pass_info; |
| 115 return render_pass_info.id; |
| 134 } | 116 } |
| 135 | 117 |
| 136 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { | 118 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { |
| 137 SurfaceToResourceChildIdMap::iterator it = | 119 SurfaceToResourceChildIdMap::iterator it = |
| 138 surface_id_to_resource_child_id_.find(surface->surface_id()); | 120 surface_id_to_resource_child_id_.find(surface->surface_id()); |
| 139 if (it == surface_id_to_resource_child_id_.end()) { | 121 if (it == surface_id_to_resource_child_id_.end()) { |
| 140 int child_id = | 122 int child_id = |
| 141 provider_->CreateChild(base::Bind(&UnrefHelper, surface->factory())); | 123 provider_->CreateChild(base::Bind(&UnrefHelper, surface->factory())); |
| 142 if (surface->factory()) { | 124 if (surface->factory()) { |
| 143 provider_->SetChildNeedsSyncTokens( | 125 provider_->SetChildNeedsSyncTokens( |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 | 767 |
| 786 CopyUndrawnSurfaces(&prewalk_result); | 768 CopyUndrawnSurfaces(&prewalk_result); |
| 787 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 769 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; |
| 788 CopyPasses(root_surface_frame, surface); | 770 CopyPasses(root_surface_frame, surface); |
| 789 referenced_surfaces_.erase(it); | 771 referenced_surfaces_.erase(it); |
| 790 | 772 |
| 791 moved_pixel_passes_.clear(); | 773 moved_pixel_passes_.clear(); |
| 792 copy_request_passes_.clear(); | 774 copy_request_passes_.clear(); |
| 793 render_pass_dependencies_.clear(); | 775 render_pass_dependencies_.clear(); |
| 794 | 776 |
| 777 // Remove all render pass mappings that weren't used in the current frame. |
| 778 for (auto it = render_pass_allocator_map_.begin(); |
| 779 it != render_pass_allocator_map_.end();) { |
| 780 if (it->second.in_use) { |
| 781 it->second.in_use = false; |
| 782 it++; |
| 783 } else { |
| 784 it = render_pass_allocator_map_.erase(it); |
| 785 } |
| 786 } |
| 787 |
| 795 DCHECK(referenced_surfaces_.empty()); | 788 DCHECK(referenced_surfaces_.empty()); |
| 796 | 789 |
| 797 if (dest_pass_list_->empty()) | 790 if (dest_pass_list_->empty()) |
| 798 return CompositorFrame(); | 791 return CompositorFrame(); |
| 799 | 792 |
| 800 dest_pass_list_ = NULL; | 793 dest_pass_list_ = NULL; |
| 801 ProcessAddedAndRemovedSurfaces(); | 794 ProcessAddedAndRemovedSurfaces(); |
| 802 contained_surfaces_.swap(previous_contained_surfaces_); | 795 contained_surfaces_.swap(previous_contained_surfaces_); |
| 803 contained_surfaces_.clear(); | 796 contained_surfaces_.clear(); |
| 804 | 797 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 827 | 820 |
| 828 void SurfaceAggregator::SetFullDamageForSurface(const SurfaceId& surface_id) { | 821 void SurfaceAggregator::SetFullDamageForSurface(const SurfaceId& surface_id) { |
| 829 auto it = previous_contained_surfaces_.find(surface_id); | 822 auto it = previous_contained_surfaces_.find(surface_id); |
| 830 if (it == previous_contained_surfaces_.end()) | 823 if (it == previous_contained_surfaces_.end()) |
| 831 return; | 824 return; |
| 832 // Set the last drawn index as 0 to ensure full damage next time it's drawn. | 825 // Set the last drawn index as 0 to ensure full damage next time it's drawn. |
| 833 it->second = 0; | 826 it->second = 0; |
| 834 } | 827 } |
| 835 | 828 |
| 836 } // namespace cc | 829 } // namespace cc |
| OLD | NEW |