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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/containers/adapters.h" | 12 #include "base/containers/adapters.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 #include "cc/base/math_util.h" | 19 #include "cc/base/math_util.h" |
20 #include "cc/output/compositor_frame.h" | 20 #include "cc/output/compositor_frame.h" |
21 #include "cc/quads/draw_quad.h" | 21 #include "cc/quads/draw_quad.h" |
22 #include "cc/quads/render_pass_draw_quad.h" | 22 #include "cc/quads/render_pass_draw_quad.h" |
23 #include "cc/quads/shared_quad_state.h" | 23 #include "cc/quads/shared_quad_state.h" |
24 #include "cc/quads/solid_color_draw_quad.h" | 24 #include "cc/quads/solid_color_draw_quad.h" |
25 #include "cc/quads/surface_draw_quad.h" | 25 #include "cc/quads/surface_draw_quad.h" |
26 #include "cc/quads/texture_draw_quad.h" | 26 #include "cc/quads/texture_draw_quad.h" |
27 #include "cc/resources/resource_provider.h" | 27 #include "cc/resources/resource_provider.h" |
| 28 #include "cc/surfaces/compositor_frame_sink_support.h" |
28 #include "cc/surfaces/surface.h" | 29 #include "cc/surfaces/surface.h" |
29 #include "cc/surfaces/surface_factory.h" | |
30 #include "cc/surfaces/surface_manager.h" | 30 #include "cc/surfaces/surface_manager.h" |
31 #include "cc/trees/blocking_task_runner.h" | 31 #include "cc/trees/blocking_task_runner.h" |
32 | 32 |
33 namespace cc { | 33 namespace cc { |
34 namespace { | 34 namespace { |
35 | 35 |
36 // Maximum bucket size for the UMA stats. | 36 // Maximum bucket size for the UMA stats. |
37 constexpr int kUmaStatMaxSurfaces = 30; | 37 constexpr int kUmaStatMaxSurfaces = 30; |
38 | 38 |
39 const char kUmaValidSurface[] = | 39 const char kUmaValidSurface[] = |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 if (out_clip.is_clipped) | 114 if (out_clip.is_clipped) |
115 out_clip.rect.Intersect(final_clip); | 115 out_clip.rect.Intersect(final_clip); |
116 else | 116 else |
117 out_clip.rect = final_clip; | 117 out_clip.rect = final_clip; |
118 out_clip.is_clipped = true; | 118 out_clip.is_clipped = true; |
119 } | 119 } |
120 | 120 |
121 return out_clip; | 121 return out_clip; |
122 } | 122 } |
123 | 123 |
124 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory, | 124 static void UnrefHelper( |
125 const ReturnedResourceArray& resources, | 125 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support, |
126 BlockingTaskRunner* main_thread_task_runner) { | 126 const ReturnedResourceArray& resources, |
127 if (surface_factory) | 127 BlockingTaskRunner* main_thread_task_runner) { |
128 surface_factory->UnrefResources(resources); | 128 if (compositor_frame_sink_support) |
| 129 compositor_frame_sink_support->UnrefResources(resources); |
129 } | 130 } |
130 | 131 |
131 int SurfaceAggregator::RemapPassId(int surface_local_pass_id, | 132 int SurfaceAggregator::RemapPassId(int surface_local_pass_id, |
132 const SurfaceId& surface_id) { | 133 const SurfaceId& surface_id) { |
133 auto key = std::make_pair(surface_id, surface_local_pass_id); | 134 auto key = std::make_pair(surface_id, surface_local_pass_id); |
134 auto it = render_pass_allocator_map_.find(key); | 135 auto it = render_pass_allocator_map_.find(key); |
135 if (it != render_pass_allocator_map_.end()) { | 136 if (it != render_pass_allocator_map_.end()) { |
136 it->second.in_use = true; | 137 it->second.in_use = true; |
137 return it->second.id; | 138 return it->second.id; |
138 } | 139 } |
139 | 140 |
140 RenderPassInfo render_pass_info; | 141 RenderPassInfo render_pass_info; |
141 render_pass_info.id = next_render_pass_id_++; | 142 render_pass_info.id = next_render_pass_id_++; |
142 render_pass_allocator_map_[key] = render_pass_info; | 143 render_pass_allocator_map_[key] = render_pass_info; |
143 return render_pass_info.id; | 144 return render_pass_info.id; |
144 } | 145 } |
145 | 146 |
146 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { | 147 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { |
147 SurfaceToResourceChildIdMap::iterator it = | 148 SurfaceToResourceChildIdMap::iterator it = |
148 surface_id_to_resource_child_id_.find(surface->surface_id()); | 149 surface_id_to_resource_child_id_.find(surface->surface_id()); |
149 if (it == surface_id_to_resource_child_id_.end()) { | 150 if (it == surface_id_to_resource_child_id_.end()) { |
150 int child_id = | 151 int child_id = provider_->CreateChild( |
151 provider_->CreateChild(base::Bind(&UnrefHelper, surface->factory())); | 152 base::Bind(&UnrefHelper, surface->compositor_frame_sink_support())); |
152 if (surface->factory()) { | 153 if (surface->compositor_frame_sink_support()) { |
153 provider_->SetChildNeedsSyncTokens( | 154 provider_->SetChildNeedsSyncTokens( |
154 child_id, surface->factory()->needs_sync_points()); | 155 child_id, |
| 156 surface->compositor_frame_sink_support()->needs_sync_points()); |
155 } | 157 } |
156 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; | 158 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; |
157 return child_id; | 159 return child_id; |
158 } else { | 160 } else { |
159 return it->second; | 161 return it->second; |
160 } | 162 } |
161 } | 163 } |
162 | 164 |
163 gfx::Rect SurfaceAggregator::DamageRectForSurface( | 165 gfx::Rect SurfaceAggregator::DamageRectForSurface( |
164 const Surface* surface, | 166 const Surface* surface, |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 return gfx::Rect(); | 605 return gfx::Rect(); |
604 } | 606 } |
605 contained_surfaces_[surface_id] = surface->frame_index(); | 607 contained_surfaces_[surface_id] = surface->frame_index(); |
606 if (!surface->HasActiveFrame()) | 608 if (!surface->HasActiveFrame()) |
607 return gfx::Rect(); | 609 return gfx::Rect(); |
608 const CompositorFrame& frame = surface->GetActiveFrame(); | 610 const CompositorFrame& frame = surface->GetActiveFrame(); |
609 int child_id = 0; | 611 int child_id = 0; |
610 // TODO(jbauman): hack for unit tests that don't set up rp | 612 // TODO(jbauman): hack for unit tests that don't set up rp |
611 if (provider_) { | 613 if (provider_) { |
612 child_id = ChildIdForSurface(surface); | 614 child_id = ChildIdForSurface(surface); |
613 if (surface->factory()) | 615 if (surface->compositor_frame_sink_support()) |
614 surface->factory()->RefResources(frame.resource_list); | 616 surface->compositor_frame_sink_support()->RefResources( |
| 617 frame.resource_list); |
615 provider_->ReceiveFromChild(child_id, frame.resource_list); | 618 provider_->ReceiveFromChild(child_id, frame.resource_list); |
616 } | 619 } |
617 CHECK(debug_weak_this.get()); | 620 CHECK(debug_weak_this.get()); |
618 | 621 |
619 ResourceIdSet referenced_resources; | 622 ResourceIdSet referenced_resources; |
620 size_t reserve_size = frame.resource_list.size(); | 623 size_t reserve_size = frame.resource_list.size(); |
621 referenced_resources.reserve(reserve_size); | 624 referenced_resources.reserve(reserve_size); |
622 | 625 |
623 bool invalid_frame = false; | 626 bool invalid_frame = false; |
624 ResourceProvider::ResourceIdMap empty_map; | 627 ResourceProvider::ResourceIdMap empty_map; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 | 749 |
747 CHECK(debug_weak_this.get()); | 750 CHECK(debug_weak_this.get()); |
748 for (const auto& surface_id : frame.metadata.referenced_surfaces) { | 751 for (const auto& surface_id : frame.metadata.referenced_surfaces) { |
749 if (!contained_surfaces_.count(surface_id)) { | 752 if (!contained_surfaces_.count(surface_id)) { |
750 result->undrawn_surfaces.insert(surface_id); | 753 result->undrawn_surfaces.insert(surface_id); |
751 PrewalkTree(surface_id, false, 0, result); | 754 PrewalkTree(surface_id, false, 0, result); |
752 } | 755 } |
753 } | 756 } |
754 | 757 |
755 CHECK(debug_weak_this.get()); | 758 CHECK(debug_weak_this.get()); |
756 if (surface->factory()) { | 759 if (surface->compositor_frame_sink_support()) { |
757 surface->factory()->WillDrawSurface( | 760 surface->compositor_frame_sink_support()->WillDrawSurface( |
758 surface->surface_id().local_surface_id(), damage_rect); | 761 surface->surface_id().local_surface_id(), damage_rect); |
759 } | 762 } |
760 | 763 |
761 CHECK(debug_weak_this.get()); | 764 CHECK(debug_weak_this.get()); |
762 for (const auto& render_pass : frame.render_pass_list) { | 765 for (const auto& render_pass : frame.render_pass_list) { |
763 if (!render_pass->copy_requests.empty()) { | 766 if (!render_pass->copy_requests.empty()) { |
764 int remapped_pass_id = RemapPassId(render_pass->id, surface_id); | 767 int remapped_pass_id = RemapPassId(render_pass->id, surface_id); |
765 copy_request_passes_.insert(remapped_pass_id); | 768 copy_request_passes_.insert(remapped_pass_id); |
766 } | 769 } |
767 } | 770 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 } | 931 } |
929 | 932 |
930 void SurfaceAggregator::SetOutputColorSpace( | 933 void SurfaceAggregator::SetOutputColorSpace( |
931 const gfx::ColorSpace& blending_color_space, | 934 const gfx::ColorSpace& blending_color_space, |
932 const gfx::ColorSpace& output_color_space) { | 935 const gfx::ColorSpace& output_color_space) { |
933 blending_color_space_ = blending_color_space; | 936 blending_color_space_ = blending_color_space; |
934 output_color_space_ = output_color_space; | 937 output_color_space_ = output_color_space; |
935 } | 938 } |
936 | 939 |
937 } // namespace cc | 940 } // namespace cc |
OLD | NEW |