| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 const RenderPass& source) { | 156 const RenderPass& source) { |
| 157 int previous_index = previous_contained_surfaces_[surface->surface_id()]; | 157 int previous_index = previous_contained_surfaces_[surface->surface_id()]; |
| 158 if (previous_index == surface->frame_index()) | 158 if (previous_index == surface->frame_index()) |
| 159 return gfx::Rect(); | 159 return gfx::Rect(); |
| 160 else if (previous_index == surface->frame_index() - 1) | 160 else if (previous_index == surface->frame_index() - 1) |
| 161 return source.damage_rect; | 161 return source.damage_rect; |
| 162 return gfx::Rect(surface->size()); | 162 return gfx::Rect(surface->size()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad, | 165 void SurfaceAggregator::HandleSurfaceQuad(const SurfaceDrawQuad* surface_quad, |
| 166 float opacity, |
| 166 RenderPass* dest_pass) { | 167 RenderPass* dest_pass) { |
| 167 SurfaceId surface_id = surface_quad->surface_id; | 168 SurfaceId surface_id = surface_quad->surface_id; |
| 168 // If this surface's id is already in our referenced set then it creates | 169 // If this surface's id is already in our referenced set then it creates |
| 169 // a cycle in the graph and should be dropped. | 170 // a cycle in the graph and should be dropped. |
| 170 if (referenced_surfaces_.count(surface_id)) | 171 if (referenced_surfaces_.count(surface_id)) |
| 171 return; | 172 return; |
| 172 Surface* surface = manager_->GetSurfaceForId(surface_id); | 173 Surface* surface = manager_->GetSurfaceForId(surface_id); |
| 173 if (!surface) { | 174 if (!surface) { |
| 174 contained_surfaces_[surface_id] = 0; | 175 contained_surfaces_[surface_id] = 0; |
| 175 return; | 176 return; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 MoveMatchingRequests(source.id, ©_requests, ©_pass->copy_requests); | 221 MoveMatchingRequests(source.id, ©_requests, ©_pass->copy_requests); |
| 221 | 222 |
| 222 // Contributing passes aggregated in to the pass list need to take the | 223 // Contributing passes aggregated in to the pass list need to take the |
| 223 // transform of the surface quad into account to update their transform to | 224 // transform of the surface quad into account to update their transform to |
| 224 // the root surface. | 225 // the root surface. |
| 225 // TODO(jamesr): Make sure this is sufficient for surfaces nested several | 226 // TODO(jamesr): Make sure this is sufficient for surfaces nested several |
| 226 // levels deep and add tests. | 227 // levels deep and add tests. |
| 227 copy_pass->transform_to_root_target.ConcatTransform( | 228 copy_pass->transform_to_root_target.ConcatTransform( |
| 228 surface_quad->quadTransform()); | 229 surface_quad->quadTransform()); |
| 229 | 230 |
| 230 CopyQuadsToPass(source.quad_list, | 231 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, |
| 231 source.shared_quad_state_list, | 232 gfx::Transform(), 1.f, copy_pass.get(), surface_id); |
| 232 gfx::Transform(), | |
| 233 copy_pass.get(), | |
| 234 surface_id); | |
| 235 | 233 |
| 236 dest_pass_list_->push_back(copy_pass.Pass()); | 234 dest_pass_list_->push_back(copy_pass.Pass()); |
| 237 } | 235 } |
| 238 | 236 |
| 239 const RenderPass& last_pass = *render_pass_list.back(); | 237 const RenderPass& last_pass = *render_pass_list.back(); |
| 240 if (merge_pass) { | 238 if (merge_pass) { |
| 241 // TODO(jamesr): Clean up last pass special casing. | 239 // TODO(jamesr): Clean up last pass special casing. |
| 242 const QuadList& quads = last_pass.quad_list; | 240 const QuadList& quads = last_pass.quad_list; |
| 243 | 241 |
| 244 // TODO(jamesr): Make sure clipping is enforced. | 242 // TODO(jamesr): Make sure clipping is enforced. |
| 245 CopyQuadsToPass(quads, | 243 CopyQuadsToPass(quads, last_pass.shared_quad_state_list, |
| 246 last_pass.shared_quad_state_list, | |
| 247 surface_quad->quadTransform(), | 244 surface_quad->quadTransform(), |
| 248 dest_pass, | 245 surface_quad->opacity() * opacity, dest_pass, surface_id); |
| 249 surface_id); | |
| 250 } else { | 246 } else { |
| 251 RenderPassId remapped_pass_id = RemapPassId(last_pass.id, surface_id); | 247 RenderPassId remapped_pass_id = RemapPassId(last_pass.id, surface_id); |
| 252 | 248 |
| 253 SharedQuadState* shared_quad_state = | 249 SharedQuadState* shared_quad_state = |
| 254 dest_pass->CreateAndAppendSharedQuadState(); | 250 dest_pass->CreateAndAppendSharedQuadState(); |
| 255 shared_quad_state->CopyFrom(surface_quad->shared_quad_state); | 251 shared_quad_state->CopyFrom(surface_quad->shared_quad_state); |
| 252 shared_quad_state->opacity *= opacity; |
| 256 RenderPassDrawQuad* quad = | 253 RenderPassDrawQuad* quad = |
| 257 dest_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); | 254 dest_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
| 258 quad->SetNew(shared_quad_state, | 255 quad->SetNew(shared_quad_state, |
| 259 surface_quad->rect, | 256 surface_quad->rect, |
| 260 surface_quad->visible_rect, | 257 surface_quad->visible_rect, |
| 261 remapped_pass_id, | 258 remapped_pass_id, |
| 262 0, | 259 0, |
| 263 gfx::Vector2dF(), | 260 gfx::Vector2dF(), |
| 264 gfx::Size(), | 261 gfx::Size(), |
| 265 FilterOperations(), | 262 FilterOperations(), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 293 if (copy_shared_quad_state->is_clipped) { | 290 if (copy_shared_quad_state->is_clipped) { |
| 294 copy_shared_quad_state->clip_rect = MathUtil::MapEnclosingClippedRect( | 291 copy_shared_quad_state->clip_rect = MathUtil::MapEnclosingClippedRect( |
| 295 content_to_target_transform, copy_shared_quad_state->clip_rect); | 292 content_to_target_transform, copy_shared_quad_state->clip_rect); |
| 296 } | 293 } |
| 297 } | 294 } |
| 298 | 295 |
| 299 void SurfaceAggregator::CopyQuadsToPass( | 296 void SurfaceAggregator::CopyQuadsToPass( |
| 300 const QuadList& source_quad_list, | 297 const QuadList& source_quad_list, |
| 301 const SharedQuadStateList& source_shared_quad_state_list, | 298 const SharedQuadStateList& source_shared_quad_state_list, |
| 302 const gfx::Transform& content_to_target_transform, | 299 const gfx::Transform& content_to_target_transform, |
| 300 float opacity, |
| 303 RenderPass* dest_pass, | 301 RenderPass* dest_pass, |
| 304 SurfaceId surface_id) { | 302 SurfaceId surface_id) { |
| 305 const SharedQuadState* last_copied_source_shared_quad_state = NULL; | 303 const SharedQuadState* last_copied_source_shared_quad_state = NULL; |
| 306 | 304 |
| 307 SharedQuadStateList::ConstIterator sqs_iter = | 305 SharedQuadStateList::ConstIterator sqs_iter = |
| 308 source_shared_quad_state_list.begin(); | 306 source_shared_quad_state_list.begin(); |
| 309 for (const auto& quad : source_quad_list) { | 307 for (const auto& quad : source_quad_list) { |
| 310 while (quad->shared_quad_state != *sqs_iter) { | 308 while (quad->shared_quad_state != *sqs_iter) { |
| 311 ++sqs_iter; | 309 ++sqs_iter; |
| 312 DCHECK(sqs_iter != source_shared_quad_state_list.end()); | 310 DCHECK(sqs_iter != source_shared_quad_state_list.end()); |
| 313 } | 311 } |
| 314 DCHECK_EQ(quad->shared_quad_state, *sqs_iter); | 312 DCHECK_EQ(quad->shared_quad_state, *sqs_iter); |
| 315 | 313 |
| 316 if (quad->material == DrawQuad::SURFACE_CONTENT) { | 314 if (quad->material == DrawQuad::SURFACE_CONTENT) { |
| 317 const SurfaceDrawQuad* surface_quad = SurfaceDrawQuad::MaterialCast(quad); | 315 const SurfaceDrawQuad* surface_quad = SurfaceDrawQuad::MaterialCast(quad); |
| 318 HandleSurfaceQuad(surface_quad, dest_pass); | 316 HandleSurfaceQuad(surface_quad, opacity, dest_pass); |
| 319 } else { | 317 } else { |
| 320 if (quad->shared_quad_state != last_copied_source_shared_quad_state) { | 318 if (quad->shared_quad_state != last_copied_source_shared_quad_state) { |
| 321 CopySharedQuadState( | 319 CopySharedQuadState( |
| 322 quad->shared_quad_state, content_to_target_transform, dest_pass); | 320 quad->shared_quad_state, content_to_target_transform, dest_pass); |
| 321 dest_pass->shared_quad_state_list.back()->opacity *= opacity; |
| 323 last_copied_source_shared_quad_state = quad->shared_quad_state; | 322 last_copied_source_shared_quad_state = quad->shared_quad_state; |
| 324 } | 323 } |
| 325 if (quad->material == DrawQuad::RENDER_PASS) { | 324 if (quad->material == DrawQuad::RENDER_PASS) { |
| 326 const RenderPassDrawQuad* pass_quad = | 325 const RenderPassDrawQuad* pass_quad = |
| 327 RenderPassDrawQuad::MaterialCast(quad); | 326 RenderPassDrawQuad::MaterialCast(quad); |
| 328 RenderPassId original_pass_id = pass_quad->render_pass_id; | 327 RenderPassId original_pass_id = pass_quad->render_pass_id; |
| 329 RenderPassId remapped_pass_id = | 328 RenderPassId remapped_pass_id = |
| 330 RemapPassId(original_pass_id, surface_id); | 329 RemapPassId(original_pass_id, surface_id); |
| 331 | 330 |
| 332 dest_pass->CopyFromAndAppendRenderPassDrawQuad( | 331 dest_pass->CopyFromAndAppendRenderPassDrawQuad( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 363 |
| 365 RenderPassId remapped_pass_id = | 364 RenderPassId remapped_pass_id = |
| 366 RemapPassId(source.id, surface->surface_id()); | 365 RemapPassId(source.id, surface->surface_id()); |
| 367 | 366 |
| 368 copy_pass->SetAll(remapped_pass_id, | 367 copy_pass->SetAll(remapped_pass_id, |
| 369 source.output_rect, | 368 source.output_rect, |
| 370 DamageRectForSurface(surface, source), | 369 DamageRectForSurface(surface, source), |
| 371 source.transform_to_root_target, | 370 source.transform_to_root_target, |
| 372 source.has_transparent_background); | 371 source.has_transparent_background); |
| 373 | 372 |
| 374 CopyQuadsToPass(source.quad_list, | 373 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, |
| 375 source.shared_quad_state_list, | 374 gfx::Transform(), 1.f, copy_pass.get(), |
| 376 gfx::Transform(), | |
| 377 copy_pass.get(), | |
| 378 surface->surface_id()); | 375 surface->surface_id()); |
| 379 | 376 |
| 380 dest_pass_list_->push_back(copy_pass.Pass()); | 377 dest_pass_list_->push_back(copy_pass.Pass()); |
| 381 } | 378 } |
| 382 } | 379 } |
| 383 | 380 |
| 384 void SurfaceAggregator::RemoveUnreferencedChildren() { | 381 void SurfaceAggregator::RemoveUnreferencedChildren() { |
| 385 for (const auto& surface : previous_contained_surfaces_) { | 382 for (const auto& surface : previous_contained_surfaces_) { |
| 386 if (!contained_surfaces_.count(surface.first)) { | 383 if (!contained_surfaces_.count(surface.first)) { |
| 387 SurfaceToResourceChildIdMap::iterator it = | 384 SurfaceToResourceChildIdMap::iterator it = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 surface->TakeLatencyInfo(&frame->metadata.latency_info); | 428 surface->TakeLatencyInfo(&frame->metadata.latency_info); |
| 432 } | 429 } |
| 433 | 430 |
| 434 // TODO(jamesr): Aggregate all resource references into the returned frame's | 431 // TODO(jamesr): Aggregate all resource references into the returned frame's |
| 435 // resource list. | 432 // resource list. |
| 436 | 433 |
| 437 return frame.Pass(); | 434 return frame.Pass(); |
| 438 } | 435 } |
| 439 | 436 |
| 440 } // namespace cc | 437 } // namespace cc |
| OLD | NEW |