Bug 1371457 - Add restyle markers for Stylo. r=bholley,gregtatum
Add restyle markers to `PrepareAndTraverseSubtree` to cover both initial styling
and part of the work of restyling. Also add restyle markers around the post
traversal work in `DoProcessPendingRestyles`.
A new marker is also added around the change hint processing after the post
traversal.
MozReview-Commit-ID: 43PSyCJLikR
--- a/devtools/client/locales/en-US/markers.properties
+++ b/devtools/client/locales/en-US/markers.properties
@@ -10,16 +10,17 @@
# A good criteria is the language in which you'd find the best
# documentation on web development on the web. These strings
# are specifically for marker names in the performance tool.
# LOCALIZATION NOTE (marker.label.*):
# These strings are displayed in the Performance Tool waterfall, identifying markers.
# We want to use the same wording as Google Chrome when appropriate.
marker.label.styles=Recalculate Style
+marker.label.stylesApplyChanges=Apply Style Changes
marker.label.reflow=Layout
marker.label.paint=Paint
marker.label.composite=Composite Layers
marker.label.compositeForwardTransaction=Composite Request Sent
marker.label.javascript=Function Call
marker.label.parseHTML=Parse HTML
marker.label.parseXML=Parse XML
marker.label.domevent=DOM Event
--- a/devtools/client/performance/modules/markers.js
+++ b/devtools/client/performance/modules/markers.js
@@ -48,16 +48,21 @@ const TIMELINE_BLUEPRINT = {
/* Group 0 - Reflow and Rendering pipeline */
"Styles": {
group: 0,
colorName: "graphs-purple",
label: L10N.getStr("marker.label.styles"),
fields: Formatters.StylesFields,
},
+ "StylesApplyChanges": {
+ group: 0,
+ colorName: "graphs-purple",
+ label: L10N.getStr("marker.label.stylesApplyChanges"),
+ },
"Reflow": {
group: 0,
colorName: "graphs-purple",
label: L10N.getStr("marker.label.reflow"),
},
"Paint": {
group: 0,
colorName: "graphs-green",
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -1,16 +1,18 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ServoRestyleManager.h"
+#include "mozilla/AutoRestyleTimelineMarker.h"
+#include "mozilla/AutoTimelineMarker.h"
#include "mozilla/DocumentStyleRootIterator.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/ServoStyleSet.h"
#include "mozilla/Unused.h"
#include "mozilla/ViewportFrame.h"
#include "mozilla/dom/ChildIterator.h"
#include "mozilla/dom/ElementInlines.h"
#include "nsBlockFrame.h"
@@ -763,52 +765,60 @@ ServoRestyleManager::DoProcessPendingRes
? TraversalRestyleBehavior::ForCSSRuleChanges
: TraversalRestyleBehavior::Normal;
while (animationOnly ? styleSet->StyleDocumentForAnimationOnly()
: styleSet->StyleDocument(restyleBehavior)) {
if (!animationOnly) {
ClearSnapshots();
}
+ nsStyleChangeList currentChanges(StyleBackendType::Servo);
+ bool anyStyleChanged = false;
+
// Recreate style contexts, and queue up change hints (which also handle
// lazy frame construction).
- nsStyleChangeList currentChanges(StyleBackendType::Servo);
- DocumentStyleRootIterator iter(doc);
- bool anyStyleChanged = false;
- while (Element* root = iter.GetNextStyleRoot()) {
- ServoRestyleState state(*styleSet, currentChanges);
- anyStyleChanged |= ProcessPostTraversal(root, nullptr, state);
+ {
+ AutoRestyleTimelineMarker marker(
+ mPresContext->GetDocShell(), animationOnly);
+ DocumentStyleRootIterator iter(doc);
+ while (Element* root = iter.GetNextStyleRoot()) {
+ ServoRestyleState state(*styleSet, currentChanges);
+ anyStyleChanged |= ProcessPostTraversal(root, nullptr, state);
+ }
}
// Process the change hints.
//
// Unfortunately, the frame constructor can generate new change hints while
// processing existing ones. We redirect those into a secondary queue and
// iterate until there's nothing left.
- ReentrantChangeList newChanges;
- mReentrantChanges = &newChanges;
- while (!currentChanges.IsEmpty()) {
- ProcessRestyledFrames(currentChanges);
- MOZ_ASSERT(currentChanges.IsEmpty());
- for (ReentrantChange& change: newChanges) {
- if (!(change.mHint & nsChangeHint_ReconstructFrame) &&
- !change.mContent->GetPrimaryFrame()) {
- // SVG Elements post change hints without ensuring that the primary
- // frame will be there after that (see bug 1366142).
- //
- // Just ignore those, since we can't really process them.
- continue;
+ {
+ AutoTimelineMarker marker(
+ mPresContext->GetDocShell(), "StylesApplyChanges");
+ ReentrantChangeList newChanges;
+ mReentrantChanges = &newChanges;
+ while (!currentChanges.IsEmpty()) {
+ ProcessRestyledFrames(currentChanges);
+ MOZ_ASSERT(currentChanges.IsEmpty());
+ for (ReentrantChange& change: newChanges) {
+ if (!(change.mHint & nsChangeHint_ReconstructFrame) &&
+ !change.mContent->GetPrimaryFrame()) {
+ // SVG Elements post change hints without ensuring that the primary
+ // frame will be there after that (see bug 1366142).
+ //
+ // Just ignore those, since we can't really process them.
+ continue;
+ }
+ currentChanges.AppendChange(change.mContent->GetPrimaryFrame(),
+ change.mContent, change.mHint);
}
- currentChanges.AppendChange(change.mContent->GetPrimaryFrame(),
- change.mContent, change.mHint);
+ newChanges.Clear();
}
- newChanges.Clear();
+ mReentrantChanges = nullptr;
}
- mReentrantChanges = nullptr;
-
if (anyStyleChanged) {
// Maybe no styles changed when:
//
// * Only explicit change hints were posted in the first place.
// * When an attribute or state change in the content happens not to need
// a restyle after all.
//
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -2,16 +2,17 @@
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ServoStyleSet.h"
#include "gfxPlatformFontList.h"
+#include "mozilla/AutoRestyleTimelineMarker.h"
#include "mozilla/DocumentStyleRootIterator.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/ServoRestyleManager.h"
#include "mozilla/ServoStyleRuleMap.h"
#include "mozilla/css/Loader.h"
#include "mozilla/dom/AnonymousContent.h"
#include "mozilla/dom/ChildIterator.h"
#include "mozilla/dom/Element.h"
@@ -418,31 +419,35 @@ ServoStyleSet::PreTraverse(Element* aRoo
}
bool
ServoStyleSet::PrepareAndTraverseSubtree(
RawGeckoElementBorrowed aRoot,
TraversalRootBehavior aRootBehavior,
TraversalRestyleBehavior aRestyleBehavior)
{
+ bool forAnimationOnly =
+ aRestyleBehavior == TraversalRestyleBehavior::ForAnimationOnly;
+
+ AutoRestyleTimelineMarker marker(
+ mPresContext->GetDocShell(), forAnimationOnly);
+
// Get the Document's root element to ensure that the cache is valid before
// calling into the (potentially-parallel) Servo traversal, where a cache hit
// is necessary to avoid a data race when updating the cache.
mozilla::Unused << aRoot->OwnerDoc()->GetRootElement();
MOZ_ASSERT(!StylistNeedsUpdate());
AutoSetInServoTraversal guard(this);
const SnapshotTable& snapshots = Snapshots();
bool isInitial = !aRoot->HasServoData();
bool forReconstruct =
aRestyleBehavior == TraversalRestyleBehavior::ForReconstruct;
- bool forAnimationOnly =
- aRestyleBehavior == TraversalRestyleBehavior::ForAnimationOnly;
#ifdef DEBUG
bool forNewlyBoundElement =
aRestyleBehavior == TraversalRestyleBehavior::ForNewlyBoundElement;
#endif
bool postTraversalRequired = Servo_TraverseSubtree(
aRoot, mRawSet.get(), &snapshots, aRootBehavior, aRestyleBehavior);
MOZ_ASSERT(!(isInitial || forReconstruct || forNewlyBoundElement) ||
!postTraversalRequired);