<!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>[180088] trunk/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/180088">180088</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2015-02-13 16:06:14 -0800 (Fri, 13 Feb 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make WebCore::IOSurface have single ownership instead of refcounting
https://bugs.webkit.org/show_bug.cgi?id=141578

Reviewed by Anders Carlsson.

In the interests of making it harder to misuse and to make it more like
ImageBuffer, our IOSurface wrapper should have single ownership.

This will also allow future changes which depend on temporarily
consuming an IOSurface to more easily enforce correct usage.

* WebCore.exp.in:
* platform/graphics/cg/IOSurfacePool.cpp:
(WebCore::IOSurfacePool::takeSurface):
(WebCore::IOSurfacePool::addSurface):
(WebCore::IOSurfacePool::insertSurfaceIntoPool):
(WebCore::IOSurfacePool::tryEvictInUseSurface):
(WebCore::IOSurfacePool::tryEvictOldestCachedSurface):
(WebCore::IOSurfacePool::collectInUseSurfaces):
* platform/graphics/cg/IOSurfacePool.h:
* platform/graphics/cocoa/IOSurface.h:
* platform/graphics/cocoa/IOSurface.mm:
(IOSurface::create):
(IOSurface::createFromSendRight):
(IOSurface::createFromSurface):
(IOSurface::createFromImage):
Make IOSurface::create()s return a unique_ptr, and adjust everywhere.

