OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 if (!layer_tree_host_impl_->renderer()) | 542 if (!layer_tree_host_impl_->renderer()) |
543 return false; | 543 return false; |
544 | 544 |
545 if (!root_layer()) | 545 if (!root_layer()) |
546 return false; | 546 return false; |
547 | 547 |
548 needs_update_draw_properties_ = false; | 548 needs_update_draw_properties_ = false; |
549 render_surface_layer_list_.clear(); | 549 render_surface_layer_list_.clear(); |
550 | 550 |
551 { | 551 { |
552 TRACE_EVENT2("cc", | 552 TRACE_EVENT2( |
553 "LayerTreeImpl::UpdateDrawProperties", | 553 "cc", "LayerTreeImpl::UpdateDrawProperties::CalculateDrawProperties", |
554 "IsActive", | 554 "IsActive", IsActiveTree(), "SourceFrameNumber", source_frame_number_); |
555 IsActiveTree(), | |
556 "SourceFrameNumber", | |
557 source_frame_number_); | |
558 LayerImpl* page_scale_layer = | 555 LayerImpl* page_scale_layer = |
559 page_scale_layer_ ? page_scale_layer_ : InnerViewportContainerLayer(); | 556 page_scale_layer_ ? page_scale_layer_ : InnerViewportContainerLayer(); |
560 bool can_render_to_separate_surface = | 557 bool can_render_to_separate_surface = |
561 (layer_tree_host_impl_->GetDrawMode() != | 558 (layer_tree_host_impl_->GetDrawMode() != |
562 DRAW_MODE_RESOURCELESS_SOFTWARE); | 559 DRAW_MODE_RESOURCELESS_SOFTWARE); |
563 | 560 |
564 ++render_surface_layer_list_id_; | 561 ++render_surface_layer_list_id_; |
565 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( | 562 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( |
566 root_layer(), DrawViewportSize(), | 563 root_layer(), DrawViewportSize(), |
567 layer_tree_host_impl_->DrawTransform(), device_scale_factor(), | 564 layer_tree_host_impl_->DrawTransform(), device_scale_factor(), |
568 current_page_scale_factor(), page_scale_layer, | 565 current_page_scale_factor(), page_scale_layer, |
569 elastic_overscroll()->Current(IsActiveTree()), | 566 elastic_overscroll()->Current(IsActiveTree()), |
570 overscroll_elasticity_layer_, resource_provider()->max_texture_size(), | 567 overscroll_elasticity_layer_, resource_provider()->max_texture_size(), |
571 settings().can_use_lcd_text, settings().layers_always_allowed_lcd_text, | 568 settings().can_use_lcd_text, settings().layers_always_allowed_lcd_text, |
572 can_render_to_separate_surface, | 569 can_render_to_separate_surface, |
573 settings().layer_transforms_should_scale_layer_contents, | 570 settings().layer_transforms_should_scale_layer_contents, |
574 settings().verify_property_trees, | 571 settings().verify_property_trees, |
575 &render_surface_layer_list_, render_surface_layer_list_id_); | 572 &render_surface_layer_list_, render_surface_layer_list_id_); |
576 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 573 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
577 } | 574 } |
578 | 575 |
579 { | 576 { |
580 TRACE_EVENT_BEGIN2("cc", "LayerTreeImpl::UpdateTilePriorities", "IsActive", | 577 TRACE_EVENT2("cc", "LayerTreeImpl::UpdateDrawProperties::Occlusion", |
581 IsActiveTree(), "SourceFrameNumber", | 578 "IsActive", IsActiveTree(), "SourceFrameNumber", |
582 source_frame_number_); | 579 source_frame_number_); |
583 scoped_ptr<OcclusionTracker<LayerImpl>> occlusion_tracker; | 580 OcclusionTracker<LayerImpl> occlusion_tracker( |
584 if (settings().use_occlusion_for_tile_prioritization) { | 581 root_layer()->render_surface()->content_rect()); |
585 occlusion_tracker.reset(new OcclusionTracker<LayerImpl>( | 582 occlusion_tracker.set_minimum_tracking_size( |
586 root_layer()->render_surface()->content_rect())); | 583 settings().minimum_occlusion_tracking_size); |
587 occlusion_tracker->set_minimum_tracking_size( | |
588 settings().minimum_occlusion_tracking_size); | |
589 } | |
590 | |
591 bool resourceless_software_draw = (layer_tree_host_impl_->GetDrawMode() == | |
592 DRAW_MODE_RESOURCELESS_SOFTWARE); | |
593 | 584 |
594 // LayerIterator is used here instead of CallFunctionForSubtree to only | 585 // LayerIterator is used here instead of CallFunctionForSubtree to only |
595 // UpdateTilePriorities on layers that will be visible (and thus have valid | 586 // UpdateTilePriorities on layers that will be visible (and thus have valid |
596 // draw properties) and not because any ordering is required. | 587 // draw properties) and not because any ordering is required. |
597 typedef LayerIterator<LayerImpl> LayerIteratorType; | 588 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list_); |
598 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); | 589 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list_); |
| 590 it != end; ++it) { |
| 591 occlusion_tracker.EnterLayer(it); |
| 592 |
| 593 // There are very few render targets so this should be cheap to do for |
| 594 // each layer instead of something more complicated. |
| 595 bool inside_replica = false; |
| 596 LayerImpl* layer = it->render_target(); |
| 597 while (layer && !inside_replica) { |
| 598 if (layer->render_target()->has_replica()) |
| 599 inside_replica = true; |
| 600 layer = layer->render_target()->parent(); |
| 601 } |
| 602 |
| 603 // Don't use occlusion if a layer will appear in a replica, since the |
| 604 // tile raster code does not know how to look for the replica and would |
| 605 // consider it occluded even though the replica is visible. |
| 606 // Since occlusion is only used for browser compositor (i.e. |
| 607 // use_occlusion_for_tile_prioritization) and it won't use replicas, |
| 608 // this should matter not. |
| 609 |
| 610 if (it.represents_itself()) { |
| 611 Occlusion occlusion = |
| 612 inside_replica ? Occlusion() |
| 613 : occlusion_tracker.GetCurrentOcclusionForLayer( |
| 614 it->draw_transform()); |
| 615 it->draw_properties().occlusion_in_content_space = occlusion; |
| 616 } |
| 617 |
| 618 if (it.represents_contributing_render_surface()) { |
| 619 // Surfaces aren't used by the tile raster code, so they can have |
| 620 // occlusion regardless of replicas. |
| 621 Occlusion occlusion = |
| 622 occlusion_tracker.GetCurrentOcclusionForContributingSurface( |
| 623 it->render_surface()->draw_transform()); |
| 624 it->render_surface()->set_occlusion_in_content_space(occlusion); |
| 625 // Masks are used to draw the contributing surface, so should have |
| 626 // the same occlusion as the surface (nothing inside the surface |
| 627 // occludes them). |
| 628 if (LayerImpl* mask = it->mask_layer()) { |
| 629 Occlusion mask_occlusion = |
| 630 inside_replica |
| 631 ? Occlusion() |
| 632 : occlusion_tracker.GetCurrentOcclusionForContributingSurface( |
| 633 it->render_surface()->draw_transform() * |
| 634 it->draw_transform()); |
| 635 mask->draw_properties().occlusion_in_content_space = mask_occlusion; |
| 636 } |
| 637 if (LayerImpl* replica = it->replica_layer()) { |
| 638 if (LayerImpl* mask = replica->mask_layer()) |
| 639 mask->draw_properties().occlusion_in_content_space = Occlusion(); |
| 640 } |
| 641 } |
| 642 |
| 643 occlusion_tracker.LeaveLayer(it); |
| 644 } |
| 645 |
| 646 unoccluded_screen_space_region_ = |
| 647 occlusion_tracker.ComputeVisibleRegionInScreen(); |
| 648 } |
| 649 |
| 650 { |
| 651 TRACE_EVENT_BEGIN2("cc", "LayerTreeImpl::UpdateDrawProperties::UpdateTiles", |
| 652 "IsActive", IsActiveTree(), "SourceFrameNumber", |
| 653 source_frame_number_); |
| 654 const bool resourceless_software_draw = |
| 655 (layer_tree_host_impl_->GetDrawMode() == |
| 656 DRAW_MODE_RESOURCELESS_SOFTWARE); |
| 657 static const Occlusion kEmptyOcclusion; |
599 size_t layers_updated_count = 0; | 658 size_t layers_updated_count = 0; |
600 bool tile_priorities_updated = false; | 659 bool tile_priorities_updated = false; |
601 for (LayerIteratorType it = | 660 for (PictureLayerImpl* layer : picture_layers_) { |
602 LayerIteratorType::Begin(&render_surface_layer_list_); | 661 // TODO(danakj): Remove this to fix crbug.com/446751 |
603 it != end; | 662 if (!layer->IsDrawnRenderSurfaceLayerListMember()) |
604 ++it) { | |
605 if (occlusion_tracker) | |
606 occlusion_tracker->EnterLayer(it); | |
607 | |
608 LayerImpl* layer = *it; | |
609 const Occlusion& occlusion_in_content_space = | |
610 occlusion_tracker ? occlusion_tracker->GetCurrentOcclusionForLayer( | |
611 layer->draw_transform()) | |
612 : Occlusion(); | |
613 | |
614 if (it.represents_itself()) { | |
615 tile_priorities_updated |= layer->UpdateTiles( | |
616 occlusion_in_content_space, resourceless_software_draw); | |
617 ++layers_updated_count; | |
618 } | |
619 | |
620 if (!it.represents_contributing_render_surface()) { | |
621 if (occlusion_tracker) | |
622 occlusion_tracker->LeaveLayer(it); | |
623 continue; | 663 continue; |
624 } | 664 ++layers_updated_count; |
625 | 665 const Occlusion& occlusion = |
626 if (layer->mask_layer()) { | 666 settings().use_occlusion_for_tile_prioritization |
627 tile_priorities_updated |= layer->mask_layer()->UpdateTiles( | 667 ? layer->draw_properties().occlusion_in_content_space |
628 occlusion_in_content_space, resourceless_software_draw); | 668 : kEmptyOcclusion; |
629 ++layers_updated_count; | 669 tile_priorities_updated |= |
630 } | 670 layer->UpdateTiles(occlusion, resourceless_software_draw); |
631 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { | |
632 tile_priorities_updated |= | |
633 layer->replica_layer()->mask_layer()->UpdateTiles( | |
634 occlusion_in_content_space, resourceless_software_draw); | |
635 ++layers_updated_count; | |
636 } | |
637 | |
638 if (occlusion_tracker) | |
639 occlusion_tracker->LeaveLayer(it); | |
640 } | 671 } |
641 | 672 |
642 if (tile_priorities_updated) | 673 if (tile_priorities_updated) |
643 DidModifyTilePriorities(); | 674 DidModifyTilePriorities(); |
644 | 675 |
645 TRACE_EVENT_END1("cc", "LayerTreeImpl::UpdateTilePriorities", | 676 TRACE_EVENT_END1("cc", "LayerTreeImpl::UpdateTilePriorities", |
646 "layers_updated_count", layers_updated_count); | 677 "layers_updated_count", layers_updated_count); |
647 } | 678 } |
648 | 679 |
649 DCHECK(!needs_update_draw_properties_) << | 680 DCHECK(!needs_update_draw_properties_) << |
650 "CalcDrawProperties should not set_needs_update_draw_properties()"; | 681 "CalcDrawProperties should not set_needs_update_draw_properties()"; |
651 return true; | 682 return true; |
652 } | 683 } |
653 | 684 |
654 const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const { | 685 const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const { |
655 // If this assert triggers, then the list is dirty. | 686 // If this assert triggers, then the list is dirty. |
656 DCHECK(!needs_update_draw_properties_); | 687 DCHECK(!needs_update_draw_properties_); |
657 return render_surface_layer_list_; | 688 return render_surface_layer_list_; |
658 } | 689 } |
659 | 690 |
| 691 const Region& LayerTreeImpl::UnoccludedScreenSpaceRegion() const { |
| 692 // If this assert triggers, then the render_surface_layer_list_ is dirty, so |
| 693 // the unoccluded_screen_space_region_ is not valid anymore. |
| 694 DCHECK(!needs_update_draw_properties_); |
| 695 return unoccluded_screen_space_region_; |
| 696 } |
| 697 |
660 gfx::Size LayerTreeImpl::ScrollableSize() const { | 698 gfx::Size LayerTreeImpl::ScrollableSize() const { |
661 LayerImpl* root_scroll_layer = OuterViewportScrollLayer() | 699 LayerImpl* root_scroll_layer = OuterViewportScrollLayer() |
662 ? OuterViewportScrollLayer() | 700 ? OuterViewportScrollLayer() |
663 : InnerViewportScrollLayer(); | 701 : InnerViewportScrollLayer(); |
664 if (!root_scroll_layer || root_scroll_layer->children().empty()) | 702 if (!root_scroll_layer || root_scroll_layer->children().empty()) |
665 return gfx::Size(); | 703 return gfx::Size(); |
666 return root_scroll_layer->children()[0]->bounds(); | 704 return root_scroll_layer->children()[0]->bounds(); |
667 } | 705 } |
668 | 706 |
669 LayerImpl* LayerTreeImpl::LayerById(int id) { | 707 LayerImpl* LayerTreeImpl::LayerById(int id) { |
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 scoped_ptr<PendingPageScaleAnimation> pending_animation) { | 1628 scoped_ptr<PendingPageScaleAnimation> pending_animation) { |
1591 pending_page_scale_animation_ = pending_animation.Pass(); | 1629 pending_page_scale_animation_ = pending_animation.Pass(); |
1592 } | 1630 } |
1593 | 1631 |
1594 scoped_ptr<PendingPageScaleAnimation> | 1632 scoped_ptr<PendingPageScaleAnimation> |
1595 LayerTreeImpl::TakePendingPageScaleAnimation() { | 1633 LayerTreeImpl::TakePendingPageScaleAnimation() { |
1596 return pending_page_scale_animation_.Pass(); | 1634 return pending_page_scale_animation_.Pass(); |
1597 } | 1635 } |
1598 | 1636 |
1599 } // namespace cc | 1637 } // namespace cc |
OLD | NEW |