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_manager.h" | 30 #include "cc/surfaces/surface_manager.h" |
30 #include "cc/trees/blocking_task_runner.h" | 31 #include "cc/trees/blocking_task_runner.h" |
31 | 32 |
32 namespace cc { | 33 namespace cc { |
33 namespace { | 34 namespace { |
34 | 35 |
35 // Maximum bucket size for the UMA stats. | 36 // Maximum bucket size for the UMA stats. |
36 constexpr int kUmaStatMaxSurfaces = 30; | 37 constexpr int kUmaStatMaxSurfaces = 30; |
37 | 38 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 if (out_clip.is_clipped) | 114 if (out_clip.is_clipped) |
114 out_clip.rect.Intersect(final_clip); | 115 out_clip.rect.Intersect(final_clip); |
115 else | 116 else |
116 out_clip.rect = final_clip; | 117 out_clip.rect = final_clip; |
117 out_clip.is_clipped = true; | 118 out_clip.is_clipped = true; |
118 } | 119 } |
119 | 120 |
120 return out_clip; | 121 return out_clip; |
121 } | 122 } |
122 | 123 |
123 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory, | 124 static void UnrefHelper( |
124 const ReturnedResourceArray& resources, | 125 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support, |
125 BlockingTaskRunner* main_thread_task_runner) { | 126 const ReturnedResourceArray& resources, |
126 if (surface_factory) | 127 BlockingTaskRunner* main_thread_task_runner) { |
127 surface_factory->UnrefResources(resources); | 128 if (compositor_frame_sink_support) |
| 129 compositor_frame_sink_support->UnrefResources(resources); |
128 } | 130 } |
129 | 131 |
130 int SurfaceAggregator::RemapPassId(int surface_local_pass_id, | 132 int SurfaceAggregator::RemapPassId(int surface_local_pass_id, |
131 const SurfaceId& surface_id) { | 133 const SurfaceId& surface_id) { |
132 auto key = std::make_pair(surface_id, surface_local_pass_id); | 134 auto key = std::make_pair(surface_id, surface_local_pass_id); |
133 auto it = render_pass_allocator_map_.find(key); | 135 auto it = render_pass_allocator_map_.find(key); |
134 if (it != render_pass_allocator_map_.end()) { | 136 if (it != render_pass_allocator_map_.end()) { |
135 it->second.in_use = true; | 137 it->second.in_use = true; |
136 return it->second.id; | 138 return it->second.id; |
137 } | 139 } |
138 | 140 |
139 RenderPassInfo render_pass_info; | 141 RenderPassInfo render_pass_info; |
140 render_pass_info.id = next_render_pass_id_++; | 142 render_pass_info.id = next_render_pass_id_++; |
141 render_pass_allocator_map_[key] = render_pass_info; | 143 render_pass_allocator_map_[key] = render_pass_info; |
142 return render_pass_info.id; | 144 return render_pass_info.id; |
143 } | 145 } |
144 | 146 |
145 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { | 147 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { |
146 auto it = surface_id_to_resource_child_id_.find(surface->surface_id()); | 148 auto it = surface_id_to_resource_child_id_.find(surface->surface_id()); |
147 if (it == surface_id_to_resource_child_id_.end()) { | 149 if (it == surface_id_to_resource_child_id_.end()) { |
148 int child_id = | 150 int child_id = provider_->CreateChild( |
149 provider_->CreateChild(base::Bind(&UnrefHelper, surface->factory())); | 151 base::Bind(&UnrefHelper, surface->compositor_frame_sink_support())); |
150 if (surface->factory()) { | 152 if (surface->compositor_frame_sink_support()) { |
151 provider_->SetChildNeedsSyncTokens( | 153 provider_->SetChildNeedsSyncTokens( |
152 child_id, surface->factory()->needs_sync_points()); | 154 child_id, |
| 155 surface->compositor_frame_sink_support()->needs_sync_points()); |
153 } | 156 } |
154 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; | 157 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; |
155 return child_id; | 158 return child_id; |
156 } else { | 159 } else { |
157 return it->second; | 160 return it->second; |
158 } | 161 } |
159 } | 162 } |
160 | 163 |
161 gfx::Rect SurfaceAggregator::DamageRectForSurface( | 164 gfx::Rect SurfaceAggregator::DamageRectForSurface( |
162 const Surface* surface, | 165 const Surface* surface, |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 return gfx::Rect(); | 605 return gfx::Rect(); |
603 } | 606 } |
604 contained_surfaces_[surface_id] = surface->frame_index(); | 607 contained_surfaces_[surface_id] = surface->frame_index(); |
605 if (!surface->HasActiveFrame()) | 608 if (!surface->HasActiveFrame()) |
606 return gfx::Rect(); | 609 return gfx::Rect(); |
607 const CompositorFrame& frame = surface->GetActiveFrame(); | 610 const CompositorFrame& frame = surface->GetActiveFrame(); |
608 int child_id = 0; | 611 int child_id = 0; |
609 // 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 |
610 if (provider_) { | 613 if (provider_) { |
611 child_id = ChildIdForSurface(surface); | 614 child_id = ChildIdForSurface(surface); |
612 if (surface->factory()) | 615 if (surface->compositor_frame_sink_support()) |
613 surface->factory()->RefResources(frame.resource_list); | 616 surface->compositor_frame_sink_support()->RefResources( |
| 617 frame.resource_list); |
614 provider_->ReceiveFromChild(child_id, frame.resource_list); | 618 provider_->ReceiveFromChild(child_id, frame.resource_list); |
615 } | 619 } |
616 CHECK(debug_weak_this.get()); | 620 CHECK(debug_weak_this.get()); |
617 | 621 |
618 std::vector<ResourceId> referenced_resources; | 622 std::vector<ResourceId> referenced_resources; |
619 size_t reserve_size = frame.resource_list.size(); | 623 size_t reserve_size = frame.resource_list.size(); |
620 referenced_resources.reserve(reserve_size); | 624 referenced_resources.reserve(reserve_size); |
621 | 625 |
622 bool invalid_frame = false; | 626 bool invalid_frame = false; |
623 ResourceProvider::ResourceIdMap empty_map; | 627 ResourceProvider::ResourceIdMap empty_map; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 } | 931 } |
928 | 932 |
929 void SurfaceAggregator::SetOutputColorSpace( | 933 void SurfaceAggregator::SetOutputColorSpace( |
930 const gfx::ColorSpace& blending_color_space, | 934 const gfx::ColorSpace& blending_color_space, |
931 const gfx::ColorSpace& output_color_space) { | 935 const gfx::ColorSpace& output_color_space) { |
932 blending_color_space_ = blending_color_space; | 936 blending_color_space_ = blending_color_space; |
933 output_color_space_ = output_color_space; | 937 output_color_space_ = output_color_space; |
934 } | 938 } |
935 | 939 |
936 } // namespace cc | 940 } // namespace cc |
OLD | NEW |