* Shared/mac/RemoteLayerBackingStore.h:
* Shared/mac/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::Buffer::discard):
* UIProcess/API/mac/WKView.mm:
(-[WKView _takeViewSnapshot]):
* UIProcess/mac/ViewGestureController.h:
* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::removeSwipeSnapshot):
* UIProcess/mac/ViewSnapshotStore.h:
* UIProcess/mac/ViewSnapshotStore.mm:
(WebKit::ViewSnapshot::create):
(WebKit::ViewSnapshot::ViewSnapshot):
(WebKit::ViewSnapshot::hasImage):
Adjust to the single-ownership model.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgIOSurfacePoolcpp">trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgIOSurfacePoolh">trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscocoaIOSurfaceh">trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscocoaIOSurfacemm">trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm</a></li>
<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="#trunkSourceWebKit2UIProcessAPImacWKViewmm">trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacViewGestureControllerh">trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacViewGestureControllerMacmm">trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacViewSnapshotStoreh">trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacViewSnapshotStoremm">trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebCore/ChangeLog        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2015-02-13  Timothy Horton  &lt;timothy_horton@apple.com&gt;
+
+        Make WebCore::IOSurface have single ownership instead of refcounting
+        https://bugs.webkit.org/show_bug.cgi?id=141578
+
+        Reviewed by Anders Carlsson.
+
+        In the interests of making it harder to misuse and to make it more like
+        ImageBuffer, our IOSurface wrapper should have single ownership.
+
+        This will also allow future changes which depend on temporarily
+        consuming an IOSurface to more easily enforce correct usage.
+
+        * WebCore.exp.in:
+        * platform/graphics/cg/IOSurfacePool.cpp:
+        (WebCore::IOSurfacePool::takeSurface):
+        (WebCore::IOSurfacePool::addSurface):
+        (WebCore::IOSurfacePool::insertSurfaceIntoPool):
+        (WebCore::IOSurfacePool::tryEvictInUseSurface):
+        (WebCore::IOSurfacePool::tryEvictOldestCachedSurface):
+        (WebCore::IOSurfacePool::collectInUseSurfaces):
+        * platform/graphics/cg/IOSurfacePool.h:
+        * platform/graphics/cocoa/IOSurface.h:
+        * platform/graphics/cocoa/IOSurface.mm:
+        (IOSurface::create):
+        (IOSurface::createFromSendRight):
+        (IOSurface::createFromSurface):
+        (IOSurface::createFromImage):
+        Make IOSurface::create()s return a unique_ptr, and adjust everywhere.
+
</ins><span class="cx"> 2015-02-12  Enrica Casucci  &lt;enrica@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Additional emoji group support.
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebCore/WebCore.exp.in        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -3231,7 +3231,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if USE(IOSURFACE)
</span><del>-__ZN7WebCore13IOSurfacePool10addSurfaceEPNS_9IOSurfaceE
</del><ins>+__ZN7WebCore13IOSurfacePool10addSurfaceENSt3__110unique_ptrINS_9IOSurfaceENS1_14default_deleteIS3_EEEE
</ins><span class="cx"> __ZN7WebCore13IOSurfacePool10sharedPoolEv
</span><span class="cx"> __ZN7WebCore13IOSurfacePool11setPoolSizeEm
</span><span class="cx"> __ZN7WebCore9IOSurface11createImageEv
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgIOSurfacePoolcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.cpp (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.cpp        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.cpp        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -75,14 +75,14 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void IOSurfacePool::willAddSurface(IOSurface* surface, bool inUse)
</del><ins>+void IOSurfacePool::willAddSurface(IOSurface&amp; surface, bool inUse)
</ins><span class="cx"> {
</span><del>-    CachedSurfaceDetails&amp; details = m_surfaceDetails.add(surface, CachedSurfaceDetails()).iterator-&gt;value;
</del><ins>+    CachedSurfaceDetails&amp; details = m_surfaceDetails.add(&amp;surface, CachedSurfaceDetails()).iterator-&gt;value;
</ins><span class="cx">     details.resetLastUseTime();
</span><span class="cx"> 
</span><del>-    surface-&gt;releaseGraphicsContext();
</del><ins>+    surface.releaseGraphicsContext();
</ins><span class="cx"> 
</span><del>-    size_t surfaceBytes = surface-&gt;totalBytes();
</del><ins>+    size_t surfaceBytes = surface.totalBytes();
</ins><span class="cx"> 
</span><span class="cx">     evict(surfaceBytes);
</span><span class="cx"> 
</span><span class="lines">@@ -91,14 +91,14 @@
</span><span class="cx">         m_inUseBytesCached += surfaceBytes;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void IOSurfacePool::didRemoveSurface(IOSurface* surface, bool inUse)
</del><ins>+void IOSurfacePool::didRemoveSurface(IOSurface&amp; surface, bool inUse)
</ins><span class="cx"> {
</span><del>-    size_t surfaceBytes = surface-&gt;totalBytes();
</del><ins>+    size_t surfaceBytes = surface.totalBytes();
</ins><span class="cx">     m_bytesCached -= surfaceBytes;
</span><span class="cx">     if (inUse)
</span><span class="cx">         m_inUseBytesCached -= surfaceBytes;
</span><span class="cx"> 
</span><del>-    m_surfaceDetails.remove(surface);
</del><ins>+    m_surfaceDetails.remove(&amp;surface);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void IOSurfacePool::didUseSurfaceOfSize(IntSize size)
</span><span class="lines">@@ -107,7 +107,7 @@
</span><span class="cx">     m_sizesInPruneOrder.append(size);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;IOSurface&gt; IOSurfacePool::takeSurface(IntSize size, ColorSpace colorSpace)
</del><ins>+std::unique_ptr&lt;IOSurface&gt; IOSurfacePool::takeSurface(IntSize size, ColorSpace colorSpace)
</ins><span class="cx"> {
</span><span class="cx">     CachedSurfaceMap::iterator mapIter = m_cachedSurfaces.find(size);
</span><span class="cx"> 
</span><span class="lines">@@ -119,8 +119,8 @@
</span><span class="cx">     for (auto surfaceIter = mapIter-&gt;value.begin(); surfaceIter != mapIter-&gt;value.end(); ++surfaceIter) {
</span><span class="cx">         if (!surfaceMatchesParameters(*surfaceIter-&gt;get(), size, colorSpace))
</span><span class="cx">             continue;
</span><del>-        
-        RefPtr&lt;IOSurface&gt; surface = surfaceIter-&gt;get();
</del><ins>+
+        auto surface = WTF::move(*surfaceIter);
</ins><span class="cx">         mapIter-&gt;value.remove(surfaceIter);
</span><span class="cx"> 
</span><span class="cx">         didUseSurfaceOfSize(size);
</span><span class="lines">@@ -130,12 +130,12 @@
</span><span class="cx">             m_sizesInPruneOrder.removeLast();
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        didRemoveSurface(surface.get(), false);
</del><ins>+        didRemoveSurface(*surface, false);
</ins><span class="cx"> 
</span><span class="cx">         surface-&gt;setIsVolatile(false);
</span><span class="cx"> 
</span><span class="cx">         DUMP_POOL_STATISTICS();
</span><del>-        return surface.release();
</del><ins>+        return surface;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Some of the in-use surfaces may no longer actually be in-use, but we haven't moved them over yet.
</span><span class="lines">@@ -145,21 +145,21 @@
</span><span class="cx">         if (surfaceIter-&gt;get()-&gt;isInUse())
</span><span class="cx">             continue;
</span><span class="cx">         
</span><del>-        RefPtr&lt;IOSurface&gt; surface = surfaceIter-&gt;get();
</del><ins>+        auto surface = WTF::move(*surfaceIter);
</ins><span class="cx">         m_inUseSurfaces.remove(surfaceIter);
</span><del>-        didRemoveSurface(surface.get(), true);
</del><ins>+        didRemoveSurface(*surface, true);
</ins><span class="cx"> 
</span><span class="cx">         surface-&gt;setIsVolatile(false);
</span><span class="cx"> 
</span><span class="cx">         DUMP_POOL_STATISTICS();
</span><del>-        return surface.release();
</del><ins>+        return surface;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     DUMP_POOL_STATISTICS();
</span><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void IOSurfacePool::addSurface(IOSurface* surface)
</del><ins>+void IOSurfacePool::addSurface(std::unique_ptr&lt;IOSurface&gt; surface)
</ins><span class="cx"> {
</span><span class="cx">     if (surface-&gt;totalBytes() &gt; m_maximumBytesCached)
</span><span class="cx">         return;
</span><span class="lines">@@ -171,26 +171,27 @@
</span><span class="cx"> 
</span><span class="cx">     bool surfaceIsInUse = surface-&gt;isInUse();
</span><span class="cx"> 
</span><del>-    willAddSurface(surface, surfaceIsInUse);
</del><ins>+    willAddSurface(*surface, surfaceIsInUse);
</ins><span class="cx"> 
</span><span class="cx">     if (surfaceIsInUse) {
</span><del>-        m_inUseSurfaces.prepend(surface);
</del><ins>+        m_inUseSurfaces.prepend(WTF::move(surface));
</ins><span class="cx">         scheduleCollectionTimer();
</span><span class="cx">         DUMP_POOL_STATISTICS();
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    insertSurfaceIntoPool(surface);
</del><ins>+    insertSurfaceIntoPool(WTF::move(surface));
</ins><span class="cx">     DUMP_POOL_STATISTICS();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void IOSurfacePool::insertSurfaceIntoPool(IOSurface* surface)
</del><ins>+void IOSurfacePool::insertSurfaceIntoPool(std::unique_ptr&lt;IOSurface&gt; surface)
</ins><span class="cx"> {
</span><del>-    auto insertedTuple = m_cachedSurfaces.add(surface-&gt;size(), CachedSurfaceQueue());
-    insertedTuple.iterator-&gt;value.prepend(surface);
</del><ins>+    IntSize surfaceSize = surface-&gt;size();
+    auto insertedTuple = m_cachedSurfaces.add(surfaceSize, CachedSurfaceQueue());
+    insertedTuple.iterator-&gt;value.prepend(WTF::move(surface));
</ins><span class="cx">     if (!insertedTuple.isNewEntry)
</span><del>-        m_sizesInPruneOrder.remove(m_sizesInPruneOrder.reverseFind(surface-&gt;size()));
-    m_sizesInPruneOrder.append(surface-&gt;size());
</del><ins>+        m_sizesInPruneOrder.remove(m_sizesInPruneOrder.reverseFind(surfaceSize));
+    m_sizesInPruneOrder.append(surfaceSize);
</ins><span class="cx"> 
</span><span class="cx">     scheduleCollectionTimer();
</span><span class="cx"> }
</span><span class="lines">@@ -206,8 +207,8 @@
</span><span class="cx">     if (m_inUseSurfaces.isEmpty())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    RefPtr&lt;IOSurface&gt; surface = m_inUseSurfaces.takeLast();
-    didRemoveSurface(surface.get(), true);
</del><ins>+    auto surface = m_inUseSurfaces.takeLast();
+    didRemoveSurface(*surface, true);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void IOSurfacePool::tryEvictOldestCachedSurface()
</span><span class="lines">@@ -220,8 +221,8 @@
</span><span class="cx"> 
</span><span class="cx">     CachedSurfaceMap::iterator surfaceQueueIter = m_cachedSurfaces.find(m_sizesInPruneOrder.first());
</span><span class="cx">     ASSERT(!surfaceQueueIter-&gt;value.isEmpty());
</span><del>-    RefPtr&lt;IOSurface&gt; surface = surfaceQueueIter-&gt;value.takeLast();
-    didRemoveSurface(surface.get(), false);
</del><ins>+    auto surface = surfaceQueueIter-&gt;value.takeLast();
+    didRemoveSurface(*surface, false);
</ins><span class="cx"> 
</span><span class="cx">     if (surfaceQueueIter-&gt;value.isEmpty()) {
</span><span class="cx">         m_cachedSurfaces.remove(surfaceQueueIter);
</span><span class="lines">@@ -260,15 +261,15 @@
</span><span class="cx">     for (CachedSurfaceQueue::iterator surfaceIter = m_inUseSurfaces.begin(); surfaceIter != m_inUseSurfaces.end(); ++surfaceIter) {
</span><span class="cx">         IOSurface* surface = surfaceIter-&gt;get();
</span><span class="cx">         if (surface-&gt;isInUse()) {
</span><del>-            newInUseSurfaces.append(*surfaceIter);
</del><ins>+            newInUseSurfaces.append(WTF::move(*surfaceIter));
</ins><span class="cx">             continue;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         m_inUseBytesCached -= surface-&gt;totalBytes();
</span><del>-        insertSurfaceIntoPool(surface);
</del><ins>+        insertSurfaceIntoPool(WTF::move(*surfaceIter));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    m_inUseSurfaces = newInUseSurfaces;
</del><ins>+    m_inUseSurfaces = WTF::move(newInUseSurfaces);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool IOSurfacePool::markOlderSurfacesPurgeable()
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgIOSurfacePoolh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.h (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.h        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebCore/platform/graphics/cg/IOSurfacePool.h        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -49,8 +49,8 @@
</span><span class="cx"> public:
</span><span class="cx">     WEBCORE_EXPORT static IOSurfacePool&amp; sharedPool();
</span><span class="cx"> 
</span><del>-    PassRefPtr&lt;IOSurface&gt; takeSurface(IntSize size, ColorSpace colorSpace);
-    WEBCORE_EXPORT void addSurface(IOSurface*);
</del><ins>+    std::unique_ptr&lt;IOSurface&gt; takeSurface(IntSize, ColorSpace);
+    WEBCORE_EXPORT void addSurface(std::unique_ptr&lt;IOSurface&gt;);
</ins><span class="cx"> 
</span><span class="cx">     void discardAllSurfaces();
</span><span class="cx"> 
</span><span class="lines">@@ -72,15 +72,15 @@
</span><span class="cx">         bool hasMarkedPurgeable;
</span><span class="cx">     };
</span><span class="cx"> 
</span><del>-    typedef Deque&lt;RefPtr&lt;IOSurface&gt;&gt; CachedSurfaceQueue;
</del><ins>+    typedef Deque&lt;std::unique_ptr&lt;IOSurface&gt;&gt; CachedSurfaceQueue;
</ins><span class="cx">     typedef HashMap&lt;IntSize, CachedSurfaceQueue&gt; CachedSurfaceMap;
</span><span class="cx">     typedef HashMap&lt;IOSurface*, CachedSurfaceDetails&gt; CachedSurfaceDetailsMap;
</span><span class="cx"> 
</span><del>-    void willAddSurface(IOSurface*, bool inUse);
-    void didRemoveSurface(IOSurface*, bool inUse);
</del><ins>+    void willAddSurface(IOSurface&amp;, bool inUse);
+    void didRemoveSurface(IOSurface&amp;, bool inUse);
</ins><span class="cx">     void didUseSurfaceOfSize(IntSize);
</span><span class="cx"> 
</span><del>-    void insertSurfaceIntoPool(IOSurface*);
</del><ins>+    void insertSurfaceIntoPool(std::unique_ptr&lt;IOSurface&gt;);
</ins><span class="cx"> 
</span><span class="cx">     void evict(size_t additionalSize);
</span><span class="cx">     void tryEvictInUseSurface();
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscocoaIOSurfaceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -31,18 +31,17 @@
</span><span class="cx"> #include &quot;GraphicsContext.h&quot;
</span><span class="cx"> #include &quot;IntSize.h&quot;
</span><span class="cx"> #include &lt;wtf/PassRefPtr.h&gt;
</span><del>-#include &lt;wtf/RefCounted.h&gt;
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class MachSendRight;
</span><span class="cx"> 
</span><del>-class IOSurface final : public RefCounted&lt;IOSurface&gt; {
</del><ins>+class IOSurface final {
</ins><span class="cx"> public:
</span><del>-    WEBCORE_EXPORT static PassRefPtr&lt;IOSurface&gt; create(IntSize, ColorSpace);
-    WEBCORE_EXPORT static PassRefPtr&lt;IOSurface&gt; createFromSendRight(const MachSendRight&amp;, ColorSpace);
-    static PassRefPtr&lt;IOSurface&gt; createFromSurface(IOSurfaceRef, ColorSpace);
-    WEBCORE_EXPORT static PassRefPtr&lt;IOSurface&gt; createFromImage(CGImageRef);
</del><ins>+    WEBCORE_EXPORT static std::unique_ptr&lt;IOSurface&gt; create(IntSize, ColorSpace);
+    WEBCORE_EXPORT static std::unique_ptr&lt;IOSurface&gt; createFromSendRight(const MachSendRight&amp;, ColorSpace);
+    static std::unique_ptr&lt;IOSurface&gt; createFromSurface(IOSurfaceRef, ColorSpace);
+    WEBCORE_EXPORT static std::unique_ptr&lt;IOSurface&gt; createFromImage(CGImageRef);
</ins><span class="cx"> 
</span><span class="cx">     static IntSize maximumSize();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscocoaIOSurfacemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -41,25 +41,25 @@
</span><span class="cx"> 
</span><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;IOSurface&gt; IOSurface::create(IntSize size, ColorSpace colorSpace)
</del><ins>+std::unique_ptr&lt;IOSurface&gt; IOSurface::create(IntSize size, ColorSpace colorSpace)
</ins><span class="cx"> {
</span><del>-    if (RefPtr&lt;IOSurface&gt; cachedSurface = IOSurfacePool::sharedPool().takeSurface(size, colorSpace))
-        return cachedSurface.release();
-    return adoptRef(new IOSurface(size, colorSpace));
</del><ins>+    if (std::unique_ptr&lt;IOSurface&gt; cachedSurface = IOSurfacePool::sharedPool().takeSurface(size, colorSpace))
+        return cachedSurface;
+    return std::unique_ptr&lt;IOSurface&gt;(new IOSurface(size, colorSpace));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;IOSurface&gt; IOSurface::createFromSendRight(const MachSendRight&amp; sendRight, ColorSpace colorSpace)
</del><ins>+std::unique_ptr&lt;IOSurface&gt; IOSurface::createFromSendRight(const MachSendRight&amp; sendRight, ColorSpace colorSpace)
</ins><span class="cx"> {
</span><span class="cx">     RetainPtr&lt;IOSurfaceRef&gt; surface = adoptCF(IOSurfaceLookupFromMachPort(sendRight.sendRight()));
</span><span class="cx">     return IOSurface::createFromSurface(surface.get(), colorSpace);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;IOSurface&gt; IOSurface::createFromSurface(IOSurfaceRef surface, ColorSpace colorSpace)
</del><ins>+std::unique_ptr&lt;IOSurface&gt; IOSurface::createFromSurface(IOSurfaceRef surface, ColorSpace colorSpace)
</ins><span class="cx"> {
</span><del>-    return adoptRef(new IOSurface(surface, colorSpace));
</del><ins>+    return std::unique_ptr&lt;IOSurface&gt;(new IOSurface(surface, colorSpace));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;IOSurface&gt; IOSurface::createFromImage(CGImageRef image)
</del><ins>+std::unique_ptr&lt;IOSurface&gt; IOSurface::createFromImage(CGImageRef image)
</ins><span class="cx"> {
</span><span class="cx">     if (!image)
</span><span class="cx">         return nullptr;
</span><span class="lines">@@ -67,12 +67,12 @@
</span><span class="cx">     size_t width = CGImageGetWidth(image);
</span><span class="cx">     size_t height = CGImageGetHeight(image);
</span><span class="cx"> 
</span><del>-    RefPtr&lt;IOSurface&gt; surface = IOSurface::create(IntSize(width, height), ColorSpaceDeviceRGB);
</del><ins>+    std::unique_ptr&lt;IOSurface&gt; surface = IOSurface::create(IntSize(width, height), ColorSpaceDeviceRGB);
</ins><span class="cx">     auto surfaceContext = surface-&gt;ensurePlatformContext();
</span><span class="cx">     CGContextDrawImage(surfaceContext, CGRectMake(0, 0, width, height), image);
</span><span class="cx">     CGContextFlush(surfaceContext);
</span><span class="cx"> 
</span><del>-    return surface.release();
</del><ins>+    return surface;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> IOSurface::IOSurface(IntSize size, ColorSpace colorSpace)
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebKit2/ChangeLog        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2015-02-13  Timothy Horton  &lt;timothy_horton@apple.com&gt;
+
+        Make WebCore::IOSurface have single ownership instead of refcounting
+        https://bugs.webkit.org/show_bug.cgi?id=141578
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/mac/RemoteLayerBackingStore.h:
+        * Shared/mac/RemoteLayerBackingStore.mm:
+        (WebKit::RemoteLayerBackingStore::Buffer::discard):
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _takeViewSnapshot]):
+        * UIProcess/mac/ViewGestureController.h:
+        * UIProcess/mac/ViewGestureControllerMac.mm:
+        (WebKit::ViewGestureController::beginSwipeGesture):
+        (WebKit::ViewGestureController::removeSwipeSnapshot):
+        * UIProcess/mac/ViewSnapshotStore.h:
+        * UIProcess/mac/ViewSnapshotStore.mm:
+        (WebKit::ViewSnapshot::create):
+        (WebKit::ViewSnapshot::ViewSnapshot):
+        (WebKit::ViewSnapshot::hasImage):
+        Adjust to the single-ownership model.
+
</ins><span class="cx"> 2015-02-13  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS] Unreviewed build fix after r180076.
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedmacRemoteLayerBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -110,7 +110,7 @@
</span><span class="cx">     struct Buffer {
</span><span class="cx">         RefPtr&lt;ShareableBitmap&gt; bitmap;
</span><span class="cx"> #if USE(IOSURFACE)
</span><del>-        RefPtr&lt;WebCore::IOSurface&gt; surface;
</del><ins>+        std::unique_ptr&lt;WebCore::IOSurface&gt; surface;
</ins><span class="cx">         bool isVolatile = false;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedmacRemoteLayerBackingStoremm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -444,8 +444,7 @@
</span><span class="cx"> {
</span><span class="cx"> #if USE(IOSURFACE)
</span><span class="cx">     if (surface)
</span><del>-        IOSurfacePool::sharedPool().addSurface(surface.get());
-    surface = nullptr;
</del><ins>+        IOSurfacePool::sharedPool().addSurface(WTF::move(surface));
</ins><span class="cx">     isVolatile = false;
</span><span class="cx"> #endif
</span><span class="cx">     bitmap = nullptr;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPImacWKViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -3231,7 +3231,7 @@
</span><span class="cx">         return nullptr;
</span><span class="cx">     surface-&gt;setIsVolatile(true);
</span><span class="cx"> 
</span><del>-    return ViewSnapshot::create(surface.get(), surface-&gt;size(), surface-&gt;totalBytes());
</del><ins>+    return ViewSnapshot::create(WTF::move(surface));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)_wheelEventWasNotHandledByWebCore:(NSEvent *)event
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacViewGestureControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -160,7 +160,7 @@
</span><span class="cx">     RunLoop::Timer&lt;ViewGestureController&gt; m_swipeWatchdogTimer;
</span><span class="cx"> 
</span><span class="cx"> #if USE(IOSURFACE)
</span><del>-    RefPtr&lt;WebCore::IOSurface&gt; m_currentSwipeSnapshotSurface;
</del><ins>+    RefPtr&lt;ViewSnapshot&gt; m_currentSwipeSnapshot;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacViewGestureControllerMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -554,7 +554,7 @@
</span><span class="cx">         if (coreColor.isValid())
</span><span class="cx">             backgroundColor = cachedCGColor(coreColor, ColorSpaceDeviceRGB);
</span><span class="cx"> #if USE_IOSURFACE_VIEW_SNAPSHOTS
</span><del>-        m_currentSwipeSnapshotSurface = snapshot-&gt;surface();
</del><ins>+        m_currentSwipeSnapshot = snapshot;
</ins><span class="cx"> #endif
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -772,9 +772,9 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx"> #if USE_IOSURFACE_VIEW_SNAPSHOTS
</span><del>-    if (m_currentSwipeSnapshotSurface)
-        m_currentSwipeSnapshotSurface-&gt;setIsVolatile(true);
-    m_currentSwipeSnapshotSurface = nullptr;
</del><ins>+    if (m_currentSwipeSnapshot)
+        m_currentSwipeSnapshot-&gt;surface()-&gt;setIsVolatile(true);
+    m_currentSwipeSnapshot = nullptr;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     for (const auto&amp; layer : m_currentSwipeLiveLayers)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacViewSnapshotStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -62,7 +62,7 @@
</span><span class="cx"> class ViewSnapshot : public RefCounted&lt;ViewSnapshot&gt; {
</span><span class="cx"> public:
</span><span class="cx"> #if USE_IOSURFACE_VIEW_SNAPSHOTS
</span><del>-    static PassRefPtr&lt;ViewSnapshot&gt; create(WebCore::IOSurface*, WebCore::IntSize, size_t imageSizeInBytes);
</del><ins>+    static PassRefPtr&lt;ViewSnapshot&gt; create(std::unique_ptr&lt;WebCore::IOSurface&gt;);
</ins><span class="cx"> #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
</span><span class="cx">     static PassRefPtr&lt;ViewSnapshot&gt; create(uint32_t slotID, WebCore::IntSize, size_t imageSizeInBytes);
</span><span class="cx"> #endif
</span><span class="lines">@@ -90,13 +90,13 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx"> #if USE_IOSURFACE_VIEW_SNAPSHOTS
</span><del>-    explicit ViewSnapshot(WebCore::IOSurface*, WebCore::IntSize, size_t imageSizeInBytes);
</del><ins>+    explicit ViewSnapshot(std::unique_ptr&lt;WebCore::IOSurface&gt;);
</ins><span class="cx"> #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
</span><span class="cx">     explicit ViewSnapshot(uint32_t slotID, WebCore::IntSize, size_t imageSizeInBytes);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if USE_IOSURFACE_VIEW_SNAPSHOTS
</span><del>-    RefPtr&lt;WebCore::IOSurface&gt; m_surface;
</del><ins>+    std::unique_ptr&lt;WebCore::IOSurface&gt; m_surface;
</ins><span class="cx"> #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
</span><span class="cx">     uint32_t m_slotID;
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacViewSnapshotStoremm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm (180087 => 180088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm        2015-02-13 23:44:02 UTC (rev 180087)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm        2015-02-14 00:06:14 UTC (rev 180088)
</span><span class="lines">@@ -134,9 +134,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> #if USE_IOSURFACE_VIEW_SNAPSHOTS
</span><del>-PassRefPtr&lt;ViewSnapshot&gt; ViewSnapshot::create(IOSurface* surface, IntSize size, size_t imageSizeInBytes)
</del><ins>+PassRefPtr&lt;ViewSnapshot&gt; ViewSnapshot::create(std::unique_ptr&lt;IOSurface&gt; surface)
</ins><span class="cx"> {
</span><del>-    return adoptRef(new ViewSnapshot(surface, size, imageSizeInBytes));
</del><ins>+    return adoptRef(new ViewSnapshot(WTF::move(surface)));
</ins><span class="cx"> }
</span><span class="cx"> #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
</span><span class="cx"> PassRefPtr&lt;ViewSnapshot&gt; ViewSnapshot::create(uint32_t slotID, IntSize size, size_t imageSizeInBytes)
</span><span class="lines">@@ -146,14 +146,16 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if USE_IOSURFACE_VIEW_SNAPSHOTS
</span><del>-ViewSnapshot::ViewSnapshot(IOSurface* surface, IntSize size, size_t imageSizeInBytes)
-    : m_surface(surface)
</del><ins>+ViewSnapshot::ViewSnapshot(std::unique_ptr&lt;IOSurface&gt; surface)
+    : m_surface(WTF::move(surface))
+    , m_imageSizeInBytes(m_surface-&gt;totalBytes())
+    , m_size(m_surface-&gt;size())
</ins><span class="cx"> #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
</span><span class="cx"> ViewSnapshot::ViewSnapshot(uint32_t slotID, IntSize size, size_t imageSizeInBytes)
</span><span class="cx">     : m_slotID(slotID)
</span><del>-#endif
</del><span class="cx">     , m_imageSizeInBytes(imageSizeInBytes)
</span><span class="cx">     , m_size(size)
</span><ins>+#endif
</ins><span class="cx"> {
</span><span class="cx">     if (hasImage())
</span><span class="cx">         ViewSnapshotStore::singleton().didAddImageToSnapshot(*this);
</span><span class="lines">@@ -167,7 +169,7 @@
</span><span class="cx"> bool ViewSnapshot::hasImage() const
</span><span class="cx"> {
</span><span class="cx"> #if USE_IOSURFACE_VIEW_SNAPSHOTS
</span><del>-    return m_surface;
</del><ins>+    return !!m_surface;
</ins><span class="cx"> #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
</span><span class="cx">     return m_slotID;
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>