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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 SurfaceAggregator::~SurfaceAggregator() { | 89 SurfaceAggregator::~SurfaceAggregator() { |
89 // Notify client of all surfaces being removed. | 90 // Notify client of all surfaces being removed. |
90 contained_surfaces_.clear(); | 91 contained_surfaces_.clear(); |
91 ProcessAddedAndRemovedSurfaces(); | 92 ProcessAddedAndRemovedSurfaces(); |
92 } | 93 } |
93 | 94 |
94 SurfaceAggregator::PrewalkResult::PrewalkResult() {} | 95 SurfaceAggregator::PrewalkResult::PrewalkResult() {} |
95 | 96 |
96 SurfaceAggregator::PrewalkResult::~PrewalkResult() {} | 97 SurfaceAggregator::PrewalkResult::~PrewalkResult() {} |
97 | 98 |
| 99 // static |
| 100 void SurfaceAggregator::UnrefHelper( |
| 101 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support, |
| 102 const ReturnedResourceArray& resources, |
| 103 BlockingTaskRunner* main_thread_task_runner) { |
| 104 if (compositor_frame_sink_support) |
| 105 compositor_frame_sink_support->UnrefResources(resources); |
| 106 } |
| 107 |
98 // Create a clip rect for an aggregated quad from the original clip rect and | 108 // Create a clip rect for an aggregated quad from the original clip rect and |
99 // the clip rect from the surface it's on. | 109 // the clip rect from the surface it's on. |
100 SurfaceAggregator::ClipData SurfaceAggregator::CalculateClipRect( | 110 SurfaceAggregator::ClipData SurfaceAggregator::CalculateClipRect( |
101 const ClipData& surface_clip, | 111 const ClipData& surface_clip, |
102 const ClipData& quad_clip, | 112 const ClipData& quad_clip, |
103 const gfx::Transform& target_transform) { | 113 const gfx::Transform& target_transform) { |
104 ClipData out_clip; | 114 ClipData out_clip; |
105 if (surface_clip.is_clipped) | 115 if (surface_clip.is_clipped) |
106 out_clip = surface_clip; | 116 out_clip = surface_clip; |
107 | 117 |
108 if (quad_clip.is_clipped) { | 118 if (quad_clip.is_clipped) { |
109 // TODO(jamesr): This only works if target_transform maps integer | 119 // TODO(jamesr): This only works if target_transform maps integer |
110 // rects to integer rects. | 120 // rects to integer rects. |
111 gfx::Rect final_clip = | 121 gfx::Rect final_clip = |
112 MathUtil::MapEnclosingClippedRect(target_transform, quad_clip.rect); | 122 MathUtil::MapEnclosingClippedRect(target_transform, quad_clip.rect); |
113 if (out_clip.is_clipped) | 123 if (out_clip.is_clipped) |
114 out_clip.rect.Intersect(final_clip); | 124 out_clip.rect.Intersect(final_clip); |
115 else | 125 else |
116 out_clip.rect = final_clip; | 126 out_clip.rect = final_clip; |
117 out_clip.is_clipped = true; | 127 out_clip.is_clipped = true; |
118 } | 128 } |
119 | 129 |
120 return out_clip; | 130 return out_clip; |
121 } | 131 } |
122 | 132 |
123 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory, | |
124 const ReturnedResourceArray& resources, | |
125 BlockingTaskRunner* main_thread_task_runner) { | |
126 if (surface_factory) | |
127 surface_factory->UnrefResources(resources); | |
128 } | |
129 | |
130 int SurfaceAggregator::RemapPassId(int surface_local_pass_id, | 133 int SurfaceAggregator::RemapPassId(int surface_local_pass_id, |
131 const SurfaceId& surface_id) { | 134 const SurfaceId& surface_id) { |
132 auto key = std::make_pair(surface_id, surface_local_pass_id); | 135 auto key = std::make_pair(surface_id, surface_local_pass_id); |
133 auto it = render_pass_allocator_map_.find(key); | 136 auto it = render_pass_allocator_map_.find(key); |
134 if (it != render_pass_allocator_map_.end()) { | 137 if (it != render_pass_allocator_map_.end()) { |
135 it->second.in_use = true; | 138 it->second.in_use = true; |
136 return it->second.id; | 139 return it->second.id; |
137 } | 140 } |
138 | 141 |
139 RenderPassInfo render_pass_info; | 142 RenderPassInfo render_pass_info; |
140 render_pass_info.id = next_render_pass_id_++; | 143 render_pass_info.id = next_render_pass_id_++; |
141 render_pass_allocator_map_[key] = render_pass_info; | 144 render_pass_allocator_map_[key] = render_pass_info; |
142 return render_pass_info.id; | 145 return render_pass_info.id; |
143 } | 146 } |
144 | 147 |
145 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { | 148 int SurfaceAggregator::ChildIdForSurface(Surface* surface) { |
146 auto it = surface_id_to_resource_child_id_.find(surface->surface_id()); | 149 auto it = surface_id_to_resource_child_id_.find(surface->surface_id()); |
147 if (it == surface_id_to_resource_child_id_.end()) { | 150 if (it == surface_id_to_resource_child_id_.end()) { |
148 int child_id = | 151 int child_id = provider_->CreateChild( |
149 provider_->CreateChild(base::Bind(&UnrefHelper, surface->factory())); | 152 base::Bind(&UnrefHelper, surface->compositor_frame_sink_support())); |
150 if (surface->factory()) { | 153 if (surface->compositor_frame_sink_support()) { |
151 provider_->SetChildNeedsSyncTokens( | 154 provider_->SetChildNeedsSyncTokens( |
152 child_id, surface->factory()->needs_sync_points()); | 155 child_id, |
| 156 surface->compositor_frame_sink_support()->needs_sync_points()); |
153 } | 157 } |
154 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; | 158 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; |
155 return child_id; | 159 return child_id; |
156 } else { | 160 } else { |
157 return it->second; | 161 return it->second; |
158 } | 162 } |
159 } | 163 } |
160 | 164 |
161 gfx::Rect SurfaceAggregator::DamageRectForSurface( | 165 gfx::Rect SurfaceAggregator::DamageRectForSurface( |
162 const Surface* surface, | 166 const Surface* surface, |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 return gfx::Rect(); | 606 return gfx::Rect(); |
603 } | 607 } |
604 contained_surfaces_[surface_id] = surface->frame_index(); | 608 contained_surfaces_[surface_id] = surface->frame_index(); |
605 if (!surface->HasActiveFrame()) | 609 if (!surface->HasActiveFrame()) |
606 return gfx::Rect(); | 610 return gfx::Rect(); |
607 const CompositorFrame& frame = surface->GetActiveFrame(); | 611 const CompositorFrame& frame = surface->GetActiveFrame(); |
608 int child_id = 0; | 612 int child_id = 0; |
609 // TODO(jbauman): hack for unit tests that don't set up rp | 613 // TODO(jbauman): hack for unit tests that don't set up rp |
610 if (provider_) { | 614 if (provider_) { |
611 child_id = ChildIdForSurface(surface); | 615 child_id = ChildIdForSurface(surface); |
612 if (surface->factory()) | 616 if (surface->compositor_frame_sink_support()) |
613 surface->factory()->RefResources(frame.resource_list); | 617 surface->compositor_frame_sink_support()->RefResources( |
| 618 frame.resource_list); |
614 provider_->ReceiveFromChild(child_id, frame.resource_list); | 619 provider_->ReceiveFromChild(child_id, frame.resource_list); |
615 } | 620 } |
616 CHECK(debug_weak_this.get()); | 621 CHECK(debug_weak_this.get()); |
617 | 622 |
618 std::vector<ResourceId> referenced_resources; | 623 std::vector<ResourceId> referenced_resources; |
619 size_t reserve_size = frame.resource_list.size(); | 624 size_t reserve_size = frame.resource_list.size(); |
620 referenced_resources.reserve(reserve_size); | 625 referenced_resources.reserve(reserve_size); |
621 | 626 |
622 bool invalid_frame = false; | 627 bool invalid_frame = false; |
623 ResourceProvider::ResourceIdMap empty_map; | 628 ResourceProvider::ResourceIdMap empty_map; |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 } | 936 } |
932 | 937 |
933 void SurfaceAggregator::SetOutputColorSpace( | 938 void SurfaceAggregator::SetOutputColorSpace( |
934 const gfx::ColorSpace& blending_color_space, | 939 const gfx::ColorSpace& blending_color_space, |
935 const gfx::ColorSpace& output_color_space) { | 940 const gfx::ColorSpace& output_color_space) { |
936 blending_color_space_ = blending_color_space; | 941 blending_color_space_ = blending_color_space; |
937 output_color_space_ = output_color_space; | 942 output_color_space_ = output_color_space; |
938 } | 943 } |
939 | 944 |
940 } // namespace cc | 945 } // namespace cc |
OLD | NEW |