Commit be9e1147 authored by Steve Kobes's avatar Steve Kobes Committed by Commit Bot

Extract some layout shift reporting steps into a helper.

These steps will need to be deferred for pointerdown buffering.

Also expand logging to indicate when layout shifts were ignored due to
recent input.

Bug: 978027
Change-Id: I9beca66d9d626de8f1327d730e41ed9bdebbcfa1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715228Reviewed-by: default avatarBryan McQuade <bmcquade@chromium.org>
Reviewed-by: default avatarSteve Kobes <skobes@chromium.org>
Commit-Queue: Steve Kobes <skobes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680446}
parent 827c9695
...@@ -203,7 +203,7 @@ void LayoutShiftTracker::ObjectShifted( ...@@ -203,7 +203,7 @@ void LayoutShiftTracker::ObjectShifted(
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
LocalFrame& frame = frame_view_->GetFrame(); LocalFrame& frame = frame_view_->GetFrame();
if (!HadRecentInput() && ShouldLog(frame)) { if (ShouldLog(frame)) {
DVLOG(2) << "in " << (frame.IsMainFrame() ? "" : "subframe ") DVLOG(2) << "in " << (frame.IsMainFrame() ? "" : "subframe ")
<< frame.GetDocument()->Url().GetString() << ", " << frame.GetDocument()->Url().GetString() << ", "
<< source.DebugName() << " moved from " << old_rect.ToString() << source.DebugName() << " moved from " << old_rect.ToString()
...@@ -307,28 +307,44 @@ void LayoutShiftTracker::NotifyPrePaintFinished() { ...@@ -307,28 +307,44 @@ void LayoutShiftTracker::NotifyPrePaintFinished() {
? double(frame_max_distance_) / viewport_max_dimension ? double(frame_max_distance_) / viewport_max_dimension
: 1.0; : 1.0;
double score_delta = impact_fraction * move_distance_factor; double score_delta = impact_fraction * move_distance_factor;
double weighted_score_delta = score_delta * SubframeWeightingFactor();
if (!HadRecentInput())
score_ += score_delta;
overall_max_distance_ = std::max(overall_max_distance_, frame_max_distance_); overall_max_distance_ = std::max(overall_max_distance_, frame_max_distance_);
LocalFrame& frame = frame_view_->GetFrame();
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
if (!HadRecentInput() && ShouldLog(frame)) { LocalFrame& frame = frame_view_->GetFrame();
if (ShouldLog(frame)) {
DVLOG(1) << "in " << (frame.IsMainFrame() ? "" : "subframe ") DVLOG(1) << "in " << (frame.IsMainFrame() ? "" : "subframe ")
<< frame.GetDocument()->Url().GetString() << ", viewport was " << frame.GetDocument()->Url().GetString() << ", viewport was "
<< (impact_fraction * 100) << "% impacted with distance fraction " << (impact_fraction * 100) << "% impacted with distance fraction "
<< move_distance_factor << "; raising score to " << score_; << move_distance_factor;
} }
#endif #endif
TRACE_EVENT_INSTANT2("loading", "LayoutShift", TRACE_EVENT_SCOPE_THREAD, ReportShift(score_delta, weighted_score_delta);
"data", PerFrameTraceData(score_delta, HadRecentInput()),
"frame", ToTraceValue(&frame)); if (use_sweep_line) {
if (!region_experimental_.IsEmpty() && !HadRecentInput()) {
SetLayoutShiftRects(region_experimental_.GetRects(), 1, true);
}
region_experimental_.Reset();
} else {
if (!region_.IsEmpty() && !HadRecentInput()) {
SetLayoutShiftRects(region_.Rects(), granularity_scale, false);
}
region_ = Region();
}
frame_max_distance_ = 0.0;
frame_scroll_delta_ = ScrollOffset();
}
if (!HadRecentInput()) { void LayoutShiftTracker::ReportShift(double score_delta,
double weighted_score_delta = score_delta * SubframeWeightingFactor(); double weighted_score_delta) {
LocalFrame& frame = frame_view_->GetFrame();
bool had_recent_input = HadRecentInput();
if (!had_recent_input) {
score_ += score_delta;
if (weighted_score_delta > 0) { if (weighted_score_delta > 0) {
weighted_score_ += weighted_score_delta; weighted_score_ += weighted_score_delta;
frame.Client()->DidObserveLayoutShift(weighted_score_delta, frame.Client()->DidObserveLayoutShift(weighted_score_delta,
...@@ -342,24 +358,24 @@ void LayoutShiftTracker::NotifyPrePaintFinished() { ...@@ -342,24 +358,24 @@ void LayoutShiftTracker::NotifyPrePaintFinished() {
WindowPerformance* performance = WindowPerformance* performance =
DOMWindowPerformance::performance(*frame.DomWindow()); DOMWindowPerformance::performance(*frame.DomWindow());
if (performance) { if (performance) {
performance->AddLayoutJankFraction(score_delta, HadRecentInput(), performance->AddLayoutJankFraction(score_delta, had_recent_input,
most_recent_input_timestamp_); most_recent_input_timestamp_);
} }
} }
if (use_sweep_line) { TRACE_EVENT_INSTANT2("loading", "LayoutShift", TRACE_EVENT_SCOPE_THREAD,
if (!region_experimental_.IsEmpty() && !HadRecentInput()) { "data", PerFrameTraceData(score_delta, had_recent_input),
SetLayoutShiftRects(region_experimental_.GetRects(), 1, true); "frame", ToTraceValue(&frame));
}
region_experimental_.Reset(); #if DCHECK_IS_ON()
} else { if (ShouldLog(frame)) {
if (!region_.IsEmpty() && !HadRecentInput()) { DVLOG(1) << "in " << (frame.IsMainFrame() ? "" : "subframe ")
SetLayoutShiftRects(region_.Rects(), granularity_scale, false); << frame.GetDocument()->Url().GetString() << ", layout shift of "
} << score_delta
region_ = Region(); << (had_recent_input ? " excluded by recent input" : " reported")
<< "; cumulative score is " << score_;
} }
frame_max_distance_ = 0.0; #endif
frame_scroll_delta_ = ScrollOffset();
} }
void LayoutShiftTracker::NotifyInput(const WebInputEvent& event) { void LayoutShiftTracker::NotifyInput(const WebInputEvent& event) {
......
...@@ -58,6 +58,7 @@ class CORE_EXPORT LayoutShiftTracker { ...@@ -58,6 +58,7 @@ class CORE_EXPORT LayoutShiftTracker {
const PropertyTreeState&, const PropertyTreeState&,
FloatRect old_rect, FloatRect old_rect,
FloatRect new_rect); FloatRect new_rect);
void ReportShift(double score_delta, double weighted_score_delta);
void TimerFired(TimerBase*) {} void TimerFired(TimerBase*) {}
std::unique_ptr<TracedValue> PerFrameTraceData(double score_delta, std::unique_ptr<TracedValue> PerFrameTraceData(double score_delta,
bool input_detected) const; bool input_detected) const;
......
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