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(
if (InvalidateLayerIfNoPrecedingEntry(i)) {
squashed_layers_[i].paint_layer->SetGroupedMapping(
nullptr, PaintLayer::kDoNotInvalidateLayerAndRemoveFromMapping);
squashed_layers_[i].paint_layer->SetLostGroupedMapping(true);
}
layers_needing_paint_invalidation.push_back(
squashed_layers_[i].paint_layer);
......
......@@ -285,63 +285,72 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal(
PaintLayer* layer,
SquashingState& squashing_state,
Vector<PaintLayer*>& layers_needing_paint_invalidation) {
if (RequiresSquashing(layer->GetCompositingReasons())) {
SquashingDisallowedReasons reasons_preventing_squashing =
GetReasonsPreventingSquashing(layer, squashing_state);
if (reasons_preventing_squashing) {
layer->SetCompositingReasons(layer->GetCompositingReasons() |
CompositingReason::kSquashingDisallowed);
layer->SetSquashingDisallowedReasons(reasons_preventing_squashing);
if (layer->NeedsCompositingLayerAssignment()) {
CHECK(layer->GetCompositingReasons() ||
(layer->GetCompositingState() != kNotComposited) ||
layer->LostGroupedMapping());
if (RequiresSquashing(layer->GetCompositingReasons())) {
SquashingDisallowedReasons reasons_preventing_squashing =
GetReasonsPreventingSquashing(layer, squashing_state);
if (reasons_preventing_squashing) {
layer->SetCompositingReasons(layer->GetCompositingReasons() |
CompositingReason::kSquashingDisallowed);
layer->SetSquashingDisallowedReasons(reasons_preventing_squashing);
}
}
}
CompositingStateTransitionType composited_layer_update =
ComputeCompositedLayerUpdate(layer);
if (compositor_->AllocateOrClearCompositedLayerMapping(
layer, composited_layer_update)) {
TRACE_LAYER_INVALIDATION(
layer, InspectorLayerInvalidationTrackingEvent::kNewCompositedLayer);
layers_needing_paint_invalidation.push_back(layer);
layers_changed_ = true;
if (ScrollingCoordinator* scrolling_coordinator =
layer->GetScrollingCoordinator()) {
if (layer->GetLayoutObject().Style()->HasViewportConstrainedPosition()) {
scrolling_coordinator->FrameViewFixedObjectsDidChange(
layer->GetLayoutObject().View()->GetFrameView());
CompositingStateTransitionType composited_layer_update =
ComputeCompositedLayerUpdate(layer);
if (compositor_->AllocateOrClearCompositedLayerMapping(
layer, composited_layer_update)) {
TRACE_LAYER_INVALIDATION(
layer, InspectorLayerInvalidationTrackingEvent::kNewCompositedLayer);
layers_needing_paint_invalidation.push_back(layer);
layers_changed_ = true;
if (ScrollingCoordinator* scrolling_coordinator =
layer->GetScrollingCoordinator()) {
if (layer->GetLayoutObject()
.Style()
->HasViewportConstrainedPosition()) {
scrolling_coordinator->FrameViewFixedObjectsDidChange(
layer->GetLayoutObject().View()->GetFrameView());
}
}
}
}
if (composited_layer_update != kNoCompositingStateChange) {
// A change in the compositing state of a ScrollTimeline's scroll source can
// cause the compositor's view of the scroll source to become out of date.
// We inform the WorkletAnimationController about any such changes so that
// it can schedule a compositing animations update.
Node* node = layer->GetLayoutObject().GetNode();
if (node && ScrollTimeline::HasActiveScrollTimeline(node)) {
node->GetDocument()
.GetWorkletAnimationController()
.ScrollSourceCompositingStateChanged(node);
if (composited_layer_update != kNoCompositingStateChange) {
// A change in the compositing state of a ScrollTimeline's scroll source
// can cause the compositor's view of the scroll source to become out of
// date. We inform the WorkletAnimationController about any such changes
// so that it can schedule a compositing animations update.
Node* node = layer->GetLayoutObject().GetNode();
if (node && ScrollTimeline::HasActiveScrollTimeline(node)) {
node->GetDocument()
.GetWorkletAnimationController()
.ScrollSourceCompositingStateChanged(node);
}
}
}
// Add this layer to a squashing backing if needed.
UpdateSquashingAssignment(layer, squashing_state, composited_layer_update,
layers_needing_paint_invalidation);
const bool layer_is_squashed =
composited_layer_update == kPutInSquashingLayer ||
(composited_layer_update == kNoCompositingStateChange &&
layer->GroupedMapping());
if (layer_is_squashed) {
squashing_state.next_squashed_layer_index++;
IntRect layer_bounds = layer->ClippedAbsoluteBoundingBox();
squashing_state.total_area_of_squashed_rects += layer_bounds.Size().Area();
squashing_state.bounding_rect.Unite(layer_bounds);
// Add this layer to a squashing backing if needed.
UpdateSquashingAssignment(layer, squashing_state, composited_layer_update,
layers_needing_paint_invalidation);
const bool layer_is_squashed =
composited_layer_update == kPutInSquashingLayer ||
(composited_layer_update == kNoCompositingStateChange &&
layer->GroupedMapping());
if (layer_is_squashed) {
squashing_state.next_squashed_layer_index++;
IntRect layer_bounds = layer->ClippedAbsoluteBoundingBox();
squashing_state.total_area_of_squashed_rects +=
layer_bounds.Size().Area();
squashing_state.bounding_rect.Unite(layer_bounds);
}
}
if (layer->StackingNode()->IsStackingContext()) {
if (layer->StackingDescendantNeedsCompositingLayerAssignment() &&
layer->StackingNode()->IsStackingContext()) {
PaintLayerStackingNodeIterator iterator(*layer->StackingNode(),
kNegativeZOrderChildren);
while (PaintLayerStackingNode* cur_node = iterator.Next()) {
......@@ -352,25 +361,31 @@ void CompositingLayerAssigner::AssignLayersToBackingsInternal(
// At this point, if the layer is to be separately composited, then its
// backing becomes the most recent in paint-order.
if (layer->GetCompositingState() == kPaintsIntoOwnBacking) {
if (layer->NeedsCompositingLayerAssignment() &&
layer->GetCompositingState() == kPaintsIntoOwnBacking) {
DCHECK(!RequiresSquashing(layer->GetCompositingReasons()));
squashing_state.UpdateSquashingStateForNewMapping(
layer->GetCompositedLayerMapping(), layer->HasCompositedLayerMapping(),
layers_needing_paint_invalidation);
}
PaintLayerStackingNodeIterator iterator(
*layer->StackingNode(), kNormalFlowChildren | kPositiveZOrderChildren);
while (PaintLayerStackingNode* cur_node = iterator.Next()) {
AssignLayersToBackingsInternal(cur_node->Layer(), squashing_state,
layers_needing_paint_invalidation);
if (layer->StackingDescendantNeedsCompositingLayerAssignment()) {
PaintLayerStackingNodeIterator iterator(
*layer->StackingNode(), kNormalFlowChildren | kPositiveZOrderChildren);
while (PaintLayerStackingNode* cur_node = iterator.Next()) {
AssignLayersToBackingsInternal(cur_node->Layer(), squashing_state,
layers_needing_paint_invalidation);
}
}
if (squashing_state.has_most_recent_mapping &&
&squashing_state.most_recent_mapping->OwningLayer() == layer) {
squashing_state.have_assigned_backings_to_entire_squashing_layer_subtree =
true;
if (layer->NeedsCompositingLayerAssignment()) {
if (squashing_state.has_most_recent_mapping &&
&squashing_state.most_recent_mapping->OwningLayer() == layer) {
squashing_state.have_assigned_backings_to_entire_squashing_layer_subtree =
true;
}
}
layer->ClearNeedsCompositingLayerAssignment();
}
} // namespace blink
......@@ -607,6 +607,11 @@ void CompositingRequirementsUpdater::UpdateRecursive(
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
// layer.
layer->SetCompositingReasons(reasons_to_composite);
......
......@@ -168,6 +168,8 @@ PaintLayer::PaintLayer(LayoutBoxModelObject& layout_object)
descendant_has_direct_or_scrolling_compositing_reason_(false),
needs_compositing_reasons_update_(true),
descendant_may_need_compositing_requirements_update_(false),
needs_compositing_layer_assignment_(false),
descendant_needs_compositing_layer_assignment_(false),
layout_object_(layout_object),
parent_(nullptr),
previous_(nullptr),
......@@ -2323,6 +2325,21 @@ bool PaintLayer::IsReplacedNormalFlowStacking() {
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() {
for (PaintLayer* curr = Parent();
curr && !curr->DescendantMayNeedCompositingRequirementsUpdate();
......
......@@ -849,7 +849,11 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient {
DCHECK(IsAllowedToQueryCompositingState());
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 {
DCHECK(IsAllowedToQueryCompositingState());
......@@ -1068,6 +1072,16 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient {
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:
void SetNeedsCompositingInputsUpdateInternal();
......@@ -1303,6 +1317,8 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient {
unsigned needs_compositing_reasons_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_;
......
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