Commit 33cd2bcc authored by Philip Rogers's avatar Philip Rogers Committed by Commit Bot

Defer preferred size updates to after commit

https://crrev.com/581383 removed a preferred size timer and started
synchronously updating preferred sizes in DidUpdateMainFrameLayout.
This caused a performance regression because, even though layout is
up-to-date, the preferred contents size may need to be re-computed.
Script can cause many layouts per frame which was a performance
regression because many multiple preferred contents size updates are now
occurring per frame.

This patch adds a bool for if a layout occurred which may have changed
the preferred content size, and defers the update until after the
commit.

Bug: 872599
Change-Id: Idfe1ba523b1ecfdf8f959bafc2e20ef6a52487bb
Reviewed-on: https://chromium-review.googlesource.com/1172059
Commit-Queue: Philip Rogers <pdr@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582708}
parent e10dc3ec
......@@ -26,7 +26,8 @@ void AwRenderViewExt::DidCommitCompositorFrame() {
}
void AwRenderViewExt::DidUpdateMainFrameLayout() {
UpdateContentsSize();
// The size may have changed.
needs_contents_size_update_ = true;
}
void AwRenderViewExt::OnDestruct() {
......@@ -47,6 +48,10 @@ void AwRenderViewExt::UpdateContentsSize() {
if (!webview || !main_render_frame)
return;
if (!needs_contents_size_update_)
return;
needs_contents_size_update_ = false;
gfx::Size contents_size = main_render_frame->GetWebFrame()->DocumentSize();
// Fall back to contentsPreferredMinimumSize if the mainFrame is reporting a
......
......@@ -31,6 +31,10 @@ class AwRenderViewExt : public content::RenderViewObserver {
gfx::Size last_sent_contents_size_;
// Whether the contents size may have changed and |UpdateContentsSize| needs
// to be called.
bool needs_contents_size_update_ = true;
DISALLOW_COPY_AND_ASSIGN(AwRenderViewExt);
};
......
......@@ -1135,6 +1135,7 @@ GURL RenderViewImpl::GetURLForGraphicsContext3DForWidget() {
void RenderViewImpl::DidCommitCompositorFrameForWidget() {
for (auto& observer : observers_)
observer.DidCommitCompositorFrame();
UpdatePreferredSize();
}
void RenderViewImpl::DidCompletePageScaleAnimationForWidget() {
......@@ -1666,7 +1667,8 @@ void RenderViewImpl::DidUpdateMainFrameLayout() {
for (auto& observer : observers_)
observer.DidUpdateMainFrameLayout();
UpdatePreferredSize();
// The main frame may have changed size.
needs_preferred_size_update_ = true;
}
void RenderViewImpl::NavigateBackForwardSoon(int offset) {
......@@ -1739,6 +1741,11 @@ void RenderViewImpl::UpdatePreferredSize() {
// message.
if (!send_preferred_size_changes_ || !webview())
return;
if (!needs_preferred_size_update_)
return;
needs_preferred_size_update_ = false;
blink::WebSize tmp_size = webview()->ContentsPreferredMinimumSize();
blink::WebRect tmp_rect(0, 0, tmp_size.width, tmp_size.height);
WidgetClient()->ConvertViewportToWindow(&tmp_rect);
......@@ -1853,6 +1860,8 @@ void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
if (!webview())
return;
needs_preferred_size_update_ = true;
// We need to ensure |UpdatePreferredSize| gets called. If a layout is needed,
// force an update here which will call |DidUpdateMainFrameLayout|.
webview()->UpdateLifecycle(WebWidget::LifecycleUpdate::kLayout);
......
......@@ -553,6 +553,10 @@ class CONTENT_EXPORT RenderViewImpl : private RenderWidget,
// If true, we send IPC messages when |preferred_size_| changes.
bool send_preferred_size_changes_ = false;
// Whether the preferred size may have changed and |UpdatePreferredSize| needs
// to be called.
bool needs_preferred_size_update_ = true;
// If non-empty, and |send_preferred_size_changes_| is true, disable drawing
// scroll bars on windows smaller than this size. Used for windows that the
// browser resizes to the size of the content, such as browser action popups.
......
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