| 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_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/containers/adapters.h" |
| 11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 12 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
| 13 #include "cc/layers/heads_up_display_layer_impl.h" | 14 #include "cc/layers/heads_up_display_layer_impl.h" |
| 14 #include "cc/layers/layer.h" | 15 #include "cc/layers/layer.h" |
| 15 #include "cc/layers/layer_impl.h" | 16 #include "cc/layers/layer_impl.h" |
| 16 #include "cc/layers/layer_iterator.h" | 17 #include "cc/layers/layer_iterator.h" |
| 17 #include "cc/proto/begin_main_frame_and_commit_state.pb.h" | 18 #include "cc/proto/begin_main_frame_and_commit_state.pb.h" |
| 18 #include "cc/proto/gfx_conversions.h" | 19 #include "cc/proto/gfx_conversions.h" |
| 19 #include "cc/trees/draw_property_utils.h" | 20 #include "cc/trees/draw_property_utils.h" |
| 20 #include "cc/trees/layer_tree_host.h" | 21 #include "cc/trees/layer_tree_host.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 gfx::Rect layer_in_surface_space = | 242 gfx::Rect layer_in_surface_space = |
| 242 MathUtil::MapEnclosingClippedRect(transform, layer_bound_rect); | 243 MathUtil::MapEnclosingClippedRect(transform, layer_bound_rect); |
| 243 return CalculateVisibleRectWithCachedLayerRect( | 244 return CalculateVisibleRectWithCachedLayerRect( |
| 244 target_surface_rect, layer_bound_rect, layer_in_surface_space, transform); | 245 target_surface_rect, layer_bound_rect, layer_in_surface_space, transform); |
| 245 } | 246 } |
| 246 | 247 |
| 247 static inline bool IsRootLayer(const Layer* layer) { | 248 static inline bool IsRootLayer(const Layer* layer) { |
| 248 return !layer->parent(); | 249 return !layer->parent(); |
| 249 } | 250 } |
| 250 | 251 |
| 251 static inline bool IsRootLayer(const LayerImpl* layer) { | |
| 252 return layer->layer_tree_impl()->IsRootLayer(layer); | |
| 253 } | |
| 254 | |
| 255 template <typename LayerType> | 252 template <typename LayerType> |
| 256 static bool HasInvertibleOrAnimatedTransform(LayerType* layer) { | 253 static bool HasInvertibleOrAnimatedTransform(LayerType* layer) { |
| 257 return layer->transform_is_invertible() || | 254 return layer->transform_is_invertible() || |
| 258 layer->HasPotentiallyRunningTransformAnimation(); | 255 layer->HasPotentiallyRunningTransformAnimation(); |
| 259 } | 256 } |
| 260 | 257 |
| 261 static inline void MarkLayerWithRenderSurfaceLayerListId( | 258 static inline void MarkLayerWithRenderSurfaceLayerListId( |
| 262 LayerImpl* layer, | 259 LayerImpl* layer, |
| 263 int current_render_surface_layer_list_id) { | 260 int current_render_surface_layer_list_id) { |
| 264 layer->draw_properties().last_drawn_render_surface_layer_list_id = | 261 layer->draw_properties().last_drawn_render_surface_layer_list_id = |
| 265 current_render_surface_layer_list_id; | 262 current_render_surface_layer_list_id; |
| 266 layer->set_layer_or_descendant_is_drawn( | |
| 267 !!current_render_surface_layer_list_id); | |
| 268 } | 263 } |
| 269 | 264 |
| 270 static inline void MarkMasksWithRenderSurfaceLayerListId( | 265 static inline void MarkMasksWithRenderSurfaceLayerListId( |
| 271 LayerImpl* layer, | 266 LayerImpl* layer, |
| 272 int current_render_surface_layer_list_id) { | 267 int current_render_surface_layer_list_id) { |
| 273 if (layer->mask_layer()) { | 268 if (layer->mask_layer()) { |
| 274 MarkLayerWithRenderSurfaceLayerListId(layer->mask_layer(), | 269 MarkLayerWithRenderSurfaceLayerListId(layer->mask_layer(), |
| 275 current_render_surface_layer_list_id); | 270 current_render_surface_layer_list_id); |
| 276 } | 271 } |
| 277 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { | 272 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { |
| 278 MarkLayerWithRenderSurfaceLayerListId(layer->replica_layer()->mask_layer(), | 273 MarkLayerWithRenderSurfaceLayerListId(layer->replica_layer()->mask_layer(), |
| 279 current_render_surface_layer_list_id); | 274 current_render_surface_layer_list_id); |
| 280 } | 275 } |
| 281 } | 276 } |
| 282 | 277 |
| 283 static inline void MarkLayerListWithRenderSurfaceLayerListId( | 278 static inline void ClearRenderSurfaceLayerListId(LayerImplList* layer_list, |
| 284 LayerImplList* layer_list, | 279 ScrollTree* scroll_tree) { |
| 285 int current_render_surface_layer_list_id) { | 280 const int cleared_render_surface_layer_list_id = 0; |
| 286 for (LayerImplList::iterator it = layer_list->begin(); | 281 for (LayerImpl* layer : *layer_list) { |
| 287 it != layer_list->end(); ++it) { | 282 if (layer->IsDrawnRenderSurfaceLayerListMember()) { |
| 288 MarkLayerWithRenderSurfaceLayerListId(*it, | 283 DCHECK_GT(scroll_tree->Node(layer->scroll_tree_index()) |
| 289 current_render_surface_layer_list_id); | 284 ->data.num_drawn_descendants, |
| 290 MarkMasksWithRenderSurfaceLayerListId(*it, | 285 0); |
| 291 current_render_surface_layer_list_id); | 286 scroll_tree->Node(layer->scroll_tree_index()) |
| 287 ->data.num_drawn_descendants--; |
| 288 } |
| 289 MarkLayerWithRenderSurfaceLayerListId(layer, |
| 290 cleared_render_surface_layer_list_id); |
| 291 MarkMasksWithRenderSurfaceLayerListId(layer, |
| 292 cleared_render_surface_layer_list_id); |
| 292 } | 293 } |
| 293 } | 294 } |
| 294 | 295 |
| 295 static inline void RemoveSurfaceForEarlyExit( | |
| 296 LayerImpl* layer_to_remove, | |
| 297 LayerImplList* render_surface_layer_list) { | |
| 298 DCHECK(layer_to_remove->render_surface()); | |
| 299 // Technically, we know that the layer we want to remove should be | |
| 300 // at the back of the render_surface_layer_list. However, we have had | |
| 301 // bugs before that added unnecessary layers here | |
| 302 // (https://bugs.webkit.org/show_bug.cgi?id=74147), but that causes | |
| 303 // things to crash. So here we proactively remove any additional | |
| 304 // layers from the end of the list. | |
| 305 while (render_surface_layer_list->back() != layer_to_remove) { | |
| 306 MarkLayerListWithRenderSurfaceLayerListId( | |
| 307 &render_surface_layer_list->back()->render_surface()->layer_list(), 0); | |
| 308 MarkLayerWithRenderSurfaceLayerListId(render_surface_layer_list->back(), 0); | |
| 309 | |
| 310 render_surface_layer_list->back()->ClearRenderSurfaceLayerList(); | |
| 311 render_surface_layer_list->pop_back(); | |
| 312 } | |
| 313 DCHECK_EQ(render_surface_layer_list->back(), layer_to_remove); | |
| 314 MarkLayerListWithRenderSurfaceLayerListId( | |
| 315 &layer_to_remove->render_surface()->layer_list(), 0); | |
| 316 MarkLayerWithRenderSurfaceLayerListId(layer_to_remove, 0); | |
| 317 render_surface_layer_list->pop_back(); | |
| 318 layer_to_remove->ClearRenderSurfaceLayerList(); | |
| 319 } | |
| 320 | |
| 321 struct PreCalculateMetaInformationRecursiveData { | 296 struct PreCalculateMetaInformationRecursiveData { |
| 322 size_t num_unclipped_descendants; | 297 size_t num_unclipped_descendants; |
| 323 int num_layer_or_descendants_with_copy_request; | 298 int num_layer_or_descendants_with_copy_request; |
| 324 int num_layer_or_descendants_with_touch_handler; | 299 int num_layer_or_descendants_with_touch_handler; |
| 325 int num_descendants_that_draw_content; | 300 int num_descendants_that_draw_content; |
| 326 | 301 |
| 327 PreCalculateMetaInformationRecursiveData() | 302 PreCalculateMetaInformationRecursiveData() |
| 328 : num_unclipped_descendants(0), | 303 : num_unclipped_descendants(0), |
| 329 num_layer_or_descendants_with_copy_request(0), | 304 num_layer_or_descendants_with_copy_request(0), |
| 330 num_layer_or_descendants_with_touch_handler(0), | 305 num_layer_or_descendants_with_touch_handler(0), |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 } | 495 } |
| 521 } | 496 } |
| 522 return jitter; | 497 return jitter; |
| 523 } | 498 } |
| 524 | 499 |
| 525 enum PropertyTreeOption { | 500 enum PropertyTreeOption { |
| 526 BUILD_PROPERTY_TREES_IF_NEEDED, | 501 BUILD_PROPERTY_TREES_IF_NEEDED, |
| 527 DONT_BUILD_PROPERTY_TREES | 502 DONT_BUILD_PROPERTY_TREES |
| 528 }; | 503 }; |
| 529 | 504 |
| 530 static void MarkMasksAndAddChildToDescendantsIfRequired( | 505 static void ComputeLayerScrollsDrawnDescendants(LayerTreeImpl* layer_tree_impl, |
| 531 LayerImpl* child_layer, | 506 ScrollTree* scroll_tree) { |
| 532 LayerImplList* descendants, | 507 for (int i = static_cast<int>(scroll_tree->size()) - 1; i > 0; --i) { |
| 533 const int current_render_surface_layer_list_id) { | 508 ScrollNode* node = scroll_tree->Node(i); |
| 534 // If the child is its own render target, then it has a render surface. | 509 scroll_tree->parent(node)->data.num_drawn_descendants += |
| 535 if (child_layer->has_render_surface() && | 510 node->data.num_drawn_descendants; |
| 536 child_layer->render_target() == child_layer->render_surface() && | 511 } |
| 537 !child_layer->render_surface()->layer_list().empty() && | 512 for (LayerImpl* layer : *layer_tree_impl) { |
| 538 !child_layer->render_surface()->content_rect().IsEmpty()) { | 513 bool scrolls_drawn_descendant = false; |
| 539 // This child will contribute its render surface, which means | 514 if (layer->scrollable()) { |
| 540 // we need to mark just the mask layer (and replica mask layer) | 515 ScrollNode* node = scroll_tree->Node(layer->scroll_tree_index()); |
| 541 // with the id. | 516 if (node->data.num_drawn_descendants > 0) |
| 542 MarkMasksWithRenderSurfaceLayerListId(child_layer, | 517 scrolls_drawn_descendant = true; |
| 543 current_render_surface_layer_list_id); | 518 } |
| 544 descendants->push_back(child_layer); | 519 layer->set_scrolls_drawn_descendant(scrolls_drawn_descendant); |
| 545 } | 520 } |
| 546 } | 521 } |
| 547 | 522 |
| 548 static void SetLayerOrDescendantIsDrawnIfRequired(LayerImpl* layer, | 523 static void ComputeInitialRenderSurfaceLayerList( |
| 549 LayerImpl* child_layer) { | 524 LayerTreeImpl* layer_tree_impl, |
| 550 if (child_layer->layer_or_descendant_is_drawn()) { | |
| 551 layer->set_layer_or_descendant_is_drawn(true); | |
| 552 } | |
| 553 } | |
| 554 | |
| 555 void CalculateRenderSurfaceLayerList( | |
| 556 LayerImpl* layer, | |
| 557 PropertyTrees* property_trees, | 525 PropertyTrees* property_trees, |
| 558 LayerImplList* render_surface_layer_list, | 526 LayerImplList* render_surface_layer_list, |
| 559 LayerImplList* descendants, | 527 bool can_render_to_separate_surface, |
| 560 RenderSurfaceImpl* nearest_occlusion_immune_ancestor, | 528 int current_render_surface_layer_list_id) { |
| 561 bool subtree_visible_from_ancestor, | 529 ScrollTree* scroll_tree = &property_trees->scroll_tree; |
| 530 for (int i = 0; i < static_cast<int>(scroll_tree->size()); ++i) |
| 531 scroll_tree->Node(i)->data.num_drawn_descendants = 0; |
| 532 |
| 533 // Add all non-skipped surfaces to the initial render surface layer list. Add |
| 534 // all non-skipped layers to the layer list of their target surface, and |
| 535 // add their content rect to their target surface's accumulated content rect. |
| 536 for (LayerImpl* layer : *layer_tree_impl) { |
| 537 if (layer->render_surface()) |
| 538 layer->ClearRenderSurfaceLayerList(); |
| 539 |
| 540 bool layer_is_drawn = |
| 541 property_trees->effect_tree.Node(layer->effect_tree_index()) |
| 542 ->data.is_drawn; |
| 543 bool is_root = layer_tree_impl->IsRootLayer(layer); |
| 544 bool skip_layer = |
| 545 !is_root && draw_property_utils::LayerShouldBeSkipped( |
| 546 layer, layer_is_drawn, property_trees->transform_tree, |
| 547 property_trees->effect_tree); |
| 548 if (skip_layer) |
| 549 continue; |
| 550 |
| 551 bool render_to_separate_surface = |
| 552 is_root || (can_render_to_separate_surface && layer->render_surface()); |
| 553 |
| 554 if (render_to_separate_surface) { |
| 555 DCHECK(layer->render_surface()); |
| 556 DCHECK(layer->render_target() == layer->render_surface()); |
| 557 RenderSurfaceImpl* surface = layer->render_surface(); |
| 558 surface->ClearAccumulatedContentRect(); |
| 559 render_surface_layer_list->push_back(layer); |
| 560 if (is_root) { |
| 561 // The root surface does not contribute to any other surface, it has no |
| 562 // target. |
| 563 layer->render_surface()->set_contributes_to_drawn_surface(false); |
| 564 } else { |
| 565 surface->render_target()->layer_list().push_back(layer); |
| 566 bool contributes_to_drawn_surface = |
| 567 property_trees->effect_tree.ContributesToDrawnSurface( |
| 568 layer->effect_tree_index()); |
| 569 layer->render_surface()->set_contributes_to_drawn_surface( |
| 570 contributes_to_drawn_surface); |
| 571 } |
| 572 |
| 573 draw_property_utils::ComputeSurfaceDrawProperties(property_trees, |
| 574 surface); |
| 575 |
| 576 // Ignore occlusion from outside the surface when surface contents need to |
| 577 // be fully drawn. Layers with copy-request need to be complete. We could |
| 578 // be smarter about layers with replica and exclude regions where both |
| 579 // layer and the replica are occluded, but this seems like overkill. The |
| 580 // same is true for layers with filters that move pixels. |
| 581 // TODO(senorblanco): make this smarter for the SkImageFilter case (check |
| 582 // for pixel-moving filters) |
| 583 bool is_occlusion_immune = layer->HasCopyRequest() || |
| 584 layer->has_replica() || |
| 585 layer->filters().HasReferenceFilter() || |
| 586 layer->filters().HasFilterThatMovesPixels(); |
| 587 if (is_occlusion_immune) { |
| 588 surface->SetNearestOcclusionImmuneAncestor(surface); |
| 589 } else if (is_root) { |
| 590 surface->SetNearestOcclusionImmuneAncestor(nullptr); |
| 591 } else { |
| 592 surface->SetNearestOcclusionImmuneAncestor( |
| 593 surface->render_target()->nearest_occlusion_immune_ancestor()); |
| 594 } |
| 595 } |
| 596 bool layer_should_be_drawn = draw_property_utils::LayerNeedsUpdate( |
| 597 layer, layer_is_drawn, property_trees->transform_tree); |
| 598 if (!layer_should_be_drawn) |
| 599 continue; |
| 600 |
| 601 MarkLayerWithRenderSurfaceLayerListId(layer, |
| 602 current_render_surface_layer_list_id); |
| 603 scroll_tree->Node(layer->scroll_tree_index())->data.num_drawn_descendants++; |
| 604 layer->render_target()->layer_list().push_back(layer); |
| 605 |
| 606 // The layer contributes its drawable content rect to its render target. |
| 607 layer->render_target()->AccumulateContentRectFromContributingLayer(layer); |
| 608 } |
| 609 } |
| 610 |
| 611 static void ComputeSurfaceContentRects(LayerTreeImpl* layer_tree_impl, |
| 612 PropertyTrees* property_trees, |
| 613 LayerImplList* render_surface_layer_list, |
| 614 int max_texture_size) { |
| 615 // Walk the list backwards, accumulating each surface's content rect into its |
| 616 // target's content rect. |
| 617 for (LayerImpl* layer : base::Reversed(*render_surface_layer_list)) { |
| 618 if (layer_tree_impl->IsRootLayer(layer)) { |
| 619 // The root layer's surface content rect is always the entire viewport. |
| 620 gfx::Rect viewport = |
| 621 gfx::ToEnclosingRect(property_trees->clip_tree.ViewportClip()); |
| 622 layer->render_surface()->SetContentRect(viewport); |
| 623 continue; |
| 624 } |
| 625 |
| 626 RenderSurfaceImpl* surface = layer->render_surface(); |
| 627 gfx::Rect surface_content_rect = surface->accumulated_content_rect(); |
| 628 |
| 629 if (!layer->replica_layer() && !layer->HasCopyRequest() && |
| 630 surface->is_clipped()) { |
| 631 // Here, we clip the render surface's content rect with its clip rect. |
| 632 // As the clip rect of render surface is in the surface's target |
| 633 // space, we first map the content rect into the target space, |
| 634 // intersect it with clip rect and project back the result to the |
| 635 // surface space. |
| 636 if (!surface_content_rect.IsEmpty()) { |
| 637 gfx::Rect surface_clip_rect = LayerTreeHostCommon::CalculateVisibleRect( |
| 638 surface->clip_rect(), surface_content_rect, |
| 639 surface->draw_transform()); |
| 640 surface_content_rect.Intersect(surface_clip_rect); |
| 641 } |
| 642 } |
| 643 // The RenderSurfaceImpl backing texture cannot exceed the maximum |
| 644 // supported texture size. |
| 645 surface_content_rect.set_width( |
| 646 std::min(surface_content_rect.width(), max_texture_size)); |
| 647 surface_content_rect.set_height( |
| 648 std::min(surface_content_rect.height(), max_texture_size)); |
| 649 surface->SetContentRect(surface_content_rect); |
| 650 |
| 651 // Now the render surface's content rect is calculated correctly, it could |
| 652 // contribute to its render target. |
| 653 surface->render_target() |
| 654 ->AccumulateContentRectFromContributingRenderSurface(surface); |
| 655 } |
| 656 } |
| 657 |
| 658 static void ComputeListOfNonEmptySurfaces( |
| 659 LayerTreeImpl* layer_tree_impl, |
| 660 PropertyTrees* property_trees, |
| 661 LayerImplList* initial_surface_list, |
| 662 LayerImplList* final_surface_list, |
| 663 int current_render_surface_layer_list_id) { |
| 664 // Walk the initial surface list forwards. The root surface and each |
| 665 // surface with a non-empty content rect go into the final render surface |
| 666 // layer list. Surfaces with empty content rects or whose target isn't in |
| 667 // the final list do not get added to the final list. |
| 668 for (LayerImpl* layer : *initial_surface_list) { |
| 669 bool is_root = layer_tree_impl->IsRootLayer(layer); |
| 670 RenderSurfaceImpl* surface = layer->render_surface(); |
| 671 RenderSurfaceImpl* target_surface = surface->render_target(); |
| 672 if (!is_root && (surface->content_rect().IsEmpty() || |
| 673 target_surface->layer_list().empty())) { |
| 674 ClearRenderSurfaceLayerListId(&surface->layer_list(), |
| 675 &property_trees->scroll_tree); |
| 676 surface->ClearLayerLists(); |
| 677 if (!is_root) { |
| 678 LayerImplList& target_list = target_surface->layer_list(); |
| 679 auto it = std::find(target_list.begin(), target_list.end(), layer); |
| 680 if (it != target_list.end()) { |
| 681 target_list.erase(it); |
| 682 // This surface has an empty content rect. If its target's layer list |
| 683 // had no other layers, then its target would also have had an empty |
| 684 // content rect, meaning it would have been removed and had its layer |
| 685 // list cleared when we visited it, unless the target surface is the |
| 686 // root surface. |
| 687 DCHECK(!target_surface->layer_list().empty() || |
| 688 target_surface->render_target() == target_surface); |
| 689 } else { |
| 690 // This layer was removed when the target itself was cleared. |
| 691 DCHECK(target_surface->layer_list().empty()); |
| 692 } |
| 693 } |
| 694 continue; |
| 695 } |
| 696 MarkMasksWithRenderSurfaceLayerListId(layer, |
| 697 current_render_surface_layer_list_id); |
| 698 final_surface_list->push_back(layer); |
| 699 } |
| 700 } |
| 701 |
| 702 static void CalculateRenderSurfaceLayerList( |
| 703 LayerTreeImpl* layer_tree_impl, |
| 704 PropertyTrees* property_trees, |
| 705 LayerImplList* render_surface_layer_list, |
| 562 const bool can_render_to_separate_surface, | 706 const bool can_render_to_separate_surface, |
| 563 const int current_render_surface_layer_list_id, | 707 const int current_render_surface_layer_list_id, |
| 564 const int max_texture_size) { | 708 const int max_texture_size) { |
| 565 // This calculates top level Render Surface Layer List, and Layer List for all | 709 // This calculates top level Render Surface Layer List, and Layer List for all |
| 566 // Render Surfaces. | 710 // Render Surfaces. |
| 567 | |
| 568 // |layer| is current layer. | |
| 569 | |
| 570 // |render_surface_layer_list| is the top level RenderSurfaceLayerList. | 711 // |render_surface_layer_list| is the top level RenderSurfaceLayerList. |
| 571 | 712 |
| 572 // |descendants| is used to determine what's in current layer's render | 713 LayerImplList initial_render_surface_list; |
| 573 // surface's layer list. | 714 |
| 574 | 715 // First compute an RSLL that might include surfaces that later turn out to |
| 575 // |subtree_visible_from_ancestor| is set during recursion to affect current | 716 // have an empty content rect. After surface content rects are computed, |
| 576 // layer's subtree. | 717 // produce a final RSLL that omits empty surfaces. |
| 577 | 718 ComputeInitialRenderSurfaceLayerList( |
| 578 // |can_render_to_separate_surface| and |current_render_surface_layer_list_id| | 719 layer_tree_impl, property_trees, &initial_render_surface_list, |
| 579 // are settings that should stay the same during recursion. | 720 can_render_to_separate_surface, current_render_surface_layer_list_id); |
| 580 bool layer_is_drawn = false; | 721 ComputeSurfaceContentRects(layer_tree_impl, property_trees, |
| 581 DCHECK_GE(layer->effect_tree_index(), 0); | 722 &initial_render_surface_list, max_texture_size); |
| 582 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index()) | 723 ComputeListOfNonEmptySurfaces( |
| 583 ->data.is_drawn; | 724 layer_tree_impl, property_trees, &initial_render_surface_list, |
| 584 | 725 render_surface_layer_list, current_render_surface_layer_list_id); |
| 585 // The root layer cannot be skipped. | 726 |
| 586 if (!IsRootLayer(layer) && | 727 ComputeLayerScrollsDrawnDescendants(layer_tree_impl, |
| 587 draw_property_utils::LayerShouldBeSkipped(layer, layer_is_drawn, | 728 &property_trees->scroll_tree); |
| 588 property_trees->transform_tree, | |
| 589 property_trees->effect_tree)) { | |
| 590 if (layer->render_surface()) | |
| 591 layer->ClearRenderSurfaceLayerList(); | |
| 592 for (auto* child_layer : layer->children()) { | |
| 593 CalculateRenderSurfaceLayerList( | |
| 594 child_layer, property_trees, render_surface_layer_list, descendants, | |
| 595 nearest_occlusion_immune_ancestor, layer_is_drawn, | |
| 596 can_render_to_separate_surface, current_render_surface_layer_list_id, | |
| 597 max_texture_size); | |
| 598 | |
| 599 MarkMasksAndAddChildToDescendantsIfRequired( | |
| 600 child_layer, descendants, current_render_surface_layer_list_id); | |
| 601 SetLayerOrDescendantIsDrawnIfRequired(layer, child_layer); | |
| 602 } | |
| 603 return; | |
| 604 } | |
| 605 | |
| 606 bool render_to_separate_surface = | |
| 607 IsRootLayer(layer) || | |
| 608 (can_render_to_separate_surface && layer->render_surface()); | |
| 609 | |
| 610 if (render_to_separate_surface) { | |
| 611 DCHECK(layer->render_surface()); | |
| 612 draw_property_utils::ComputeSurfaceDrawProperties(property_trees, | |
| 613 layer->render_surface()); | |
| 614 | |
| 615 | |
| 616 if (IsRootLayer(layer)) { | |
| 617 // The root surface does not contribute to any other surface, it has no | |
| 618 // target. | |
| 619 layer->render_surface()->set_contributes_to_drawn_surface(false); | |
| 620 } else { | |
| 621 bool contributes_to_drawn_surface = | |
| 622 property_trees->effect_tree.ContributesToDrawnSurface( | |
| 623 layer->effect_tree_index()); | |
| 624 layer->render_surface()->set_contributes_to_drawn_surface( | |
| 625 contributes_to_drawn_surface); | |
| 626 } | |
| 627 | |
| 628 // Ignore occlusion from outside the surface when surface contents need to | |
| 629 // be fully drawn. Layers with copy-request need to be complete. | |
| 630 // We could be smarter about layers with replica and exclude regions | |
| 631 // where both layer and the replica are occluded, but this seems like an | |
| 632 // overkill. The same is true for layers with filters that move pixels. | |
| 633 // TODO(senorblanco): make this smarter for the SkImageFilter case (check | |
| 634 // for pixel-moving filters) | |
| 635 if (layer->HasCopyRequest() || layer->has_replica() || | |
| 636 layer->filters().HasReferenceFilter() || | |
| 637 layer->filters().HasFilterThatMovesPixels()) { | |
| 638 nearest_occlusion_immune_ancestor = layer->render_surface(); | |
| 639 } | |
| 640 layer->render_surface()->SetNearestOcclusionImmuneAncestor( | |
| 641 nearest_occlusion_immune_ancestor); | |
| 642 layer->ClearRenderSurfaceLayerList(); | |
| 643 | |
| 644 render_surface_layer_list->push_back(layer); | |
| 645 | |
| 646 descendants = &(layer->render_surface()->layer_list()); | |
| 647 } | |
| 648 | |
| 649 bool layer_should_be_skipped = !draw_property_utils::LayerNeedsUpdate( | |
| 650 layer, layer_is_drawn, property_trees->transform_tree); | |
| 651 if (!layer_should_be_skipped) { | |
| 652 MarkLayerWithRenderSurfaceLayerListId(layer, | |
| 653 current_render_surface_layer_list_id); | |
| 654 descendants->push_back(layer); | |
| 655 } | |
| 656 | |
| 657 | |
| 658 // Clear the old accumulated content rect of surface. | |
| 659 if (render_to_separate_surface) | |
| 660 layer->render_surface()->ClearAccumulatedContentRect(); | |
| 661 | |
| 662 for (auto* child_layer : layer->children()) { | |
| 663 CalculateRenderSurfaceLayerList( | |
| 664 child_layer, property_trees, render_surface_layer_list, descendants, | |
| 665 nearest_occlusion_immune_ancestor, layer_is_drawn, | |
| 666 can_render_to_separate_surface, current_render_surface_layer_list_id, | |
| 667 max_texture_size); | |
| 668 | |
| 669 MarkMasksAndAddChildToDescendantsIfRequired( | |
| 670 child_layer, descendants, current_render_surface_layer_list_id); | |
| 671 SetLayerOrDescendantIsDrawnIfRequired(layer, child_layer); | |
| 672 } | |
| 673 | |
| 674 if (render_to_separate_surface && !IsRootLayer(layer) && | |
| 675 layer->render_surface()->layer_list().empty()) { | |
| 676 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); | |
| 677 return; | |
| 678 } | |
| 679 | |
| 680 // The render surface's content rect is the union of drawable content rects | |
| 681 // of the layers that draw into the surface. If the render surface is clipped, | |
| 682 // it is also intersected with the render's surface clip rect. | |
| 683 if (!IsRootLayer(layer)) { | |
| 684 // Layer contriubutes its drawable content rect to its render target. | |
| 685 if (layer->DrawsContent()) | |
| 686 layer->render_target()->AccumulateContentRectFromContributingLayer(layer); | |
| 687 | |
| 688 if (render_to_separate_surface) { | |
| 689 gfx::Rect surface_content_rect = | |
| 690 layer->render_surface()->accumulated_content_rect(); | |
| 691 | |
| 692 if (!layer->replica_layer() && !layer->HasCopyRequest() && | |
| 693 layer->render_surface()->is_clipped()) { | |
| 694 // Here, we clip the render surface's content rect with its clip rect. | |
| 695 // As the clip rect of render surface is in the surface's target | |
| 696 // space, we first map the content rect into the target space, | |
| 697 // intersect it with clip rect and project back the result to the | |
| 698 // surface space. | |
| 699 if (!surface_content_rect.IsEmpty()) { | |
| 700 gfx::Rect surface_clip_rect = | |
| 701 LayerTreeHostCommon::CalculateVisibleRect( | |
| 702 layer->render_surface()->clip_rect(), surface_content_rect, | |
| 703 layer->render_surface()->draw_transform()); | |
| 704 surface_content_rect.Intersect(surface_clip_rect); | |
| 705 } | |
| 706 } | |
| 707 // The RenderSurfaceImpl backing texture cannot exceed the maximum | |
| 708 // supported texture size. | |
| 709 surface_content_rect.set_width( | |
| 710 std::min(surface_content_rect.width(), max_texture_size)); | |
| 711 surface_content_rect.set_height( | |
| 712 std::min(surface_content_rect.height(), max_texture_size)); | |
| 713 layer->render_surface()->SetContentRect(surface_content_rect); | |
| 714 | |
| 715 // Now the render surface's content rect is calculated correctly, it could | |
| 716 // contribute to its render target. | |
| 717 layer->render_surface() | |
| 718 ->render_target() | |
| 719 ->AccumulateContentRectFromContributingRenderSurface( | |
| 720 layer->render_surface()); | |
| 721 } | |
| 722 } else { | |
| 723 // The root layer's surface content rect is always the entire viewport. | |
| 724 gfx::Rect viewport = | |
| 725 gfx::ToEnclosingRect(property_trees->clip_tree.ViewportClip()); | |
| 726 layer->render_surface()->SetContentRect(viewport); | |
| 727 } | |
| 728 | |
| 729 if (render_to_separate_surface && !IsRootLayer(layer) && | |
| 730 layer->render_surface()->DrawableContentRect().IsEmpty()) { | |
| 731 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); | |
| 732 } | |
| 733 } | 729 } |
| 734 | 730 |
| 735 static void ComputeMaskLayerDrawProperties(const LayerImpl* layer, | 731 static void ComputeMaskLayerDrawProperties(const LayerImpl* layer, |
| 736 LayerImpl* mask_layer) { | 732 LayerImpl* mask_layer) { |
| 737 DrawProperties& mask_layer_draw_properties = mask_layer->draw_properties(); | 733 DrawProperties& mask_layer_draw_properties = mask_layer->draw_properties(); |
| 738 mask_layer_draw_properties.visible_layer_rect = gfx::Rect(layer->bounds()); | 734 mask_layer_draw_properties.visible_layer_rect = gfx::Rect(layer->bounds()); |
| 739 mask_layer_draw_properties.target_space_transform = | 735 mask_layer_draw_properties.target_space_transform = |
| 740 layer->draw_properties().target_space_transform; | 736 layer->draw_properties().target_space_transform; |
| 741 mask_layer_draw_properties.screen_space_transform = | 737 mask_layer_draw_properties.screen_space_transform = |
| 742 layer->draw_properties().screen_space_transform; | 738 layer->draw_properties().screen_space_transform; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 } | 817 } |
| 822 } | 818 } |
| 823 | 819 |
| 824 if (should_measure_property_tree_performance) { | 820 if (should_measure_property_tree_performance) { |
| 825 TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), | 821 TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), |
| 826 "LayerTreeHostCommon::CalculateDrawProperties"); | 822 "LayerTreeHostCommon::CalculateDrawProperties"); |
| 827 } | 823 } |
| 828 | 824 |
| 829 DCHECK(inputs->can_render_to_separate_surface == | 825 DCHECK(inputs->can_render_to_separate_surface == |
| 830 inputs->property_trees->non_root_surfaces_enabled); | 826 inputs->property_trees->non_root_surfaces_enabled); |
| 831 const bool subtree_visible_from_ancestor = true; | |
| 832 for (LayerImpl* layer : visible_layer_list) { | 827 for (LayerImpl* layer : visible_layer_list) { |
| 833 draw_property_utils::ComputeLayerDrawProperties( | 828 draw_property_utils::ComputeLayerDrawProperties( |
| 834 layer, inputs->property_trees, inputs->layers_always_allowed_lcd_text, | 829 layer, inputs->property_trees, inputs->layers_always_allowed_lcd_text, |
| 835 inputs->can_use_lcd_text); | 830 inputs->can_use_lcd_text); |
| 836 if (layer->mask_layer()) | 831 if (layer->mask_layer()) |
| 837 ComputeMaskLayerDrawProperties(layer, layer->mask_layer()); | 832 ComputeMaskLayerDrawProperties(layer, layer->mask_layer()); |
| 838 LayerImpl* replica_mask_layer = | 833 LayerImpl* replica_mask_layer = |
| 839 layer->replica_layer() ? layer->replica_layer()->mask_layer() : nullptr; | 834 layer->replica_layer() ? layer->replica_layer()->mask_layer() : nullptr; |
| 840 if (replica_mask_layer) | 835 if (replica_mask_layer) |
| 841 ComputeMaskLayerDrawProperties(layer, replica_mask_layer); | 836 ComputeMaskLayerDrawProperties(layer, replica_mask_layer); |
| 842 } | 837 } |
| 843 | 838 |
| 844 DCHECK_EQ( | 839 DCHECK_EQ( |
| 845 inputs->current_render_surface_layer_list_id, | 840 inputs->current_render_surface_layer_list_id, |
| 846 inputs->root_layer->layer_tree_impl()->current_render_surface_list_id()); | 841 inputs->root_layer->layer_tree_impl()->current_render_surface_list_id()); |
| 847 CalculateRenderSurfaceLayerList( | 842 CalculateRenderSurfaceLayerList( |
| 848 inputs->root_layer, inputs->property_trees, | 843 inputs->root_layer->layer_tree_impl(), inputs->property_trees, |
| 849 inputs->render_surface_layer_list, nullptr, nullptr, | 844 inputs->render_surface_layer_list, inputs->can_render_to_separate_surface, |
| 850 subtree_visible_from_ancestor, inputs->can_render_to_separate_surface, | |
| 851 inputs->current_render_surface_layer_list_id, inputs->max_texture_size); | 845 inputs->current_render_surface_layer_list_id, inputs->max_texture_size); |
| 852 | 846 |
| 853 if (should_measure_property_tree_performance) { | 847 if (should_measure_property_tree_performance) { |
| 854 TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), | 848 TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), |
| 855 "LayerTreeHostCommon::CalculateDrawProperties"); | 849 "LayerTreeHostCommon::CalculateDrawProperties"); |
| 856 } | 850 } |
| 857 | 851 |
| 858 // A root layer render_surface should always exist after | 852 // A root layer render_surface should always exist after |
| 859 // CalculateDrawProperties. | 853 // CalculateDrawProperties. |
| 860 DCHECK(inputs->root_layer->render_surface()); | 854 DCHECK(inputs->root_layer->render_surface()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 | 936 |
| 943 PropertyTrees* GetPropertyTrees(Layer* layer) { | 937 PropertyTrees* GetPropertyTrees(Layer* layer) { |
| 944 return layer->layer_tree_host()->property_trees(); | 938 return layer->layer_tree_host()->property_trees(); |
| 945 } | 939 } |
| 946 | 940 |
| 947 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { | 941 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { |
| 948 return layer->layer_tree_impl()->property_trees(); | 942 return layer->layer_tree_impl()->property_trees(); |
| 949 } | 943 } |
| 950 | 944 |
| 951 } // namespace cc | 945 } // namespace cc |
| OLD | NEW |