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

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

Issue 331533002: Use a struct for cc::Surface ids for more type safety (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add is_null and explicit ctor Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « cc/surfaces/surface_aggregator.h ('k') | cc/surfaces/surface_aggregator_test_helpers.h » ('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 "base/containers/hash_tables.h" 7 #include "base/containers/hash_tables.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "cc/output/compositor_frame.h" 9 #include "cc/output/compositor_frame.h"
10 #include "cc/output/delegated_frame_data.h" 10 #include "cc/output/delegated_frame_data.h"
11 #include "cc/quads/draw_quad.h" 11 #include "cc/quads/draw_quad.h"
12 #include "cc/quads/render_pass_draw_quad.h" 12 #include "cc/quads/render_pass_draw_quad.h"
13 #include "cc/quads/shared_quad_state.h" 13 #include "cc/quads/shared_quad_state.h"
14 #include "cc/quads/surface_draw_quad.h" 14 #include "cc/quads/surface_draw_quad.h"
15 #include "cc/surfaces/surface.h" 15 #include "cc/surfaces/surface.h"
16 #include "cc/surfaces/surface_manager.h" 16 #include "cc/surfaces/surface_manager.h"
17 17
18 namespace cc { 18 namespace cc {
19 19
20 SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager) 20 SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager)
21 : manager_(manager) { 21 : manager_(manager) {
22 DCHECK(manager_); 22 DCHECK(manager_);
23 } 23 }
24 24
25 SurfaceAggregator::~SurfaceAggregator() {} 25 SurfaceAggregator::~SurfaceAggregator() {}
26 26
27 DelegatedFrameData* SurfaceAggregator::GetReferencedDataForSurfaceID( 27 DelegatedFrameData* SurfaceAggregator::GetReferencedDataForSurfaceId(
28 int surface_id) { 28 SurfaceId surface_id) {
29 Surface* referenced_surface = manager_->GetSurfaceForID(surface_id); 29 Surface* referenced_surface = manager_->GetSurfaceForId(surface_id);
30 if (!referenced_surface) 30 if (!referenced_surface)
31 return NULL; // Invalid surface id, skip this quad. 31 return NULL; // Invalid surface id, skip this quad.
32 CompositorFrame* referenced_frame = referenced_surface->GetEligibleFrame(); 32 CompositorFrame* referenced_frame = referenced_surface->GetEligibleFrame();
33 if (!referenced_frame) 33 if (!referenced_frame)
34 return NULL; 34 return NULL;
35 return referenced_frame->delegated_frame_data.get(); 35 return referenced_frame->delegated_frame_data.get();
36 } 36 }
37 37
38 class SurfaceAggregator::RenderPassIdAllocator { 38 class SurfaceAggregator::RenderPassIdAllocator {
39 public: 39 public:
(...skipping 27 matching lines...) Expand all
67 if (!allocator) { 67 if (!allocator) {
68 allocator = new RenderPassIdAllocator(surface_id); 68 allocator = new RenderPassIdAllocator(surface_id);
69 render_pass_allocator_map_.set(surface_id, make_scoped_ptr(allocator)); 69 render_pass_allocator_map_.set(surface_id, make_scoped_ptr(allocator));
70 } 70 }
71 allocator->AddKnownPass(surface_local_pass_id); 71 allocator->AddKnownPass(surface_local_pass_id);
72 return allocator->Remap(surface_local_pass_id); 72 return allocator->Remap(surface_local_pass_id);
73 } 73 }
74 74
75 void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad, 75 void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad,
76 RenderPass* dest_pass) { 76 RenderPass* dest_pass) {
77 int surface_id = surface_quad->surface_id; 77 SurfaceId surface_id = surface_quad->surface_id;
78 // If this surface's id is already in our referenced set then it creates 78 // If this surface's id is already in our referenced set then it creates
79 // a cycle in the graph and should be dropped. 79 // a cycle in the graph and should be dropped.
80 if (referenced_surfaces_.count(surface_id)) 80 if (referenced_surfaces_.count(surface_id.id))
81 return; 81 return;
82 DelegatedFrameData* referenced_data = 82 DelegatedFrameData* referenced_data =
83 GetReferencedDataForSurfaceID(surface_id); 83 GetReferencedDataForSurfaceId(surface_id);
84 if (!referenced_data) 84 if (!referenced_data)
85 return; 85 return;
86 std::set<int>::iterator it = referenced_surfaces_.insert(surface_id).first; 86 std::set<int>::iterator it = referenced_surfaces_.insert(surface_id.id).first;
87 87
88 const RenderPassList& referenced_passes = referenced_data->render_pass_list; 88 const RenderPassList& referenced_passes = referenced_data->render_pass_list;
89 for (size_t j = 0; j + 1 < referenced_passes.size(); ++j) { 89 for (size_t j = 0; j + 1 < referenced_passes.size(); ++j) {
90 const RenderPass& source = *referenced_passes[j]; 90 const RenderPass& source = *referenced_passes[j];
91 91
92 scoped_ptr<RenderPass> copy_pass(RenderPass::Create()); 92 scoped_ptr<RenderPass> copy_pass(RenderPass::Create());
93 93
94 RenderPass::Id remapped_pass_id = RemapPassId(source.id, surface_id); 94 RenderPass::Id remapped_pass_id = RemapPassId(source.id, surface_id.id);
95 95
96 copy_pass->SetAll(remapped_pass_id, 96 copy_pass->SetAll(remapped_pass_id,
97 source.output_rect, 97 source.output_rect,
98 source.damage_rect, 98 source.damage_rect,
99 source.transform_to_root_target, 99 source.transform_to_root_target,
100 source.has_transparent_background); 100 source.has_transparent_background);
101 101
102 // Contributing passes aggregated in to the pass list need to take the 102 // Contributing passes aggregated in to the pass list need to take the
103 // transform of the surface quad into account to update their transform to 103 // transform of the surface quad into account to update their transform to
104 // the root surface. 104 // the root surface.
105 // TODO(jamesr): Make sure this is sufficient for surfaces nested several 105 // TODO(jamesr): Make sure this is sufficient for surfaces nested several
106 // levels deep and add tests. 106 // levels deep and add tests.
107 copy_pass->transform_to_root_target.ConcatTransform( 107 copy_pass->transform_to_root_target.ConcatTransform(
108 surface_quad->quadTransform()); 108 surface_quad->quadTransform());
109 109
110 CopyQuadsToPass(source.quad_list, 110 CopyQuadsToPass(source.quad_list,
111 source.shared_quad_state_list, 111 source.shared_quad_state_list,
112 gfx::Transform(), 112 gfx::Transform(),
113 copy_pass.get(), 113 copy_pass.get(),
114 surface_id); 114 surface_id.id);
115 115
116 dest_pass_list_->push_back(copy_pass.Pass()); 116 dest_pass_list_->push_back(copy_pass.Pass());
117 } 117 }
118 118
119 // TODO(jamesr): Clean up last pass special casing. 119 // TODO(jamesr): Clean up last pass special casing.
120 const RenderPass& last_pass = *referenced_data->render_pass_list.back(); 120 const RenderPass& last_pass = *referenced_data->render_pass_list.back();
121 const QuadList& quads = last_pass.quad_list; 121 const QuadList& quads = last_pass.quad_list;
122 122
123 // TODO(jamesr): Make sure clipping is enforced. 123 // TODO(jamesr): Make sure clipping is enforced.
124 CopyQuadsToPass(quads, 124 CopyQuadsToPass(quads,
125 last_pass.shared_quad_state_list, 125 last_pass.shared_quad_state_list,
126 surface_quad->quadTransform(), 126 surface_quad->quadTransform(),
127 dest_pass, 127 dest_pass,
128 surface_id); 128 surface_id.id);
129 129
130 referenced_surfaces_.erase(it); 130 referenced_surfaces_.erase(it);
131 } 131 }
132 132
133 void SurfaceAggregator::CopySharedQuadState( 133 void SurfaceAggregator::CopySharedQuadState(
134 const SharedQuadState* source_sqs, 134 const SharedQuadState* source_sqs,
135 const gfx::Transform& content_to_target_transform, 135 const gfx::Transform& content_to_target_transform,
136 RenderPass* dest_render_pass) { 136 RenderPass* dest_render_pass) {
137 SharedQuadState* copy_shared_quad_state = 137 SharedQuadState* copy_shared_quad_state =
138 dest_render_pass->CreateAndAppendSharedQuadState(); 138 dest_render_pass->CreateAndAppendSharedQuadState();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 CopyQuadsToPass(source.quad_list, 208 CopyQuadsToPass(source.quad_list,
209 source.shared_quad_state_list, 209 source.shared_quad_state_list,
210 gfx::Transform(), 210 gfx::Transform(),
211 copy_pass.get(), 211 copy_pass.get(),
212 surface_id); 212 surface_id);
213 213
214 dest_pass_list_->push_back(copy_pass.Pass()); 214 dest_pass_list_->push_back(copy_pass.Pass());
215 } 215 }
216 } 216 }
217 217
218 scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(int surface_id) { 218 scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(SurfaceId surface_id) {
219 Surface* surface = manager_->GetSurfaceForID(surface_id); 219 Surface* surface = manager_->GetSurfaceForId(surface_id);
220 if (!surface) 220 if (!surface)
221 return scoped_ptr<CompositorFrame>(); 221 return scoped_ptr<CompositorFrame>();
222 CompositorFrame* root_surface_frame = surface->GetEligibleFrame(); 222 CompositorFrame* root_surface_frame = surface->GetEligibleFrame();
223 if (!root_surface_frame) 223 if (!root_surface_frame)
224 return scoped_ptr<CompositorFrame>(); 224 return scoped_ptr<CompositorFrame>();
225 225
226 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 226 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
227 frame->delegated_frame_data = make_scoped_ptr(new DelegatedFrameData); 227 frame->delegated_frame_data = make_scoped_ptr(new DelegatedFrameData);
228 228
229 DCHECK(root_surface_frame->delegated_frame_data); 229 DCHECK(root_surface_frame->delegated_frame_data);
230 230
231 const RenderPassList& source_pass_list = 231 const RenderPassList& source_pass_list =
232 root_surface_frame->delegated_frame_data->render_pass_list; 232 root_surface_frame->delegated_frame_data->render_pass_list;
233 233
234 std::set<int>::iterator it = referenced_surfaces_.insert(surface_id).first; 234 std::set<int>::iterator it = referenced_surfaces_.insert(surface_id.id).first;
235 235
236 dest_pass_list_ = &frame->delegated_frame_data->render_pass_list; 236 dest_pass_list_ = &frame->delegated_frame_data->render_pass_list;
237 CopyPasses(source_pass_list, surface_id); 237 CopyPasses(source_pass_list, surface_id.id);
238 238
239 referenced_surfaces_.erase(it); 239 referenced_surfaces_.erase(it);
240 DCHECK(referenced_surfaces_.empty()); 240 DCHECK(referenced_surfaces_.empty());
241 241
242 dest_pass_list_ = NULL; 242 dest_pass_list_ = NULL;
243 243
244 // TODO(jamesr): Aggregate all resource references into the returned frame's 244 // TODO(jamesr): Aggregate all resource references into the returned frame's
245 // resource list. 245 // resource list.
246 246
247 return frame.Pass(); 247 return frame.Pass();
248 } 248 }
249 249
250 } // namespace cc 250 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_aggregator.h ('k') | cc/surfaces/surface_aggregator_test_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698