Commit 4e710126 authored by Steve Kobes's avatar Steve Kobes Committed by Commit Bot

Report layout jank fractions to the WebLocalFrameClient.

This will allow the page_load_metrics component to observe the jank.

Also address nits in JankTracker::NotifyPrePaintFinished (empty viewport
check, DCHECK for non-zero jank fraction).

Bug: 581518
Change-Id: I22eab226dac31bd1b0ce284240bbca019ce49868
Reviewed-on: https://chromium-review.googlesource.com/c/1280616Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: Steve Kobes <skobes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599912}
parent 6bc77bbd
......@@ -666,6 +666,9 @@ class BLINK_EXPORT WebLocalFrameClient {
virtual void DidObserveNewCssPropertyUsage(int /*css_property*/,
bool /*is_animated*/) {}
// Reports that visible elements in the frame shifted (bit.ly/lsm-explainer).
virtual void DidObserveLayoutJank(double jank_fraction) {}
// Script notifications ------------------------------------------------
// Notifies that a new script context has been created for this frame.
......
......@@ -735,6 +735,11 @@ void LocalFrameClientImpl::DidObserveNewCssPropertyUsage(int css_property,
}
}
void LocalFrameClientImpl::DidObserveLayoutJank(double jank_fraction) {
if (WebLocalFrameClient* client = web_frame_->Client())
client->DidObserveLayoutJank(jank_fraction);
}
bool LocalFrameClientImpl::ShouldTrackUseCounter(const KURL& url) {
if (web_frame_->Client())
return web_frame_->Client()->ShouldTrackUseCounter(url);
......
......@@ -148,6 +148,7 @@ class LocalFrameClientImpl final : public LocalFrameClient {
void DidObserveLoadingBehavior(WebLoadingBehaviorFlag) override;
void DidObserveNewFeatureUsage(mojom::WebFeature) override;
void DidObserveNewCssPropertyUsage(int, bool) override;
void DidObserveLayoutJank(double jank_fraction) override;
bool ShouldTrackUseCounter(const KURL&) override;
void SelectorMatchChanged(const Vector<String>& added_selectors,
const Vector<String>& removed_selectors) override;
......
......@@ -223,6 +223,10 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
// process for histograms.
virtual void DidObserveNewCssPropertyUsage(int /*css_property*/,
bool /*is_animated*/) {}
// Reports that visible elements in the frame shifted (bit.ly/lsm-explainer).
virtual void DidObserveLayoutJank(double jank_fraction) {}
// Will be called by a Page upon DidCommitLoad, deciding whether to track
// UseCounter usage or not based on its url.
virtual bool ShouldTrackUseCounter(const KURL&) { return true; }
......
......@@ -6,6 +6,7 @@
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/location.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
......@@ -171,9 +172,14 @@ void JankTracker::NotifyPrePaintFinished() {
IntRect viewport = frame_view_->GetScrollableArea()->VisibleContentRect();
double granularity_scale = RegionGranularityScale(viewport);
viewport.Scale(granularity_scale);
double viewport_area = double(viewport.Width()) * double(viewport.Height());
if (viewport.IsEmpty())
return;
double viewport_area = double(viewport.Width()) * double(viewport.Height());
double jank_fraction = region_.Area() / viewport_area;
DCHECK_GT(jank_fraction, 0);
score_ += jank_fraction;
DVLOG(1) << "viewport " << (jank_fraction * 100)
......@@ -184,7 +190,9 @@ void JankTracker::NotifyPrePaintFinished() {
PerFrameTraceData(jank_fraction, granularity_scale),
"frame", ToTraceValue(&frame_view_->GetFrame()));
if (RuntimeEnabledFeatures::LayoutJankAPIEnabled() && jank_fraction > 0 &&
frame_view_->GetFrame().Client()->DidObserveLayoutJank(jank_fraction);
if (RuntimeEnabledFeatures::LayoutJankAPIEnabled() &&
frame_view_->GetFrame().DomWindow()) {
WindowPerformance* performance =
DOMWindowPerformance::performance(*frame_view_->GetFrame().DomWindow());
......
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