<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[171451] branches/safari-600.1-branch/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/171451">171451</a></dd>
<dt>Author</dt> <dd>dburkart@apple.com</dd>
<dt>Date</dt> <dd>2014-07-23 00:14:46 -0700 (Wed, 23 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/171336">r171336</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6001branchSourceWebCoreChangeLog">branches/safari-600.1-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari6001branchSourceWebCorepageChromeClienth">branches/safari-600.1-branch/Source/WebCore/page/ChromeClient.h</a></li>
<li><a href="#branchessafari6001branchSourceWebCorepageFrameViewcpp">branches/safari-600.1-branch/Source/WebCore/page/FrameView.cpp</a></li>
<li><a href="#branchessafari6001branchSourceWebCorepageFrameViewh">branches/safari-600.1-branch/Source/WebCore/page/FrameView.h</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2ChangeLog">branches/safari-600.1-branch/Source/WebKit2/ChangeLog</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2WebProcessWebCoreSupportWebChromeClienth">branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2WebProcessWebCoreSupportiosWebChromeClientIOSmm">branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2WebProcessWebPageViewUpdateDispatchercpp">branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ViewUpdateDispatcher.cpp</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2WebProcessWebPageViewUpdateDispatcherh">branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ViewUpdateDispatcher.h</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2WebProcessWebPageWebPagecpp">branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2WebProcessWebPageWebPageh">branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2WebProcessWebPageiosWebPageIOSmm">branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2WebProcessWebPagemacRemoteLayerTreeDrawingAreamm">branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6001branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebCore/ChangeLog (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebCore/ChangeLog        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebCore/ChangeLog        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -1,5 +1,42 @@
</span><span class="cx"> 2014-07-22 Dana Burkart &lt;dburkart@apple.com&gt;
</span><span class="cx">     
</span><ins>+        Merge r171336.
+
+    2014-07-21  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
+            [iOS][WK2] Improve event throttling for Scroll Events
+            https://bugs.webkit.org/show_bug.cgi?id=135082
+            &lt;rdar://problem/17445266&gt;
+
+            Reviewed by Simon Fraser.
+
+            This patch is composed of two parts. The first part in the WebKit layer
+            track an approximate measurement of the main thread responsiveness.
+            The second part in WebCore use that information to avoid sending events
+            if a page is unresponsive.
+
+            In WebCore, this patch only consider scroll events so far. Hopefully the concept
+            should be easy to generalize.
+
+            * loader/EmptyClients.h:
+            * page/ChromeClient.h:
+            Chrome client provides us with one information: how long an incoming event should be delayed.
+            Every port is free to implement whatever logic is suitable for them.
+
+            * page/FrameView.cpp:
+            (WebCore::FrameView::FrameView):
+            (WebCore::FrameView::reset):
+            (WebCore::FrameView::delayedScrollEventTimerFired):
+            (WebCore::FrameView::scrollPositionChanged):
+            (WebCore::FrameView::sendScrollEvent):
+            * page/FrameView.h:
+            Scroll events do not have any associated information so they can be coalesced by just skipping
+            all input hapenning during the throttling delay.
+
+            The implementation is done by using a timer to delay the events.
+
+2014-07-22 Dana Burkart &lt;dburkart@apple.com&gt;
+    
</ins><span class="cx">         Merge r171332.
</span><span class="cx"> 
</span><span class="cx">     2014-07-21  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebCorepageChromeClienth"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebCore/page/ChromeClient.h (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebCore/page/ChromeClient.h        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebCore/page/ChromeClient.h        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -236,6 +236,8 @@
</span><span class="cx">     virtual void didPreventDefaultForEvent() = 0;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    virtual std::chrono::milliseconds eventThrottlingDelay() { return std::chrono::milliseconds::zero(); };
+
</ins><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     virtual void didReceiveMobileDocType(bool) = 0;
</span><span class="cx">     virtual void setNeedsScrollNotifications(Frame*, bool) = 0;
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebCore/page/FrameView.cpp (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebCore/page/FrameView.cpp        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebCore/page/FrameView.cpp        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -171,6 +171,7 @@
</span><span class="cx">     , m_wasScrolledByUser(false)
</span><span class="cx">     , m_inProgrammaticScroll(false)
</span><span class="cx">     , m_safeToPropagateScrollToParent(true)
</span><ins>+    , m_delayedScrollEventTimer(this, &amp;FrameView::delayedScrollEventTimerFired)
</ins><span class="cx">     , m_isTrackingRepaints(false)
</span><span class="cx">     , m_shouldUpdateWhileOffscreen(true)
</span><span class="cx">     , m_exposedRect(FloatRect::infiniteRect())
</span><span class="lines">@@ -256,6 +257,7 @@
</span><span class="cx">     m_firstLayoutCallbackPending = false;
</span><span class="cx">     m_wasScrolledByUser = false;
</span><span class="cx">     m_safeToPropagateScrollToParent = true;
</span><ins>+    m_delayedScrollEventTimer.stop();
</ins><span class="cx">     m_lastViewportSize = IntSize();
</span><span class="cx">     m_lastZoomFactor = 1.0f;
</span><span class="cx">     m_isTrackingRepaints = false;
</span><span class="lines">@@ -1704,6 +1706,11 @@
</span><span class="cx">     return maximumOffset;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void FrameView::delayedScrollEventTimerFired(Timer&lt;FrameView&gt;&amp;)
+{
+    sendScrollEvent();
+}
+
</ins><span class="cx"> bool FrameView::fixedElementsLayoutRelativeToFrame() const
</span><span class="cx"> {
</span><span class="cx">     return frame().settings().fixedElementsLayoutRelativeToFrame();
</span><span class="lines">@@ -2040,9 +2047,14 @@
</span><span class="cx"> 
</span><span class="cx"> void FrameView::scrollPositionChanged(const IntPoint&amp; oldPosition, const IntPoint&amp; newPosition)
</span><span class="cx"> {
</span><del>-    frame().eventHandler().sendScrollEvent();
-    frame().eventHandler().dispatchFakeMouseMoveEventSoon();
-    
</del><ins>+    std::chrono::milliseconds throttlingDelay = frame().page()-&gt;chrome().client().eventThrottlingDelay();
+
+    if (throttlingDelay == std::chrono::milliseconds::zero()) {
+        m_delayedScrollEventTimer.stop();
+        sendScrollEvent();
+    } else if (!m_delayedScrollEventTimer.isActive())
+        m_delayedScrollEventTimer.startOneShot(throttlingDelay);
+
</ins><span class="cx">     if (Document* document = frame().document())
</span><span class="cx">         document-&gt;sendWillRevealEdgeEventsIfNeeded(oldPosition, newPosition, visibleContentRect(), contentsSize());
</span><span class="cx"> 
</span><span class="lines">@@ -4138,6 +4150,12 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void FrameView::sendScrollEvent()
+{
+    frame().eventHandler().sendScrollEvent();
+    frame().eventHandler().dispatchFakeMouseMoveEventSoon();
+}
+
</ins><span class="cx"> void FrameView::removeChild(Widget* widget)
</span><span class="cx"> {
</span><span class="cx">     if (widget-&gt;isFrameView())
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebCorepageFrameViewh"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebCore/page/FrameView.h (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebCore/page/FrameView.h        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebCore/page/FrameView.h        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -241,6 +241,7 @@
</span><span class="cx">     virtual bool isRubberBandInProgress() const override;
</span><span class="cx">     virtual IntPoint minimumScrollPosition() const override;
</span><span class="cx">     virtual IntPoint maximumScrollPosition() const override;
</span><ins>+    void delayedScrollEventTimerFired(Timer&lt;FrameView&gt;&amp;);
</ins><span class="cx"> 
</span><span class="cx">     // This is different than visibleContentRect() in that it ignores negative (or overly positive)
</span><span class="cx">     // offsets from rubber-banding, and it takes zooming into account. 
</span><span class="lines">@@ -597,6 +598,7 @@
</span><span class="cx">     void scrollToAnchor();
</span><span class="cx">     void scrollPositionChanged(const IntPoint&amp; oldPosition, const IntPoint&amp; newPosition);
</span><span class="cx">     void scrollableAreaSetChanged();
</span><ins>+    void sendScrollEvent();
</ins><span class="cx"> 
</span><span class="cx">     bool hasCustomScrollbars() const;
</span><span class="cx"> 
</span><span class="lines">@@ -666,6 +668,7 @@
</span><span class="cx">     bool m_wasScrolledByUser;
</span><span class="cx">     bool m_inProgrammaticScroll;
</span><span class="cx">     bool m_safeToPropagateScrollToParent;
</span><ins>+    Timer&lt;FrameView&gt; m_delayedScrollEventTimer;
</ins><span class="cx"> 
</span><span class="cx">     double m_lastPaintTime;
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/ChangeLog (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/ChangeLog        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebKit2/ChangeLog        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -1,5 +1,57 @@
</span><span class="cx"> 2014-07-22 Dana Burkart &lt;dburkart@apple.com&gt;
</span><span class="cx">     
</span><ins>+        Merge r171336.
+
+    2014-07-21  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
+            [iOS][WK2] Improve event throttling for Scroll Events
+            https://bugs.webkit.org/show_bug.cgi?id=135082
+            &lt;rdar://problem/17445266&gt;
+
+            Reviewed by Simon Fraser.
+
+            In the WebKit layer, we want a measure that is representative of the responsiveness.
+
+            In this patch, I use the total delay between a VisibleContentRectUpdate being dispatched
+            by the UIProcess, and the time RemoteLayerTreeDrawingArea flushes the layer tree.
+
+            The value used for eventThrottlingDelay() is computed by averaging the new value with
+            the old values with a 80/20 split, favoring the old data. Favoring historical data
+            over the last timing avoid excessively throttling for a single slow frame.
+
+            The computation of m_estimatedMainThreadLatency can be improved in the future, this is
+            a first cut keeping things simple.
+
+            With m_estimatedMainThreadLatency in our hands, we can compute our eventThrottlingDelay().
+            If m_estimatedMainThreadLatency is smaller than a single frame timespan, we have a fast page
+            and nothing is throttled.
+
+            If is it more than a frame, we throttle such that we can at least render two frames
+            per event dispatch based on the historical data.
+
+            The exact values will need some tweaking, but this set ensures well written pages get
+            60 events per seconds, while slow pages do not waste too much time on events.
+
+            * WebProcess/WebCoreSupport/WebChromeClient.h:
+            * WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm:
+            (WebKit::WebChromeClient::eventThrottlingDelay):
+            * WebProcess/WebPage/ViewUpdateDispatcher.cpp:
+            (WebKit::ViewUpdateDispatcher::visibleContentRectUpdate):
+            (WebKit::ViewUpdateDispatcher::dispatchVisibleContentRectUpdate):
+            * WebProcess/WebPage/ViewUpdateDispatcher.h:
+            * WebProcess/WebPage/WebPage.cpp:
+            (WebKit::WebPage::WebPage):
+            (WebKit::WebPage::didFlushLayerTreeAtTime):
+            (WebKit::WebPage::didCommitLoad):
+            * WebProcess/WebPage/WebPage.h:
+            * WebProcess/WebPage/ios/WebPageIOS.mm:
+            (WebKit::WebPage::eventThrottlingDelay):
+            (WebKit::WebPage::updateVisibleContentRects):
+            * WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm:
+            (WebKit::RemoteLayerTreeDrawingArea::flushLayers):
+
+2014-07-22 Dana Burkart &lt;dburkart@apple.com&gt;
+    
</ins><span class="cx">         Merge r171329.
</span><span class="cx"> 
</span><span class="cx">     2014-07-21  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2WebProcessWebCoreSupportWebChromeClienth"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -181,6 +181,8 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void webAppOrientationsUpdated() override;
</span><span class="cx">     virtual void showPlaybackTargetPicker(bool hasVideo) override;
</span><ins>+
+    virtual std::chrono::milliseconds eventThrottlingDelay() override;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ORIENTATION_EVENTS)
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2WebProcessWebCoreSupportiosWebChromeClientIOSmm"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebChromeClientIOS.mm        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -135,6 +135,11 @@
</span><span class="cx">     m_page-&gt;send(Messages::WebPageProxy::ShowPlaybackTargetPicker(hasVideo, m_page-&gt;rectForElementAtInteractionLocation()));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+std::chrono::milliseconds WebChromeClient::eventThrottlingDelay()
+{
+    return m_page-&gt;eventThrottlingDelay();
+}
+
</ins><span class="cx"> int WebChromeClient::deviceOrientation() const
</span><span class="cx"> {
</span><span class="cx">     return m_page-&gt;deviceOrientation();
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2WebProcessWebPageViewUpdateDispatchercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ViewUpdateDispatcher.cpp (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ViewUpdateDispatcher.cpp        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ViewUpdateDispatcher.cpp        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -61,7 +61,11 @@
</span><span class="cx">     {
</span><span class="cx">         SpinLockHolder locker(&amp;m_dataMutex);
</span><span class="cx">         updateListWasEmpty = m_latestUpdate.isEmpty();
</span><del>-        m_latestUpdate.set(pageID, visibleContentRectUpdateInfo);
</del><ins>+        auto iterator = m_latestUpdate.find(pageID);
+        if (iterator == m_latestUpdate.end())
+            m_latestUpdate.set&lt;UpdateData&gt;(pageID, { visibleContentRectUpdateInfo, visibleContentRectUpdateInfo.timestamp() });
+        else
+            iterator-&gt;value.visibleContentRectUpdateInfo = visibleContentRectUpdateInfo;
</ins><span class="cx">     }
</span><span class="cx">     if (updateListWasEmpty)
</span><span class="cx">         RunLoop::main().dispatch(bind(&amp;ViewUpdateDispatcher::dispatchVisibleContentRectUpdate, this));
</span><span class="lines">@@ -69,7 +73,7 @@
</span><span class="cx"> 
</span><span class="cx"> void ViewUpdateDispatcher::dispatchVisibleContentRectUpdate()
</span><span class="cx"> {
</span><del>-    HashMap&lt;uint64_t, VisibleContentRectUpdateInfo&gt; localCopy;
</del><ins>+    HashMap&lt;uint64_t, UpdateData&gt; localCopy;
</ins><span class="cx">     {
</span><span class="cx">         SpinLockHolder locker(&amp;m_dataMutex);
</span><span class="cx">         localCopy.swap(m_latestUpdate);
</span><span class="lines">@@ -77,7 +81,7 @@
</span><span class="cx"> 
</span><span class="cx">     for (auto&amp; slot : localCopy) {
</span><span class="cx">         if (WebPage* webPage = WebProcess::shared().webPage(slot.key))
</span><del>-            webPage-&gt;updateVisibleContentRects(slot.value);
</del><ins>+            webPage-&gt;updateVisibleContentRects(slot.value.visibleContentRectUpdateInfo, slot.value.oldestTimestamp);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2WebProcessWebPageViewUpdateDispatcherh"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ViewUpdateDispatcher.h (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ViewUpdateDispatcher.h        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ViewUpdateDispatcher.h        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -51,9 +51,14 @@
</span><span class="cx"> 
</span><span class="cx">     void dispatchVisibleContentRectUpdate();
</span><span class="cx"> 
</span><ins>+    struct UpdateData {
+        VisibleContentRectUpdateInfo visibleContentRectUpdateInfo;
+        double oldestTimestamp;
+    };
+
</ins><span class="cx">     RefPtr&lt;WorkQueue&gt; m_queue;
</span><span class="cx">     SpinLock m_dataMutex;
</span><del>-    HashMap&lt;uint64_t, VisibleContentRectUpdateInfo&gt; m_latestUpdate;
</del><ins>+    HashMap&lt;uint64_t, UpdateData&gt; m_latestUpdate;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -304,6 +304,9 @@
</span><span class="cx">     , m_userIsInteracting(false)
</span><span class="cx">     , m_hasPendingBlurNotification(false)
</span><span class="cx">     , m_useTestingViewportConfiguration(false)
</span><ins>+    , m_isInStableState(true)
+    , m_oldestNonStableUpdateVisibleContentRectsTimestamp(std::chrono::milliseconds::zero())
+    , m_estimatedLatency(std::chrono::milliseconds::zero())
</ins><span class="cx">     , m_screenSize(parameters.screenSize)
</span><span class="cx">     , m_availableScreenSize(parameters.availableScreenSize)
</span><span class="cx">     , m_deviceOrientation(0)
</span><span class="lines">@@ -2864,7 +2867,21 @@
</span><span class="cx">     layerTransaction.setAllowsUserScaling(allowsUserScaling());
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><ins>+
+void WebPage::didFlushLayerTreeAtTime(std::chrono::milliseconds timestamp)
+{
+#if PLATFORM(IOS)
+    if (m_oldestNonStableUpdateVisibleContentRectsTimestamp != std::chrono::milliseconds::zero()) {
+        std::chrono::milliseconds elapsed = timestamp - m_oldestNonStableUpdateVisibleContentRectsTimestamp;
+        m_oldestNonStableUpdateVisibleContentRectsTimestamp = std::chrono::milliseconds::zero();
+
+        m_estimatedLatency = std::chrono::milliseconds(static_cast&lt;std::chrono::milliseconds::rep&gt;(m_estimatedLatency.count() * 0.80 + elapsed.count() * 0.20));
+    }
+#else
+    UNUSED_PARAM(timestamp);
</ins><span class="cx"> #endif
</span><ins>+}
+#endif
</ins><span class="cx"> 
</span><span class="cx">     
</span><span class="cx"> #if ENABLE(INSPECTOR)
</span><span class="lines">@@ -4449,6 +4466,7 @@
</span><span class="cx">     m_scaleWasSetByUIProcess = false;
</span><span class="cx">     m_firstLayerTreeTransactionIDAfterDidCommitLoad = toRemoteLayerTreeDrawingArea(*m_drawingArea).nextTransactionID();
</span><span class="cx">     m_userHasChangedPageScaleFactor = false;
</span><ins>+    m_estimatedLatency = std::chrono::milliseconds(1000 / 60);
</ins><span class="cx"> 
</span><span class="cx">     WebProcess::shared().eventDispatcher().clearQueuedTouchEventsForPage(*this);
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -223,6 +223,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     void willCommitLayerTree(RemoteLayerTreeTransaction&amp;);
</span><ins>+    void didFlushLayerTreeAtTime(std::chrono::milliseconds);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(INSPECTOR)
</span><span class="lines">@@ -509,6 +510,8 @@
</span><span class="cx">     void dispatchAsynchronousTouchEvents(const Vector&lt;WebTouchEvent, 1&gt;&amp; queue);
</span><span class="cx">     void contentSizeCategoryDidChange(const String&amp;);
</span><span class="cx">     void executeEditCommandWithCallback(const String&amp;, uint64_t callbackID);
</span><ins>+
+    std::chrono::milliseconds eventThrottlingDelay() const;
</ins><span class="cx"> #if ENABLE(INSPECTOR)
</span><span class="cx">     void showInspectorHighlight(const WebCore::Highlight&amp;);
</span><span class="cx">     void hideInspectorHighlight();
</span><span class="lines">@@ -748,7 +751,7 @@
</span><span class="cx">     void setDeviceOrientation(int32_t);
</span><span class="cx">     void dynamicViewportSizeUpdate(const WebCore::FloatSize&amp; minimumLayoutSize, const WebCore::FloatSize&amp; minimumLayoutSizeForMinimalUI, const WebCore::FloatSize&amp; maximumUnobscuredSize, const WebCore::FloatRect&amp; targetExposedContentRect, const WebCore::FloatRect&amp; targetUnobscuredRect, const WebCore::FloatRect&amp; targetUnobscuredRectInScrollViewCoordinates, double scale, int32_t deviceOrientation);
</span><span class="cx">     void synchronizeDynamicViewportUpdate(double&amp; newTargetScale, WebCore::FloatPoint&amp; newScrollPosition, uint64_t&amp; nextValidLayerTreeTransactionID);
</span><del>-    void updateVisibleContentRects(const VisibleContentRectUpdateInfo&amp;);
</del><ins>+    void updateVisibleContentRects(const VisibleContentRectUpdateInfo&amp;, double oldestTimestamp);
</ins><span class="cx">     bool scaleWasSetByUIProcess() const { return m_scaleWasSetByUIProcess; }
</span><span class="cx">     void willStartUserTriggeredZooming();
</span><span class="cx">     void applicationWillResignActive();
</span><span class="lines">@@ -1235,6 +1238,9 @@
</span><span class="cx">     bool m_userIsInteracting;
</span><span class="cx">     bool m_hasPendingBlurNotification;
</span><span class="cx">     bool m_useTestingViewportConfiguration;
</span><ins>+    bool m_isInStableState;
+    std::chrono::milliseconds m_oldestNonStableUpdateVisibleContentRectsTimestamp;
+    std::chrono::milliseconds m_estimatedLatency;
</ins><span class="cx">     WebCore::FloatSize m_screenSize;
</span><span class="cx">     WebCore::FloatSize m_availableScreenSize;
</span><span class="cx">     RefPtr&lt;WebCore::Range&gt; m_currentBlockSelection;
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -1679,6 +1679,14 @@
</span><span class="cx">     send(Messages::WebPageProxy::VoidCallback(callbackID));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+std::chrono::milliseconds WebPage::eventThrottlingDelay() const
+{
+    if (m_isInStableState || m_estimatedLatency &lt;= std::chrono::milliseconds(1000 / 60))
+        return std::chrono::milliseconds::zero();
+
+    return std::chrono::milliseconds(std::min&lt;std::chrono::milliseconds::rep&gt;(m_estimatedLatency.count() * 2, 1000));
+}
+
</ins><span class="cx"> void WebPage::syncApplyAutocorrection(const String&amp; correction, const String&amp; originalText, bool&amp; correctionApplied)
</span><span class="cx"> {
</span><span class="cx">     RefPtr&lt;Range&gt; range;
</span><span class="lines">@@ -2463,18 +2471,19 @@
</span><span class="cx">     return adjustExposedRectForNewScale(exposedRect, exposedRectScale, newScale);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebPage::updateVisibleContentRects(const VisibleContentRectUpdateInfo&amp; visibleContentRectUpdateInfo)
</del><ins>+void WebPage::updateVisibleContentRects(const VisibleContentRectUpdateInfo&amp; visibleContentRectUpdateInfo, double oldestTimestamp)
</ins><span class="cx"> {
</span><span class="cx">     // Skip any VisibleContentRectUpdate that have been queued before DidCommitLoad suppresses the updates in the UIProcess.
</span><span class="cx">     if (visibleContentRectUpdateInfo.lastLayerTreeTransactionID() &lt; m_firstLayerTreeTransactionIDAfterDidCommitLoad)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_hasReceivedVisibleContentRectsAfterDidCommitLoad = true;
</span><ins>+    m_isInStableState = visibleContentRectUpdateInfo.inStableState();
</ins><span class="cx"> 
</span><span class="cx">     double scaleNoiseThreshold = 0.005;
</span><span class="cx">     double filteredScale = visibleContentRectUpdateInfo.scale();
</span><span class="cx">     double currentScale = m_page-&gt;pageScaleFactor();
</span><del>-    if (!visibleContentRectUpdateInfo.inStableState() &amp;&amp; fabs(filteredScale - m_page-&gt;pageScaleFactor()) &lt; scaleNoiseThreshold) {
</del><ins>+    if (!m_isInStableState &amp;&amp; fabs(filteredScale - m_page-&gt;pageScaleFactor()) &lt; scaleNoiseThreshold) {
</ins><span class="cx">         // Tiny changes of scale during interactive zoom cause content to jump by one pixel, creating
</span><span class="cx">         // visual noise. We filter those useless updates.
</span><span class="cx">         filteredScale = currentScale;
</span><span class="lines">@@ -2483,27 +2492,31 @@
</span><span class="cx">     double boundedScale = std::min(m_viewportConfiguration.maximumScale(), std::max(m_viewportConfiguration.minimumScale(), filteredScale));
</span><span class="cx"> 
</span><span class="cx">     // Skip progressively redrawing tiles if pinch-zooming while the system is under memory pressure.
</span><del>-    if (boundedScale != currentScale &amp;&amp; !visibleContentRectUpdateInfo.inStableState() &amp;&amp; memoryPressureHandler().isUnderMemoryPressure())
</del><ins>+    if (boundedScale != currentScale &amp;&amp; !m_isInStableState &amp;&amp; memoryPressureHandler().isUnderMemoryPressure())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    if (m_isInStableState)
+        m_hasStablePageScaleFactor = true;
+    else {
+        if (m_oldestNonStableUpdateVisibleContentRectsTimestamp == std::chrono::milliseconds::zero())
+            m_oldestNonStableUpdateVisibleContentRectsTimestamp = std::chrono::milliseconds(static_cast&lt;std::chrono::milliseconds::rep&gt;(oldestTimestamp * 1000));
+    }
+
</ins><span class="cx">     FloatRect exposedRect = visibleContentRectUpdateInfo.exposedRect();
</span><span class="cx">     FloatRect adjustedExposedRect = adjustExposedRectForBoundedScale(exposedRect, visibleContentRectUpdateInfo.scale(), boundedScale);
</span><span class="cx">     m_drawingArea-&gt;setExposedContentRect(adjustedExposedRect);
</span><span class="cx"> 
</span><span class="cx">     IntPoint scrollPosition = roundedIntPoint(visibleContentRectUpdateInfo.unobscuredRect().location());
</span><span class="cx"> 
</span><del>-    if (!m_hasStablePageScaleFactor &amp;&amp; visibleContentRectUpdateInfo.inStableState())
-        m_hasStablePageScaleFactor = true;
-
</del><span class="cx">     float floatBoundedScale = boundedScale;
</span><span class="cx">     bool hasSetPageScale = false;
</span><span class="cx">     if (floatBoundedScale != currentScale) {
</span><span class="cx">         m_scaleWasSetByUIProcess = true;
</span><del>-        m_hasStablePageScaleFactor = visibleContentRectUpdateInfo.inStableState();
</del><ins>+        m_hasStablePageScaleFactor = m_isInStableState;
</ins><span class="cx"> 
</span><span class="cx">         m_dynamicSizeUpdateHistory.clear();
</span><span class="cx"> 
</span><del>-        m_page-&gt;setPageScaleFactor(floatBoundedScale, scrollPosition, visibleContentRectUpdateInfo.inStableState());
</del><ins>+        m_page-&gt;setPageScaleFactor(floatBoundedScale, scrollPosition, m_isInStableState);
</ins><span class="cx">         hasSetPageScale = true;
</span><span class="cx"> 
</span><span class="cx">         if (LayerTreeHost* layerTreeHost = m_drawingArea-&gt;layerTreeHost())
</span><span class="lines">@@ -2511,7 +2524,7 @@
</span><span class="cx">         send(Messages::WebPageProxy::PageScaleFactorDidChange(floatBoundedScale));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (!hasSetPageScale &amp;&amp; visibleContentRectUpdateInfo.inStableState()) {
</del><ins>+    if (!hasSetPageScale &amp;&amp; m_isInStableState) {
</ins><span class="cx">         m_page-&gt;setPageScaleFactor(floatBoundedScale, scrollPosition, true);
</span><span class="cx">         hasSetPageScale = true;
</span><span class="cx">     }
</span><span class="lines">@@ -2529,7 +2542,7 @@
</span><span class="cx"> 
</span><span class="cx">     frameView.setScrollVelocity(horizontalVelocity, verticalVelocity, scaleChangeRate, visibleContentRectUpdateInfo.timestamp());
</span><span class="cx"> 
</span><del>-    if (visibleContentRectUpdateInfo.inStableState())
</del><ins>+    if (m_isInStableState)
</ins><span class="cx">         m_page-&gt;mainFrame().view()-&gt;setCustomFixedPositionLayoutRect(enclosingIntRect(visibleContentRectUpdateInfo.customFixedPositionRect()));
</span><span class="cx"> 
</span><span class="cx">     if (!visibleContentRectUpdateInfo.isChangingObscuredInsetsInteractively())
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2WebProcessWebPagemacRemoteLayerTreeDrawingAreamm"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm (171450 => 171451)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm        2014-07-23 07:12:14 UTC (rev 171450)
+++ branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm        2014-07-23 07:14:46 UTC (rev 171451)
</span><span class="lines">@@ -365,8 +365,16 @@
</span><span class="cx">     RefPtr&lt;BackingStoreFlusher&gt; backingStoreFlusher = BackingStoreFlusher::create(WebProcess::shared().parentProcessConnection(), WTF::move(commitEncoder), WTF::move(contextsToFlush));
</span><span class="cx">     m_pendingBackingStoreFlusher = backingStoreFlusher;
</span><span class="cx"> 
</span><del>-    dispatch_async(m_commitQueue, [backingStoreFlusher]{
</del><ins>+    uint64_t pageID = m_webPage.pageID();
+    dispatch_async(m_commitQueue, [backingStoreFlusher, pageID] {
</ins><span class="cx">         backingStoreFlusher-&gt;flush();
</span><ins>+
+        if (WebPage *webPage = WebProcess::shared().webPage(pageID)) {
+            std::chrono::milliseconds timestamp = std::chrono::milliseconds(static_cast&lt;std::chrono::milliseconds::rep&gt;(monotonicallyIncreasingTime() * 1000));
+            dispatch_async(dispatch_get_main_queue(), ^{
+                webPage-&gt;didFlushLayerTreeAtTime(timestamp);
+            });
+        }
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>