Commit a9be49be authored by Chris Harrelson's avatar Chris Harrelson Committed by Commit Bot

Optimize out work in CompositingLayerAssigner

* There is no need to do any work for a PaintLayer if it has no past/current compositing state.
* There is no need to recurse if the entire stacking subtree has no past/current compositing state.

Bug: 814439

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ib1d2c23e1e2c9a34bea63432d95f83a8bbe0ab13
Reviewed-on: https://chromium-review.googlesource.com/1101817
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarTien-Ren Chen <trchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570321}
parent 42eac6a8
...@@ -3635,6 +3635,7 @@ void CompositedLayerMapping::FinishAccumulatingSquashingLayers( ...@@ -3635,6 +3635,7 @@ void CompositedLayerMapping::FinishAccumulatingSquashingLayers(
if (InvalidateLayerIfNoPrecedingEntry(i)) { if (InvalidateLayerIfNoPrecedingEntry(i)) {
squashed_layers_[i].paint_layer->SetGroupedMapping( squashed_layers_[i].paint_layer->SetGroupedMapping(
nullptr, PaintLayer::kDoNotInvalidateLayerAndRemoveFromMapping); nullptr, PaintLayer::kDoNotInvalidateLayerAndRemoveFromMapping);
squashed_layers_[i].paint_layer->SetLostGroupedMapping(true);
} }
layers_needing_paint_invalidation.push_back( layers_needing_paint_invalidation.push_back(
squashed_layers_[i].paint_layer); squashed_layers_[i].paint_layer);
......
...@@ -285,6 +285,10 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal( ...@@ -285,6 +285,10 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal(
PaintLayer* layer, PaintLayer* layer,
SquashingState& squashing_state, SquashingState& squashing_state,
Vector<PaintLayer*>& layers_needing_paint_invalidation) { Vector<PaintLayer*>& layers_needing_paint_invalidation) {
if (layer->NeedsCompositingLayerAssignment()) {
CHECK(layer->GetCompositingReasons() ||
(layer->GetCompositingState() != kNotComposited) ||
layer->LostGroupedMapping());
if (RequiresSquashing(layer->GetCompositingReasons())) { if (RequiresSquashing(layer->GetCompositingReasons())) {
SquashingDisallowedReasons reasons_preventing_squashing = SquashingDisallowedReasons reasons_preventing_squashing =
GetReasonsPreventingSquashing(layer, squashing_state); GetReasonsPreventingSquashing(layer, squashing_state);
...@@ -306,7 +310,9 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal( ...@@ -306,7 +310,9 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal(
layers_changed_ = true; layers_changed_ = true;
if (ScrollingCoordinator* scrolling_coordinator = if (ScrollingCoordinator* scrolling_coordinator =
layer->GetScrollingCoordinator()) { layer->GetScrollingCoordinator()) {
if (layer->GetLayoutObject().Style()->HasViewportConstrainedPosition()) { if (layer->GetLayoutObject()
.Style()
->HasViewportConstrainedPosition()) {
scrolling_coordinator->FrameViewFixedObjectsDidChange( scrolling_coordinator->FrameViewFixedObjectsDidChange(
layer->GetLayoutObject().View()->GetFrameView()); layer->GetLayoutObject().View()->GetFrameView());
} }
...@@ -314,10 +320,10 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal( ...@@ -314,10 +320,10 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal(
} }
if (composited_layer_update != kNoCompositingStateChange) { if (composited_layer_update != kNoCompositingStateChange) {
// A change in the compositing state of a ScrollTimeline's scroll source can // A change in the compositing state of a ScrollTimeline's scroll source
// cause the compositor's view of the scroll source to become out of date. // can cause the compositor's view of the scroll source to become out of
// We inform the WorkletAnimationController about any such changes so that // date. We inform the WorkletAnimationController about any such changes
// it can schedule a compositing animations update. // so that it can schedule a compositing animations update.
Node* node = layer->GetLayoutObject().GetNode(); Node* node = layer->GetLayoutObject().GetNode();
if (node && ScrollTimeline::HasActiveScrollTimeline(node)) { if (node && ScrollTimeline::HasActiveScrollTimeline(node)) {
node->GetDocument() node->GetDocument()
...@@ -337,11 +343,14 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal( ...@@ -337,11 +343,14 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal(
if (layer_is_squashed) { if (layer_is_squashed) {
squashing_state.next_squashed_layer_index++; squashing_state.next_squashed_layer_index++;
IntRect layer_bounds = layer->ClippedAbsoluteBoundingBox(); IntRect layer_bounds = layer->ClippedAbsoluteBoundingBox();
squashing_state.total_area_of_squashed_rects += layer_bounds.Size().Area(); squashing_state.total_area_of_squashed_rects +=
layer_bounds.Size().Area();
squashing_state.bounding_rect.Unite(layer_bounds); squashing_state.bounding_rect.Unite(layer_bounds);
} }
}
if (layer->StackingNode()->IsStackingContext()) { if (layer->StackingDescendantNeedsCompositingLayerAssignment() &&
layer->StackingNode()->IsStackingContext()) {
PaintLayerStackingNodeIterator iterator(*layer->StackingNode(), PaintLayerStackingNodeIterator iterator(*layer->StackingNode(),
kNegativeZOrderChildren); kNegativeZOrderChildren);
while (PaintLayerStackingNode* cur_node = iterator.Next()) { while (PaintLayerStackingNode* cur_node = iterator.Next()) {
...@@ -352,25 +361,31 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal( ...@@ -352,25 +361,31 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal(
// At this point, if the layer is to be separately composited, then its // At this point, if the layer is to be separately composited, then its
// backing becomes the most recent in paint-order. // backing becomes the most recent in paint-order.
if (layer->GetCompositingState() == kPaintsIntoOwnBacking) { if (layer->NeedsCompositingLayerAssignment() &&
layer->GetCompositingState() == kPaintsIntoOwnBacking) {
DCHECK(!RequiresSquashing(layer->GetCompositingReasons())); DCHECK(!RequiresSquashing(layer->GetCompositingReasons()));
squashing_state.UpdateSquashingStateForNewMapping( squashing_state.UpdateSquashingStateForNewMapping(
layer->GetCompositedLayerMapping(), layer->HasCompositedLayerMapping(), layer->GetCompositedLayerMapping(), layer->HasCompositedLayerMapping(),
layers_needing_paint_invalidation); layers_needing_paint_invalidation);
} }
if (layer->StackingDescendantNeedsCompositingLayerAssignment()) {
PaintLayerStackingNodeIterator iterator( PaintLayerStackingNodeIterator iterator(
*layer->StackingNode(), kNormalFlowChildren | kPositiveZOrderChildren); *layer->StackingNode(), kNormalFlowChildren | kPositiveZOrderChildren);
while (PaintLayerStackingNode* cur_node = iterator.Next()) { while (PaintLayerStackingNode* cur_node = iterator.Next()) {
AssignLayersToBackingsInternal(cur_node->Layer(), squashing_state, AssignLayersToBackingsInternal(cur_node->Layer(), squashing_state,
layers_needing_paint_invalidation); layers_needing_paint_invalidation);
} }
}
if (layer->NeedsCompositingLayerAssignment()) {
if (squashing_state.has_most_recent_mapping && if (squashing_state.has_most_recent_mapping &&
&squashing_state.most_recent_mapping->OwningLayer() == layer) { &squashing_state.most_recent_mapping->OwningLayer() == layer) {
squashing_state.have_assigned_backings_to_entire_squashing_layer_subtree = squashing_state.have_assigned_backings_to_entire_squashing_layer_subtree =
true; true;
} }
}
layer->ClearNeedsCompositingLayerAssignment();
} }
} // namespace blink } // namespace blink
...@@ -607,6 +607,11 @@ void CompositingRequirementsUpdater::UpdateRecursive( ...@@ -607,6 +607,11 @@ void CompositingRequirementsUpdater::UpdateRecursive(
any_descendant_has3d_transform || layer->Has3DTransform(); any_descendant_has3d_transform || layer->Has3DTransform();
} }
// Layer assignment is needed for allocating or removing composited
// layers related to this PaintLayer; hence the below conditions.
if (reasons_to_composite || layer->GetCompositingState() != kNotComposited)
layer->SetNeedsCompositingLayerAssignment();
// At this point we have finished collecting all reasons to composite this // At this point we have finished collecting all reasons to composite this
// layer. // layer.
layer->SetCompositingReasons(reasons_to_composite); layer->SetCompositingReasons(reasons_to_composite);
......
...@@ -168,6 +168,8 @@ PaintLayer::PaintLayer(LayoutBoxModelObject& layout_object) ...@@ -168,6 +168,8 @@ PaintLayer::PaintLayer(LayoutBoxModelObject& layout_object)
descendant_has_direct_or_scrolling_compositing_reason_(false), descendant_has_direct_or_scrolling_compositing_reason_(false),
needs_compositing_reasons_update_(true), needs_compositing_reasons_update_(true),
descendant_may_need_compositing_requirements_update_(false), descendant_may_need_compositing_requirements_update_(false),
needs_compositing_layer_assignment_(false),
descendant_needs_compositing_layer_assignment_(false),
layout_object_(layout_object), layout_object_(layout_object),
parent_(nullptr), parent_(nullptr),
previous_(nullptr), previous_(nullptr),
...@@ -2323,6 +2325,21 @@ bool PaintLayer::IsReplacedNormalFlowStacking() { ...@@ -2323,6 +2325,21 @@ bool PaintLayer::IsReplacedNormalFlowStacking() {
return true; return true;
} }
void PaintLayer::SetNeedsCompositingLayerAssignment() {
needs_compositing_layer_assignment_ = true;
for (PaintLayer* curr = CompositingContainer();
curr && !curr->StackingDescendantNeedsCompositingLayerAssignment();
curr = curr->CompositingContainer()) {
curr->descendant_needs_compositing_layer_assignment_ = true;
}
}
void PaintLayer::ClearNeedsCompositingLayerAssignment() {
needs_compositing_layer_assignment_ = false;
descendant_needs_compositing_layer_assignment_ = false;
}
void PaintLayer::SetNeedsCompositingRequirementsUpdate() { void PaintLayer::SetNeedsCompositingRequirementsUpdate() {
for (PaintLayer* curr = Parent(); for (PaintLayer* curr = Parent();
curr && !curr->DescendantMayNeedCompositingRequirementsUpdate(); curr && !curr->DescendantMayNeedCompositingRequirementsUpdate();
......
...@@ -849,7 +849,11 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient { ...@@ -849,7 +849,11 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient {
DCHECK(IsAllowedToQueryCompositingState()); DCHECK(IsAllowedToQueryCompositingState());
return lost_grouped_mapping_; return lost_grouped_mapping_;
} }
void SetLostGroupedMapping(bool b) { lost_grouped_mapping_ = b; } void SetLostGroupedMapping(bool b) {
lost_grouped_mapping_ = b;
needs_compositing_layer_assignment_ =
needs_compositing_layer_assignment_ || b;
}
CompositingReasons GetCompositingReasons() const { CompositingReasons GetCompositingReasons() const {
DCHECK(IsAllowedToQueryCompositingState()); DCHECK(IsAllowedToQueryCompositingState());
...@@ -1068,6 +1072,16 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient { ...@@ -1068,6 +1072,16 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient {
needs_compositing_reasons_update_ = true; needs_compositing_reasons_update_ = true;
} }
void SetNeedsCompositingLayerAssignment();
void ClearNeedsCompositingLayerAssignment();
bool NeedsCompositingLayerAssignment() const {
return needs_compositing_layer_assignment_;
}
bool StackingDescendantNeedsCompositingLayerAssignment() const {
return descendant_needs_compositing_layer_assignment_;
}
private: private:
void SetNeedsCompositingInputsUpdateInternal(); void SetNeedsCompositingInputsUpdateInternal();
...@@ -1303,6 +1317,8 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient { ...@@ -1303,6 +1317,8 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient {
unsigned needs_compositing_reasons_update_ : 1; unsigned needs_compositing_reasons_update_ : 1;
unsigned descendant_may_need_compositing_requirements_update_ : 1; unsigned descendant_may_need_compositing_requirements_update_ : 1;
unsigned needs_compositing_layer_assignment_ : 1;
unsigned descendant_needs_compositing_layer_assignment_ : 1;
LayoutBoxModelObject& layout_object_; LayoutBoxModelObject& layout_object_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment