OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/layers/delegated_renderer_layer_impl.h" | 5 #include "cc/layers/delegated_renderer_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "cc/base/math_util.h" | 12 #include "cc/base/math_util.h" |
13 #include "cc/layers/append_quads_data.h" | 13 #include "cc/layers/append_quads_data.h" |
14 #include "cc/layers/quad_sink.h" | |
15 #include "cc/layers/render_pass_sink.h" | 14 #include "cc/layers/render_pass_sink.h" |
16 #include "cc/output/delegated_frame_data.h" | 15 #include "cc/output/delegated_frame_data.h" |
17 #include "cc/quads/render_pass_draw_quad.h" | 16 #include "cc/quads/render_pass_draw_quad.h" |
18 #include "cc/quads/solid_color_draw_quad.h" | 17 #include "cc/quads/solid_color_draw_quad.h" |
19 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 19 #include "cc/trees/occlusion_tracker.h" |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 | 22 |
23 DelegatedRendererLayerImpl::DelegatedRendererLayerImpl( | 23 DelegatedRendererLayerImpl::DelegatedRendererLayerImpl( |
24 LayerTreeImpl* tree_impl, int id) | 24 LayerTreeImpl* tree_impl, int id) |
25 : LayerImpl(tree_impl, id), | 25 : LayerImpl(tree_impl, id), |
26 have_render_passes_to_push_(false), | 26 have_render_passes_to_push_(false), |
27 child_id_(0), | 27 child_id_(0), |
28 own_child_id_(false) { | 28 own_child_id_(false) { |
29 } | 29 } |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 266 } |
267 | 267 |
268 bool DelegatedRendererLayerImpl::WillDraw(DrawMode draw_mode, | 268 bool DelegatedRendererLayerImpl::WillDraw(DrawMode draw_mode, |
269 ResourceProvider* resource_provider) { | 269 ResourceProvider* resource_provider) { |
270 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) | 270 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) |
271 return false; | 271 return false; |
272 return LayerImpl::WillDraw(draw_mode, resource_provider); | 272 return LayerImpl::WillDraw(draw_mode, resource_provider); |
273 } | 273 } |
274 | 274 |
275 void DelegatedRendererLayerImpl::AppendQuads( | 275 void DelegatedRendererLayerImpl::AppendQuads( |
276 QuadSink* quad_sink, | 276 RenderPass* render_pass, |
| 277 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
277 AppendQuadsData* append_quads_data) { | 278 AppendQuadsData* append_quads_data) { |
278 AppendRainbowDebugBorder(quad_sink, append_quads_data); | 279 AppendRainbowDebugBorder(render_pass, append_quads_data); |
279 | 280 |
280 // This list will be empty after a lost context until a new frame arrives. | 281 // This list will be empty after a lost context until a new frame arrives. |
281 if (render_passes_in_draw_order_.empty()) | 282 if (render_passes_in_draw_order_.empty()) |
282 return; | 283 return; |
283 | 284 |
284 RenderPass::Id target_render_pass_id = append_quads_data->render_pass_id; | 285 RenderPass::Id target_render_pass_id = append_quads_data->render_pass_id; |
285 | 286 |
286 const RenderPass* root_delegated_render_pass = | 287 const RenderPass* root_delegated_render_pass = |
287 render_passes_in_draw_order_.back(); | 288 render_passes_in_draw_order_.back(); |
288 | 289 |
289 DCHECK(root_delegated_render_pass->output_rect.origin().IsOrigin()); | 290 DCHECK(root_delegated_render_pass->output_rect.origin().IsOrigin()); |
290 gfx::Size frame_size = root_delegated_render_pass->output_rect.size(); | 291 gfx::Size frame_size = root_delegated_render_pass->output_rect.size(); |
291 | 292 |
292 // If the index of the RenderPassId is 0, then it is a RenderPass generated | 293 // If the index of the RenderPassId is 0, then it is a RenderPass generated |
293 // for a layer in this compositor, not the delegating renderer. Then we want | 294 // for a layer in this compositor, not the delegating renderer. Then we want |
294 // to merge our root RenderPass with the target RenderPass. Otherwise, it is | 295 // to merge our root RenderPass with the target RenderPass. Otherwise, it is |
295 // some RenderPass which we added from the delegating renderer. | 296 // some RenderPass which we added from the delegating renderer. |
296 bool should_merge_root_render_pass_with_target = !target_render_pass_id.index; | 297 bool should_merge_root_render_pass_with_target = !target_render_pass_id.index; |
297 if (should_merge_root_render_pass_with_target) { | 298 if (should_merge_root_render_pass_with_target) { |
298 // Verify that the RenderPass we are appending to is created by our | 299 // Verify that the RenderPass we are appending to is created by our |
299 // render_target. | 300 // render_target. |
300 DCHECK(target_render_pass_id.layer_id == render_target()->id()); | 301 DCHECK(target_render_pass_id.layer_id == render_target()->id()); |
301 | 302 |
302 AppendRenderPassQuads( | 303 AppendRenderPassQuads(render_pass, |
303 quad_sink, append_quads_data, root_delegated_render_pass, frame_size); | 304 occlusion_tracker, |
| 305 append_quads_data, |
| 306 root_delegated_render_pass, |
| 307 frame_size); |
304 } else { | 308 } else { |
305 // Verify that the RenderPass we are appending to was created by us. | 309 // Verify that the RenderPass we are appending to was created by us. |
306 DCHECK(target_render_pass_id.layer_id == id()); | 310 DCHECK(target_render_pass_id.layer_id == id()); |
307 | 311 |
308 int render_pass_index = IdToIndex(target_render_pass_id.index); | 312 int render_pass_index = IdToIndex(target_render_pass_id.index); |
309 const RenderPass* delegated_render_pass = | 313 const RenderPass* delegated_render_pass = |
310 render_passes_in_draw_order_[render_pass_index]; | 314 render_passes_in_draw_order_[render_pass_index]; |
311 AppendRenderPassQuads( | 315 AppendRenderPassQuads(render_pass, |
312 quad_sink, append_quads_data, delegated_render_pass, frame_size); | 316 occlusion_tracker, |
| 317 append_quads_data, |
| 318 delegated_render_pass, |
| 319 frame_size); |
313 } | 320 } |
314 } | 321 } |
315 | 322 |
316 void DelegatedRendererLayerImpl::AppendRainbowDebugBorder( | 323 void DelegatedRendererLayerImpl::AppendRainbowDebugBorder( |
317 QuadSink* quad_sink, | 324 RenderPass* render_pass, |
318 AppendQuadsData* append_quads_data) { | 325 AppendQuadsData* append_quads_data) { |
319 if (!ShowDebugBorders()) | 326 if (!ShowDebugBorders()) |
320 return; | 327 return; |
321 | 328 |
322 SharedQuadState* shared_quad_state = quad_sink->CreateSharedQuadState(); | 329 SharedQuadState* shared_quad_state = |
| 330 render_pass->CreateAndAppendSharedQuadState(); |
323 PopulateSharedQuadState(shared_quad_state); | 331 PopulateSharedQuadState(shared_quad_state); |
324 | 332 |
325 SkColor color; | 333 SkColor color; |
326 float border_width; | 334 float border_width; |
327 GetDebugBorderProperties(&color, &border_width); | 335 GetDebugBorderProperties(&color, &border_width); |
328 | 336 |
329 SkColor colors[] = { | 337 SkColor colors[] = { |
330 0x80ff0000, // Red. | 338 0x80ff0000, // Red. |
331 0x80ffa500, // Orange. | 339 0x80ffa500, // Orange. |
332 0x80ffff00, // Yellow. | 340 0x80ffff00, // Yellow. |
(...skipping 26 matching lines...) Expand all Loading... |
359 border_width, | 367 border_width, |
360 height); | 368 height); |
361 | 369 |
362 if (top.IsEmpty() && left.IsEmpty()) | 370 if (top.IsEmpty() && left.IsEmpty()) |
363 break; | 371 break; |
364 | 372 |
365 if (!top.IsEmpty()) { | 373 if (!top.IsEmpty()) { |
366 scoped_ptr<SolidColorDrawQuad> top_quad = SolidColorDrawQuad::Create(); | 374 scoped_ptr<SolidColorDrawQuad> top_quad = SolidColorDrawQuad::Create(); |
367 top_quad->SetNew( | 375 top_quad->SetNew( |
368 shared_quad_state, top, top, colors[i % kNumColors], false); | 376 shared_quad_state, top, top, colors[i % kNumColors], false); |
369 quad_sink->Append(top_quad.PassAs<DrawQuad>()); | 377 render_pass->AppendDrawQuad(top_quad.PassAs<DrawQuad>()); |
370 | 378 |
371 scoped_ptr<SolidColorDrawQuad> bottom_quad = SolidColorDrawQuad::Create(); | 379 scoped_ptr<SolidColorDrawQuad> bottom_quad = SolidColorDrawQuad::Create(); |
372 bottom_quad->SetNew(shared_quad_state, | 380 bottom_quad->SetNew(shared_quad_state, |
373 bottom, | 381 bottom, |
374 bottom, | 382 bottom, |
375 colors[kNumColors - 1 - (i % kNumColors)], | 383 colors[kNumColors - 1 - (i % kNumColors)], |
376 false); | 384 false); |
377 quad_sink->Append(bottom_quad.PassAs<DrawQuad>()); | 385 render_pass->AppendDrawQuad(bottom_quad.PassAs<DrawQuad>()); |
378 } | 386 } |
379 if (!left.IsEmpty()) { | 387 if (!left.IsEmpty()) { |
380 scoped_ptr<SolidColorDrawQuad> left_quad = SolidColorDrawQuad::Create(); | 388 scoped_ptr<SolidColorDrawQuad> left_quad = SolidColorDrawQuad::Create(); |
381 left_quad->SetNew(shared_quad_state, | 389 left_quad->SetNew(shared_quad_state, |
382 left, | 390 left, |
383 left, | 391 left, |
384 colors[kNumColors - 1 - (i % kNumColors)], | 392 colors[kNumColors - 1 - (i % kNumColors)], |
385 false); | 393 false); |
386 quad_sink->Append(left_quad.PassAs<DrawQuad>()); | 394 render_pass->AppendDrawQuad(left_quad.PassAs<DrawQuad>()); |
387 | 395 |
388 scoped_ptr<SolidColorDrawQuad> right_quad = SolidColorDrawQuad::Create(); | 396 scoped_ptr<SolidColorDrawQuad> right_quad = SolidColorDrawQuad::Create(); |
389 right_quad->SetNew( | 397 right_quad->SetNew( |
390 shared_quad_state, right, right, colors[i % kNumColors], false); | 398 shared_quad_state, right, right, colors[i % kNumColors], false); |
391 quad_sink->Append(right_quad.PassAs<DrawQuad>()); | 399 render_pass->AppendDrawQuad(right_quad.PassAs<DrawQuad>()); |
392 } | 400 } |
393 } | 401 } |
394 } | 402 } |
395 | 403 |
396 void DelegatedRendererLayerImpl::AppendRenderPassQuads( | 404 void DelegatedRendererLayerImpl::AppendRenderPassQuads( |
397 QuadSink* quad_sink, | 405 RenderPass* render_pass, |
| 406 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
398 AppendQuadsData* append_quads_data, | 407 AppendQuadsData* append_quads_data, |
399 const RenderPass* delegated_render_pass, | 408 const RenderPass* delegated_render_pass, |
400 const gfx::Size& frame_size) const { | 409 const gfx::Size& frame_size) const { |
401 | |
402 const SharedQuadState* delegated_shared_quad_state = NULL; | 410 const SharedQuadState* delegated_shared_quad_state = NULL; |
403 SharedQuadState* output_shared_quad_state = NULL; | 411 SharedQuadState* output_shared_quad_state = NULL; |
404 | 412 |
405 for (size_t i = 0; i < delegated_render_pass->quad_list.size(); ++i) { | 413 for (size_t i = 0; i < delegated_render_pass->quad_list.size(); ++i) { |
406 const DrawQuad* delegated_quad = delegated_render_pass->quad_list[i]; | 414 const DrawQuad* delegated_quad = delegated_render_pass->quad_list[i]; |
407 | 415 |
408 if (delegated_quad->shared_quad_state != delegated_shared_quad_state) { | 416 if (delegated_quad->shared_quad_state != delegated_shared_quad_state) { |
409 delegated_shared_quad_state = delegated_quad->shared_quad_state; | 417 delegated_shared_quad_state = delegated_quad->shared_quad_state; |
410 output_shared_quad_state = quad_sink->CreateSharedQuadState(); | 418 output_shared_quad_state = render_pass->CreateAndAppendSharedQuadState(); |
411 output_shared_quad_state->CopyFrom(delegated_shared_quad_state); | 419 output_shared_quad_state->CopyFrom(delegated_shared_quad_state); |
412 | 420 |
413 bool is_root_delegated_render_pass = | 421 bool is_root_delegated_render_pass = |
414 delegated_render_pass == render_passes_in_draw_order_.back(); | 422 delegated_render_pass == render_passes_in_draw_order_.back(); |
415 if (is_root_delegated_render_pass) { | 423 if (is_root_delegated_render_pass) { |
416 // Don't allow areas inside the bounds that are empty. | 424 // Don't allow areas inside the bounds that are empty. |
417 DCHECK(display_size_.IsEmpty() || | 425 DCHECK(display_size_.IsEmpty() || |
418 gfx::Rect(display_size_).Contains(gfx::Rect(bounds()))); | 426 gfx::Rect(display_size_).Contains(gfx::Rect(bounds()))); |
419 gfx::Transform delegated_frame_to_target_transform = | 427 gfx::Transform delegated_frame_to_target_transform = |
420 draw_transform() * DelegatedFrameToLayerSpaceTransform(frame_size); | 428 draw_transform() * DelegatedFrameToLayerSpaceTransform(frame_size); |
(...skipping 18 matching lines...) Expand all Loading... |
439 } | 447 } |
440 output_shared_quad_state->clip_rect = clip_rect; | 448 output_shared_quad_state->clip_rect = clip_rect; |
441 output_shared_quad_state->is_clipped = true; | 449 output_shared_quad_state->is_clipped = true; |
442 } | 450 } |
443 | 451 |
444 output_shared_quad_state->opacity *= draw_opacity(); | 452 output_shared_quad_state->opacity *= draw_opacity(); |
445 } | 453 } |
446 } | 454 } |
447 DCHECK(output_shared_quad_state); | 455 DCHECK(output_shared_quad_state); |
448 | 456 |
449 gfx::Rect quad_visible_rect = quad_sink->UnoccludedContentRect( | 457 gfx::Rect quad_visible_rect = occlusion_tracker.UnoccludedContentRect( |
450 this, | 458 this->render_target(), |
451 delegated_quad->visible_rect, | 459 delegated_quad->visible_rect, |
452 output_shared_quad_state->content_to_target_transform); | 460 output_shared_quad_state->content_to_target_transform); |
453 if (quad_visible_rect.IsEmpty()) | 461 if (quad_visible_rect.IsEmpty()) |
454 continue; | 462 continue; |
455 | 463 |
456 scoped_ptr<DrawQuad> output_quad; | 464 scoped_ptr<DrawQuad> output_quad; |
457 if (delegated_quad->material != DrawQuad::RENDER_PASS) { | 465 if (delegated_quad->material != DrawQuad::RENDER_PASS) { |
458 output_quad = delegated_quad->Copy(output_shared_quad_state); | 466 output_quad = delegated_quad->Copy(output_shared_quad_state); |
459 output_quad->visible_rect = quad_visible_rect; | 467 output_quad->visible_rect = quad_visible_rect; |
460 } else { | 468 } else { |
(...skipping 12 matching lines...) Expand all Loading... |
473 append_quads_data->render_pass_id); | 481 append_quads_data->render_pass_id); |
474 | 482 |
475 output_quad = RenderPassDrawQuad::MaterialCast(delegated_quad)->Copy( | 483 output_quad = RenderPassDrawQuad::MaterialCast(delegated_quad)->Copy( |
476 output_shared_quad_state, | 484 output_shared_quad_state, |
477 output_contributing_render_pass_id).PassAs<DrawQuad>(); | 485 output_contributing_render_pass_id).PassAs<DrawQuad>(); |
478 output_quad->visible_rect = quad_visible_rect; | 486 output_quad->visible_rect = quad_visible_rect; |
479 } | 487 } |
480 } | 488 } |
481 | 489 |
482 if (output_quad) | 490 if (output_quad) |
483 quad_sink->Append(output_quad.Pass()); | 491 render_pass->AppendDrawQuad(output_quad.Pass()); |
484 } | 492 } |
485 } | 493 } |
486 | 494 |
487 const char* DelegatedRendererLayerImpl::LayerTypeAsString() const { | 495 const char* DelegatedRendererLayerImpl::LayerTypeAsString() const { |
488 return "cc::DelegatedRendererLayerImpl"; | 496 return "cc::DelegatedRendererLayerImpl"; |
489 } | 497 } |
490 | 498 |
491 void DelegatedRendererLayerImpl::ClearChildId() { | 499 void DelegatedRendererLayerImpl::ClearChildId() { |
492 if (!child_id_) | 500 if (!child_id_) |
493 return; | 501 return; |
494 | 502 |
495 if (own_child_id_) { | 503 if (own_child_id_) { |
496 ResourceProvider* provider = layer_tree_impl()->resource_provider(); | 504 ResourceProvider* provider = layer_tree_impl()->resource_provider(); |
497 provider->DestroyChild(child_id_); | 505 provider->DestroyChild(child_id_); |
498 } | 506 } |
499 | 507 |
500 resources_.clear(); | 508 resources_.clear(); |
501 child_id_ = 0; | 509 child_id_ = 0; |
502 } | 510 } |
503 | 511 |
504 } // namespace cc | 512 } // namespace cc |
OLD | NEW |