<!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>[168493] trunk/Source/WebKit2</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/168493">168493</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2014-05-08 13:56:37 -0700 (Thu, 08 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>[iOS WebKit2] Flush RemoteLayerBackingStore contexts on a secondary queue
https://bugs.webkit.org/show_bug.cgi?id=132667
<rdar://problem/15349483>
Reviewed by Darin Adler.
* Shared/mac/RemoteLayerBackingStore.h:
* Shared/mac/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::takeFrontContextPendingFlush):
(WebKit::RemoteLayerBackingStore::flush): Deleted.
Add takeFrontContextPendingFlush, which returns the painted-but-not-yet-flushed front context,
and drops our reference to it. This needs to be called on all backing store between paints.
* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h:
(WebKit::RemoteLayerTreeDrawingArea::BackingStoreFlusher::hasFlushed):
* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm:
(WebKit::RemoteLayerTreeDrawingArea::RemoteLayerTreeDrawingArea):
(WebKit::RemoteLayerTreeDrawingArea::~RemoteLayerTreeDrawingArea):
(WebKit::RemoteLayerTreeDrawingArea::flushLayers):
(WebKit::RemoteLayerTreeDrawingArea::BackingStoreFlusher::create):
(WebKit::RemoteLayerTreeDrawingArea::BackingStoreFlusher::BackingStoreFlusher):
(WebKit::RemoteLayerTreeDrawingArea::BackingStoreFlusher::flush):
(WebKit::flushBackingStoreChangesInTransaction): Deleted.
Flush backing store and send the layer tree commit to the UI process from a dispatch queue.
We will only ever have a single commit in flight at a time, and there's a new
RELEASE_ASSERT to ensure that is the case.
We package up the commit on the main thread; the queue calls CGContextFlush
on all of the newly painted contexts and then tosses the commit over to the UI process.
This is a win in many cases because the Web process main thread can go ahead
and do other non-painting tasks while the queue is blocked on painting.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedmacRemoteLayerBackingStoreh">trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h</a></li>
<li><a href="#trunkSourceWebKit2SharedmacRemoteLayerBackingStoremm">trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPagemacRemoteLayerTreeDrawingAreah">trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPagemacRemoteLayerTreeDrawingAreamm">trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (168492 => 168493)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-05-08 20:41:38 UTC (rev 168492)
+++ trunk/Source/WebKit2/ChangeLog        2014-05-08 20:56:37 UTC (rev 168493)
</span><span class="lines">@@ -1,5 +1,38 @@
</span><span class="cx"> 2014-05-08 Tim Horton <timothy_horton@apple.com>
</span><span class="cx">
</span><ins>+ [iOS WebKit2] Flush RemoteLayerBackingStore contexts on a secondary queue
+ https://bugs.webkit.org/show_bug.cgi?id=132667
+ <rdar://problem/15349483>
+
+ Reviewed by Darin Adler.
+
+ * Shared/mac/RemoteLayerBackingStore.h:
+ * Shared/mac/RemoteLayerBackingStore.mm:
+ (WebKit::RemoteLayerBackingStore::takeFrontContextPendingFlush):
+ (WebKit::RemoteLayerBackingStore::flush): Deleted.
+ Add takeFrontContextPendingFlush, which returns the painted-but-not-yet-flushed front context,
+ and drops our reference to it. This needs to be called on all backing store between paints.
+
+ * WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h:
+ (WebKit::RemoteLayerTreeDrawingArea::BackingStoreFlusher::hasFlushed):
+ * WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm:
+ (WebKit::RemoteLayerTreeDrawingArea::RemoteLayerTreeDrawingArea):
+ (WebKit::RemoteLayerTreeDrawingArea::~RemoteLayerTreeDrawingArea):
+ (WebKit::RemoteLayerTreeDrawingArea::flushLayers):
+ (WebKit::RemoteLayerTreeDrawingArea::BackingStoreFlusher::create):
+ (WebKit::RemoteLayerTreeDrawingArea::BackingStoreFlusher::BackingStoreFlusher):
+ (WebKit::RemoteLayerTreeDrawingArea::BackingStoreFlusher::flush):
+ (WebKit::flushBackingStoreChangesInTransaction): Deleted.
+ Flush backing store and send the layer tree commit to the UI process from a dispatch queue.
+ We will only ever have a single commit in flight at a time, and there's a new
+ RELEASE_ASSERT to ensure that is the case.
+ We package up the commit on the main thread; the queue calls CGContextFlush
+ on all of the newly painted contexts and then tosses the commit over to the UI process.
+ This is a win in many cases because the Web process main thread can go ahead
+ and do other non-painting tasks while the queue is blocked on painting.
+
+2014-05-08 Tim Horton <timothy_horton@apple.com>
+
</ins><span class="cx"> [wk2] Don't use the XPC-based plugin process for Adobe Reader
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=132701
</span><span class="cx"> <rdar://problem/16792692>
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedmacRemoteLayerBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h (168492 => 168493)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h        2014-05-08 20:41:38 UTC (rev 168492)
+++ trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h        2014-05-08 20:56:37 UTC (rev 168493)
</span><span class="lines">@@ -81,7 +81,7 @@
</span><span class="cx"> return !!m_frontBuffer;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- void flush();
</del><ins>+ RetainPtr<CGContextRef> takeFrontContextPendingFlush();
</ins><span class="cx">
</span><span class="cx"> enum class Volatility {
</span><span class="cx"> NonVolatile,
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedmacRemoteLayerBackingStoremm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm (168492 => 168493)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm        2014-05-08 20:41:38 UTC (rev 168492)
+++ trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm        2014-05-08 20:56:37 UTC (rev 168493)
</span><span class="lines">@@ -354,12 +354,9 @@
</span><span class="cx"> layer.contents = (id)m_frontBuffer->makeCGImageCopy().get();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void RemoteLayerBackingStore::flush()
</del><ins>+RetainPtr<CGContextRef> RemoteLayerBackingStore::takeFrontContextPendingFlush()
</ins><span class="cx"> {
</span><del>- if (m_frontContextPendingFlush) {
- CGContextFlush(m_frontContextPendingFlush.get());
- m_frontContextPendingFlush = nullptr;
- }
</del><ins>+ return std::move(m_frontContextPendingFlush);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> #if USE(IOSURFACE)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagemacRemoteLayerTreeDrawingAreah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h (168492 => 168493)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h        2014-05-08 20:41:38 UTC (rev 168492)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h        2014-05-08 20:56:37 UTC (rev 168493)
</span><span class="lines">@@ -30,12 +30,18 @@
</span><span class="cx"> #include "GraphicsLayerCARemote.h"
</span><span class="cx"> #include <WebCore/GraphicsLayerClient.h>
</span><span class="cx"> #include <WebCore/Timer.h>
</span><ins>+#include <atomic>
+#include <dispatch/dispatch.h>
</ins><span class="cx"> #include <wtf/HashMap.h>
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> class PlatformCALayer;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+namespace IPC {
+class MessageEncoder;
+}
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><span class="cx"> class RemoteLayerTreeContext;
</span><span class="lines">@@ -96,6 +102,23 @@
</span><span class="cx">
</span><span class="cx"> WebCore::TiledBacking* mainFrameTiledBacking() const;
</span><span class="cx">
</span><ins>+ class BackingStoreFlusher : public ThreadSafeRefCounted<BackingStoreFlusher> {
+ public:
+ static PassRefPtr<BackingStoreFlusher> create(IPC::Connection*, std::unique_ptr<IPC::MessageEncoder>, Vector<RetainPtr<CGContextRef>>);
+
+ void flush();
+ bool hasFlushed() const { return m_hasFlushed; }
+
+ private:
+ BackingStoreFlusher(IPC::Connection*, std::unique_ptr<IPC::MessageEncoder>, Vector<RetainPtr<CGContextRef>>);
+
+ RefPtr<IPC::Connection> m_connection;
+ std::unique_ptr<IPC::MessageEncoder> m_commitEncoder;
+ Vector<RetainPtr<CGContextRef>> m_contextsToFlush;
+
+ std::atomic<bool> m_hasFlushed;
+ };
+
</ins><span class="cx"> std::unique_ptr<RemoteLayerTreeContext> m_remoteLayerTreeContext;
</span><span class="cx"> std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
</span><span class="cx">
</span><span class="lines">@@ -110,6 +133,9 @@
</span><span class="cx">
</span><span class="cx"> bool m_waitingForBackingStoreSwap;
</span><span class="cx"> bool m_hadFlushDeferredWhileWaitingForBackingStoreSwap;
</span><ins>+
+ dispatch_queue_t m_commitQueue;
+ RefPtr<BackingStoreFlusher> m_pendingBackingStoreFlusher;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> DRAWING_AREA_TYPE_CASTS(RemoteLayerTreeDrawingArea, type() == DrawingAreaTypeRemoteLayerTree);
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagemacRemoteLayerTreeDrawingAreamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm (168492 => 168493)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm        2014-05-08 20:41:38 UTC (rev 168492)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm        2014-05-08 20:56:37 UTC (rev 168493)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #import "RemoteScrollingCoordinator.h"
</span><span class="cx"> #import "RemoteScrollingCoordinatorTransaction.h"
</span><span class="cx"> #import "WebPage.h"
</span><ins>+#import "WebProcess.h"
</ins><span class="cx"> #import <WebCore/Frame.h>
</span><span class="cx"> #import <WebCore/FrameView.h>
</span><span class="cx"> #import <WebCore/MainFrame.h>
</span><span class="lines">@@ -64,10 +65,13 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> webPage->corePage()->settings().setDelegatesPageScaling(true);
</span><span class="cx"> #endif
</span><ins>+
+ m_commitQueue = dispatch_queue_create("com.apple.WebKit.WebContent.RemoteLayerTreeDrawingArea.CommitQueue", nullptr);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> RemoteLayerTreeDrawingArea::~RemoteLayerTreeDrawingArea()
</span><span class="cx"> {
</span><ins>+ dispatch_release(m_commitQueue);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void RemoteLayerTreeDrawingArea::setNeedsDisplay()
</span><span class="lines">@@ -223,17 +227,6 @@
</span><span class="cx"> flushLayers();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void flushBackingStoreChangesInTransaction(RemoteLayerTreeTransaction& transaction)
-{
- for (RefPtr<PlatformCALayerRemote> layer : transaction.changedLayers()) {
- if (!layer->properties().changedProperties & RemoteLayerTreeTransaction::BackingStoreChanged)
- return;
-
- if (RemoteLayerBackingStore* backingStore = layer->properties().backingStore.get())
- backingStore->flush();
- }
-}
-
</del><span class="cx"> void RemoteLayerTreeDrawingArea::flushLayers()
</span><span class="cx"> {
</span><span class="cx"> if (!m_rootLayer)
</span><span class="lines">@@ -249,6 +242,8 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ RELEASE_ASSERT(!m_pendingBackingStoreFlusher || m_pendingBackingStoreFlusher->hasFlushed());
+
</ins><span class="cx"> m_webPage->layoutIfNeeded();
</span><span class="cx">
</span><span class="cx"> FloatRect visibleRect(FloatPoint(), m_viewSize);
</span><span class="lines">@@ -268,21 +263,33 @@
</span><span class="cx"> toRemoteScrollingCoordinator(m_webPage->scrollingCoordinator())->buildTransaction(scrollingTransaction);
</span><span class="cx"> #endif
</span><span class="cx">
</span><del>- // FIXME: Move flushing backing store and sending CommitLayerTree onto a background thread.
- flushBackingStoreChangesInTransaction(layerTransaction);
-
</del><span class="cx"> m_waitingForBackingStoreSwap = true;
</span><del>- m_webPage->send(Messages::RemoteLayerTreeDrawingAreaProxy::CommitLayerTree(layerTransaction, scrollingTransaction));
</del><span class="cx">
</span><ins>+ Messages::RemoteLayerTreeDrawingAreaProxy::CommitLayerTree message(layerTransaction, scrollingTransaction);
+ auto commitEncoder = std::make_unique<IPC::MessageEncoder>(Messages::RemoteLayerTreeDrawingAreaProxy::CommitLayerTree::receiverName(), Messages::RemoteLayerTreeDrawingAreaProxy::CommitLayerTree::name(), m_webPage->pageID());
+ commitEncoder->encode(message.arguments());
+
</ins><span class="cx"> bool hadAnyChangedBackingStore = false;
</span><ins>+ Vector<RetainPtr<CGContextRef>> contextsToFlush;
</ins><span class="cx"> for (auto& layer : layerTransaction.changedLayers()) {
</span><del>- if (layer->properties().changedProperties & RemoteLayerTreeTransaction::LayerChanges::BackingStoreChanged)
</del><ins>+ if (layer->properties().changedProperties & RemoteLayerTreeTransaction::LayerChanges::BackingStoreChanged) {
</ins><span class="cx"> hadAnyChangedBackingStore = true;
</span><ins>+ if (auto contextPendingFlush = layer->properties().backingStore->takeFrontContextPendingFlush())
+ contextsToFlush.append(contextPendingFlush);
+ }
+
</ins><span class="cx"> layer->didCommit();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (hadAnyChangedBackingStore)
</span><span class="cx"> m_remoteLayerTreeContext->backingStoreCollection().schedulePurgeabilityTimer();
</span><ins>+
+ RefPtr<BackingStoreFlusher> backingStoreFlusher = BackingStoreFlusher::create(WebProcess::shared().parentProcessConnection(), std::move(commitEncoder), std::move(contextsToFlush));
+ m_pendingBackingStoreFlusher = backingStoreFlusher;
+
+ dispatch_async(m_commitQueue, [backingStoreFlusher]{
+ backingStoreFlusher->flush();
+ });
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void RemoteLayerTreeDrawingArea::didUpdate()
</span><span class="lines">@@ -308,4 +315,28 @@
</span><span class="cx"> m_webPage->pageOverlayController().didChangeDocumentSize();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+PassRefPtr<RemoteLayerTreeDrawingArea::BackingStoreFlusher> RemoteLayerTreeDrawingArea::BackingStoreFlusher::create(IPC::Connection* connection, std::unique_ptr<IPC::MessageEncoder> encoder, Vector<RetainPtr<CGContextRef>> contextsToFlush)
+{
+ return adoptRef(new RemoteLayerTreeDrawingArea::BackingStoreFlusher(connection, std::move(encoder), contextsToFlush));
+}
+
+RemoteLayerTreeDrawingArea::BackingStoreFlusher::BackingStoreFlusher(IPC::Connection* connection, std::unique_ptr<IPC::MessageEncoder> encoder, Vector<RetainPtr<CGContextRef>> contextsToFlush)
+ : m_connection(connection)
+ , m_commitEncoder(std::move(encoder))
+ , m_contextsToFlush(std::move(contextsToFlush))
+ , m_hasFlushed(false)
+{
+}
+
+void RemoteLayerTreeDrawingArea::BackingStoreFlusher::flush()
+{
+ ASSERT(!m_hasFlushed);
+
+ for (auto& context : m_contextsToFlush)
+ CGContextFlush(context.get());
+
+ m_connection->sendMessage(std::move(m_commitEncoder));
+ m_hasFlushed = true;
+}
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre>
</div>
</div>
</body>
</html>