| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 ++quad_it) { | 125 ++quad_it) { |
| 126 (*quad_it)->IterateResources(remap); | 126 (*quad_it)->IterateResources(remap); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 if (!invalid_frame) | 129 if (!invalid_frame) |
| 130 provider_->DeclareUsedResourcesFromChild(child_id, referenced_resources); | 130 provider_->DeclareUsedResourcesFromChild(child_id, referenced_resources); |
| 131 | 131 |
| 132 return invalid_frame; | 132 return invalid_frame; |
| 133 } | 133 } |
| 134 | 134 |
| 135 gfx::Rect SurfaceAggregator::DamageRectForSurface(const Surface* surface, |
| 136 const RenderPass& source) { |
| 137 int previous_index = previous_contained_surfaces_[surface->surface_id()]; |
| 138 if (previous_index == surface->frame_index()) |
| 139 return gfx::Rect(); |
| 140 else if (previous_index == surface->frame_index() - 1) |
| 141 return source.damage_rect; |
| 142 return gfx::Rect(surface->size()); |
| 143 } |
| 144 |
| 135 void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad, | 145 void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad, |
| 136 RenderPass* dest_pass) { | 146 RenderPass* dest_pass) { |
| 137 SurfaceId surface_id = surface_quad->surface_id; | 147 SurfaceId surface_id = surface_quad->surface_id; |
| 138 contained_surfaces_->insert(surface_id); | |
| 139 // If this surface's id is already in our referenced set then it creates | 148 // If this surface's id is already in our referenced set then it creates |
| 140 // a cycle in the graph and should be dropped. | 149 // a cycle in the graph and should be dropped. |
| 141 if (referenced_surfaces_.count(surface_id)) | 150 if (referenced_surfaces_.count(surface_id)) |
| 142 return; | 151 return; |
| 143 Surface* surface = manager_->GetSurfaceForId(surface_id); | 152 Surface* surface = manager_->GetSurfaceForId(surface_id); |
| 144 if (!surface) | 153 if (!surface) { |
| 154 contained_surfaces_[surface_id] = 0; |
| 145 return; | 155 return; |
| 156 } |
| 157 contained_surfaces_[surface_id] = surface->frame_index(); |
| 146 const CompositorFrame* frame = surface->GetEligibleFrame(); | 158 const CompositorFrame* frame = surface->GetEligibleFrame(); |
| 147 if (!frame) | 159 if (!frame) |
| 148 return; | 160 return; |
| 149 const DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); | 161 const DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); |
| 150 if (!frame_data) | 162 if (!frame_data) |
| 151 return; | 163 return; |
| 152 | 164 |
| 153 RenderPassList render_pass_list; | 165 RenderPassList render_pass_list; |
| 154 bool invalid_frame = TakeResources(surface, frame_data, &render_pass_list); | 166 bool invalid_frame = TakeResources(surface, frame_data, &render_pass_list); |
| 155 if (invalid_frame) | 167 if (invalid_frame) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // TODO(jamesr): Clean up last pass special casing. | 203 // TODO(jamesr): Clean up last pass special casing. |
| 192 const RenderPass& last_pass = *render_pass_list.back(); | 204 const RenderPass& last_pass = *render_pass_list.back(); |
| 193 const QuadList& quads = last_pass.quad_list; | 205 const QuadList& quads = last_pass.quad_list; |
| 194 | 206 |
| 195 // TODO(jamesr): Make sure clipping is enforced. | 207 // TODO(jamesr): Make sure clipping is enforced. |
| 196 CopyQuadsToPass(quads, | 208 CopyQuadsToPass(quads, |
| 197 last_pass.shared_quad_state_list, | 209 last_pass.shared_quad_state_list, |
| 198 surface_quad->quadTransform(), | 210 surface_quad->quadTransform(), |
| 199 dest_pass, | 211 dest_pass, |
| 200 surface_id); | 212 surface_id); |
| 213 dest_pass->damage_rect = |
| 214 gfx::UnionRects(dest_pass->damage_rect, |
| 215 MathUtil::MapEnclosingClippedRect( |
| 216 surface_quad->quadTransform(), |
| 217 DamageRectForSurface(surface, last_pass))); |
| 201 | 218 |
| 202 referenced_surfaces_.erase(it); | 219 referenced_surfaces_.erase(it); |
| 203 } | 220 } |
| 204 | 221 |
| 205 void SurfaceAggregator::CopySharedQuadState( | 222 void SurfaceAggregator::CopySharedQuadState( |
| 206 const SharedQuadState* source_sqs, | 223 const SharedQuadState* source_sqs, |
| 207 const gfx::Transform& content_to_target_transform, | 224 const gfx::Transform& content_to_target_transform, |
| 208 RenderPass* dest_render_pass) { | 225 RenderPass* dest_render_pass) { |
| 209 SharedQuadState* copy_shared_quad_state = | 226 SharedQuadState* copy_shared_quad_state = |
| 210 dest_render_pass->CreateAndAppendSharedQuadState(); | 227 dest_render_pass->CreateAndAppendSharedQuadState(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 remapped_pass_id); | 278 remapped_pass_id); |
| 262 } else { | 279 } else { |
| 263 dest_pass->CopyFromAndAppendDrawQuad( | 280 dest_pass->CopyFromAndAppendDrawQuad( |
| 264 quad, dest_pass->shared_quad_state_list.back()); | 281 quad, dest_pass->shared_quad_state_list.back()); |
| 265 } | 282 } |
| 266 } | 283 } |
| 267 } | 284 } |
| 268 } | 285 } |
| 269 | 286 |
| 270 void SurfaceAggregator::CopyPasses(const RenderPassList& source_pass_list, | 287 void SurfaceAggregator::CopyPasses(const RenderPassList& source_pass_list, |
| 271 SurfaceId surface_id) { | 288 const Surface* surface) { |
| 272 for (size_t i = 0; i < source_pass_list.size(); ++i) { | 289 for (size_t i = 0; i < source_pass_list.size(); ++i) { |
| 273 const RenderPass& source = *source_pass_list[i]; | 290 const RenderPass& source = *source_pass_list[i]; |
| 274 | 291 |
| 275 scoped_ptr<RenderPass> copy_pass(RenderPass::Create()); | 292 scoped_ptr<RenderPass> copy_pass(RenderPass::Create()); |
| 276 | 293 |
| 277 RenderPassId remapped_pass_id = RemapPassId(source.id, surface_id); | 294 RenderPassId remapped_pass_id = |
| 295 RemapPassId(source.id, surface->surface_id()); |
| 278 | 296 |
| 279 copy_pass->SetAll(remapped_pass_id, | 297 copy_pass->SetAll(remapped_pass_id, |
| 280 source.output_rect, | 298 source.output_rect, |
| 281 source.damage_rect, | 299 DamageRectForSurface(surface, source), |
| 282 source.transform_to_root_target, | 300 source.transform_to_root_target, |
| 283 source.has_transparent_background); | 301 source.has_transparent_background); |
| 284 | 302 |
| 285 CopyQuadsToPass(source.quad_list, | 303 CopyQuadsToPass(source.quad_list, |
| 286 source.shared_quad_state_list, | 304 source.shared_quad_state_list, |
| 287 gfx::Transform(), | 305 gfx::Transform(), |
| 288 copy_pass.get(), | 306 copy_pass.get(), |
| 289 surface_id); | 307 surface->surface_id()); |
| 290 | 308 |
| 291 dest_pass_list_->push_back(copy_pass.Pass()); | 309 dest_pass_list_->push_back(copy_pass.Pass()); |
| 292 } | 310 } |
| 293 } | 311 } |
| 294 | 312 |
| 295 scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate( | 313 scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(SurfaceId surface_id) { |
| 296 SurfaceId surface_id, | |
| 297 std::set<SurfaceId>* contained_surfaces) { | |
| 298 contained_surfaces_ = contained_surfaces; | |
| 299 contained_surfaces_->insert(surface_id); | |
| 300 Surface* surface = manager_->GetSurfaceForId(surface_id); | 314 Surface* surface = manager_->GetSurfaceForId(surface_id); |
| 301 DCHECK(surface); | 315 DCHECK(surface); |
| 316 contained_surfaces_[surface_id] = surface->frame_index(); |
| 302 const CompositorFrame* root_surface_frame = surface->GetEligibleFrame(); | 317 const CompositorFrame* root_surface_frame = surface->GetEligibleFrame(); |
| 303 if (!root_surface_frame) | 318 if (!root_surface_frame) |
| 304 return scoped_ptr<CompositorFrame>(); | 319 return scoped_ptr<CompositorFrame>(); |
| 305 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate"); | 320 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate"); |
| 306 | 321 |
| 307 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 322 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 308 frame->delegated_frame_data = make_scoped_ptr(new DelegatedFrameData); | 323 frame->delegated_frame_data = make_scoped_ptr(new DelegatedFrameData); |
| 309 | 324 |
| 310 DCHECK(root_surface_frame->delegated_frame_data); | 325 DCHECK(root_surface_frame->delegated_frame_data); |
| 311 | 326 |
| 312 RenderPassList source_pass_list; | 327 RenderPassList source_pass_list; |
| 313 | 328 |
| 314 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; | 329 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first; |
| 315 | 330 |
| 316 dest_resource_list_ = &frame->delegated_frame_data->resource_list; | 331 dest_resource_list_ = &frame->delegated_frame_data->resource_list; |
| 317 dest_pass_list_ = &frame->delegated_frame_data->render_pass_list; | 332 dest_pass_list_ = &frame->delegated_frame_data->render_pass_list; |
| 318 | 333 |
| 319 bool invalid_frame = | 334 bool invalid_frame = |
| 320 TakeResources(surface, | 335 TakeResources(surface, |
| 321 root_surface_frame->delegated_frame_data.get(), | 336 root_surface_frame->delegated_frame_data.get(), |
| 322 &source_pass_list); | 337 &source_pass_list); |
| 323 DCHECK(!invalid_frame); | 338 DCHECK(!invalid_frame); |
| 324 | 339 |
| 325 CopyPasses(source_pass_list, surface_id); | 340 CopyPasses(source_pass_list, surface); |
| 326 | 341 |
| 327 referenced_surfaces_.erase(it); | 342 referenced_surfaces_.erase(it); |
| 328 DCHECK(referenced_surfaces_.empty()); | 343 DCHECK(referenced_surfaces_.empty()); |
| 329 | 344 |
| 330 dest_pass_list_ = NULL; | 345 dest_pass_list_ = NULL; |
| 346 contained_surfaces_.swap(previous_contained_surfaces_); |
| 347 contained_surfaces_.clear(); |
| 331 | 348 |
| 332 // TODO(jamesr): Aggregate all resource references into the returned frame's | 349 // TODO(jamesr): Aggregate all resource references into the returned frame's |
| 333 // resource list. | 350 // resource list. |
| 334 | 351 |
| 335 return frame.Pass(); | 352 return frame.Pass(); |
| 336 } | 353 } |
| 337 | 354 |
| 338 } // namespace cc | 355 } // namespace cc |
| OLD | NEW |