Make WebCore::IOSurface have single ownership instead of refcounting
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Feb 2015 00:06:14 +0000 (00:06 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Feb 2015 00:06:14 +0000 (00:06 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180088 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/platform/graphics/cg/IOSurfacePool.cpp
Source/WebCore/platform/graphics/cg/IOSurfacePool.h
Source/WebCore/platform/graphics/cocoa/IOSurface.h
Source/WebCore/platform/graphics/cocoa/IOSurface.mm
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h
Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/mac/ViewGestureController.h
Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm
Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h
Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm

index 816de7d953f15f578bc0d0f880a80040c3dd302e..fe46bafa36b6066b9971d69b039a0e4d447440c3 100644 (file)
@@ -1,3 +1,33 @@
+2015-02-13  Timothy Horton  <timothy_horton@apple.com>
+
+        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.
+
 2015-02-12  Enrica Casucci  <enrica@apple.com>
 
         Additional emoji group support.
index 7844b47b92d430f9f153ff93e66498158bc82ba3..d71fc1e61ab1edbd506929ed0e282df3a6e671a3 100644 (file)
@@ -3231,7 +3231,7 @@ __ZN7WebCore5ColorC1ERKN3WTF6StringE
 #endif
 
 #if USE(IOSURFACE)
-__ZN7WebCore13IOSurfacePool10addSurfaceEPNS_9IOSurfaceE
+__ZN7WebCore13IOSurfacePool10addSurfaceENSt3__110unique_ptrINS_9IOSurfaceENS1_14default_deleteIS3_EEEE
 __ZN7WebCore13IOSurfacePool10sharedPoolEv
 __ZN7WebCore13IOSurfacePool11setPoolSizeEm
 __ZN7WebCore9IOSurface11createImageEv
index 2ea8dcfc21546685f455affd61aa557a0ef6ef48..ff20ed30baed051162f12eaf9eaa62897fdeff25 100644 (file)
@@ -75,14 +75,14 @@ static bool surfaceMatchesParameters(IOSurface& surface, const IntSize& requeste
     return true;
 }
 
-void IOSurfacePool::willAddSurface(IOSurface* surface, bool inUse)
+void IOSurfacePool::willAddSurface(IOSurface& surface, bool inUse)
 {
-    CachedSurfaceDetails& details = m_surfaceDetails.add(surface, CachedSurfaceDetails()).iterator->value;
+    CachedSurfaceDetails& details = m_surfaceDetails.add(&surface, CachedSurfaceDetails()).iterator->value;
     details.resetLastUseTime();
 
-    surface->releaseGraphicsContext();
+    surface.releaseGraphicsContext();
 
-    size_t surfaceBytes = surface->totalBytes();
+    size_t surfaceBytes = surface.totalBytes();
 
     evict(surfaceBytes);
 
@@ -91,14 +91,14 @@ void IOSurfacePool::willAddSurface(IOSurface* surface, bool inUse)
         m_inUseBytesCached += surfaceBytes;
 }
 
-void IOSurfacePool::didRemoveSurface(IOSurface* surface, bool inUse)
+void IOSurfacePool::didRemoveSurface(IOSurface& surface, bool inUse)
 {
-    size_t surfaceBytes = surface->totalBytes();
+    size_t surfaceBytes = surface.totalBytes();
     m_bytesCached -= surfaceBytes;
     if (inUse)
         m_inUseBytesCached -= surfaceBytes;
 
-    m_surfaceDetails.remove(surface);
+    m_surfaceDetails.remove(&surface);
 }
 
 void IOSurfacePool::didUseSurfaceOfSize(IntSize size)
@@ -107,7 +107,7 @@ void IOSurfacePool::didUseSurfaceOfSize(IntSize size)
     m_sizesInPruneOrder.append(size);
 }
 
-PassRefPtr<IOSurface> IOSurfacePool::takeSurface(IntSize size, ColorSpace colorSpace)
+std::unique_ptr<IOSurface> IOSurfacePool::takeSurface(IntSize size, ColorSpace colorSpace)
 {
     CachedSurfaceMap::iterator mapIter = m_cachedSurfaces.find(size);
 
@@ -119,8 +119,8 @@ PassRefPtr<IOSurface> IOSurfacePool::takeSurface(IntSize size, ColorSpace colorS
     for (auto surfaceIter = mapIter->value.begin(); surfaceIter != mapIter->value.end(); ++surfaceIter) {
         if (!surfaceMatchesParameters(*surfaceIter->get(), size, colorSpace))
             continue;
-        
-        RefPtr<IOSurface> surface = surfaceIter->get();
+
+        auto surface = WTF::move(*surfaceIter);
         mapIter->value.remove(surfaceIter);
 
         didUseSurfaceOfSize(size);
@@ -130,12 +130,12 @@ PassRefPtr<IOSurface> IOSurfacePool::takeSurface(IntSize size, ColorSpace colorS
             m_sizesInPruneOrder.removeLast();
         }
 
-        didRemoveSurface(surface.get(), false);
+        didRemoveSurface(*surface, false);
 
         surface->setIsVolatile(false);
 
         DUMP_POOL_STATISTICS();
-        return surface.release();
+        return surface;
     }
 
     // Some of the in-use surfaces may no longer actually be in-use, but we haven't moved them over yet.
@@ -145,21 +145,21 @@ PassRefPtr<IOSurface> IOSurfacePool::takeSurface(IntSize size, ColorSpace colorS
         if (surfaceIter->get()->isInUse())
             continue;
         
-        RefPtr<IOSurface> surface = surfaceIter->get();
+        auto surface = WTF::move(*surfaceIter);
         m_inUseSurfaces.remove(surfaceIter);
-        didRemoveSurface(surface.get(), true);
+        didRemoveSurface(*surface, true);
 
         surface->setIsVolatile(false);
 
         DUMP_POOL_STATISTICS();
-        return surface.release();
+        return surface;
     }
 
     DUMP_POOL_STATISTICS();
     return nullptr;
 }
 
-void IOSurfacePool::addSurface(IOSurface* surface)
+void IOSurfacePool::addSurface(std::unique_ptr<IOSurface> surface)
 {
     if (surface->totalBytes() > m_maximumBytesCached)
         return;
@@ -171,26 +171,27 @@ void IOSurfacePool::addSurface(IOSurface* surface)
 
     bool surfaceIsInUse = surface->isInUse();
 
-    willAddSurface(surface, surfaceIsInUse);
+    willAddSurface(*surface, surfaceIsInUse);
 
     if (surfaceIsInUse) {
-        m_inUseSurfaces.prepend(surface);
+        m_inUseSurfaces.prepend(WTF::move(surface));
         scheduleCollectionTimer();
         DUMP_POOL_STATISTICS();
         return;
     }
 
-    insertSurfaceIntoPool(surface);
+    insertSurfaceIntoPool(WTF::move(surface));
     DUMP_POOL_STATISTICS();
 }
 
-void IOSurfacePool::insertSurfaceIntoPool(IOSurface* surface)
+void IOSurfacePool::insertSurfaceIntoPool(std::unique_ptr<IOSurface> surface)
 {
-    auto insertedTuple = m_cachedSurfaces.add(surface->size(), CachedSurfaceQueue());
-    insertedTuple.iterator->value.prepend(surface);
+    IntSize surfaceSize = surface->size();
+    auto insertedTuple = m_cachedSurfaces.add(surfaceSize, CachedSurfaceQueue());
+    insertedTuple.iterator->value.prepend(WTF::move(surface));
     if (!insertedTuple.isNewEntry)
-        m_sizesInPruneOrder.remove(m_sizesInPruneOrder.reverseFind(surface->size()));
-    m_sizesInPruneOrder.append(surface->size());
+        m_sizesInPruneOrder.remove(m_sizesInPruneOrder.reverseFind(surfaceSize));
+    m_sizesInPruneOrder.append(surfaceSize);
 
     scheduleCollectionTimer();
 }
@@ -206,8 +207,8 @@ void IOSurfacePool::tryEvictInUseSurface()
     if (m_inUseSurfaces.isEmpty())
         return;
 
-    RefPtr<IOSurface> surface = m_inUseSurfaces.takeLast();
-    didRemoveSurface(surface.get(), true);
+    auto surface = m_inUseSurfaces.takeLast();
+    didRemoveSurface(*surface, true);
 }
 
 void IOSurfacePool::tryEvictOldestCachedSurface()
@@ -220,8 +221,8 @@ void IOSurfacePool::tryEvictOldestCachedSurface()
 
     CachedSurfaceMap::iterator surfaceQueueIter = m_cachedSurfaces.find(m_sizesInPruneOrder.first());
     ASSERT(!surfaceQueueIter->value.isEmpty());
-    RefPtr<IOSurface> surface = surfaceQueueIter->value.takeLast();
-    didRemoveSurface(surface.get(), false);
+    auto surface = surfaceQueueIter->value.takeLast();
+    didRemoveSurface(*surface, false);
 
     if (surfaceQueueIter->value.isEmpty()) {
         m_cachedSurfaces.remove(surfaceQueueIter);
@@ -260,15 +261,15 @@ void IOSurfacePool::collectInUseSurfaces()
     for (CachedSurfaceQueue::iterator surfaceIter = m_inUseSurfaces.begin(); surfaceIter != m_inUseSurfaces.end(); ++surfaceIter) {
         IOSurface* surface = surfaceIter->get();
         if (surface->isInUse()) {
-            newInUseSurfaces.append(*surfaceIter);
+            newInUseSurfaces.append(WTF::move(*surfaceIter));
             continue;
         }
 
         m_inUseBytesCached -= surface->totalBytes();
-        insertSurfaceIntoPool(surface);
+        insertSurfaceIntoPool(WTF::move(*surfaceIter));
     }
 
-    m_inUseSurfaces = newInUseSurfaces;
+    m_inUseSurfaces = WTF::move(newInUseSurfaces);
 }
 
 bool IOSurfacePool::markOlderSurfacesPurgeable()
index 98ea9e995ba978a2d47f91a32f156ebeaaaf4125..cf83b821f345b191410cfa871094d351b54689c5 100644 (file)
@@ -49,8 +49,8 @@ class IOSurfacePool {
 public:
     WEBCORE_EXPORT static IOSurfacePool& sharedPool();
 
-    PassRefPtr<IOSurface> takeSurface(IntSize size, ColorSpace colorSpace);
-    WEBCORE_EXPORT void addSurface(IOSurface*);
+    std::unique_ptr<IOSurface> takeSurface(IntSize, ColorSpace);
+    WEBCORE_EXPORT void addSurface(std::unique_ptr<IOSurface>);
 
     void discardAllSurfaces();
 
@@ -72,15 +72,15 @@ private:
         bool hasMarkedPurgeable;
     };
 
-    typedef Deque<RefPtr<IOSurface>> CachedSurfaceQueue;
+    typedef Deque<std::unique_ptr<IOSurface>> CachedSurfaceQueue;
     typedef HashMap<IntSize, CachedSurfaceQueue> CachedSurfaceMap;
     typedef HashMap<IOSurface*, CachedSurfaceDetails> CachedSurfaceDetailsMap;
 
-    void willAddSurface(IOSurface*, bool inUse);
-    void didRemoveSurface(IOSurface*, bool inUse);
+    void willAddSurface(IOSurface&, bool inUse);
+    void didRemoveSurface(IOSurface&, bool inUse);
     void didUseSurfaceOfSize(IntSize);
 
-    void insertSurfaceIntoPool(IOSurface*);
+    void insertSurfaceIntoPool(std::unique_ptr<IOSurface>);
 
     void evict(size_t additionalSize);
     void tryEvictInUseSurface();
index f5fb25d574582f9c804cf4bb72912f7504fec7c4..0d132fe6d634bf32e263259ac983e2f80b156ff0 100644 (file)
 #include "GraphicsContext.h"
 #include "IntSize.h"
 #include <wtf/PassRefPtr.h>
-#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
 class MachSendRight;
 
-class IOSurface final : public RefCounted<IOSurface> {
+class IOSurface final {
 public:
-    WEBCORE_EXPORT static PassRefPtr<IOSurface> create(IntSize, ColorSpace);
-    WEBCORE_EXPORT static PassRefPtr<IOSurface> createFromSendRight(const MachSendRight&, ColorSpace);
-    static PassRefPtr<IOSurface> createFromSurface(IOSurfaceRef, ColorSpace);
-    WEBCORE_EXPORT static PassRefPtr<IOSurface> createFromImage(CGImageRef);
+    WEBCORE_EXPORT static std::unique_ptr<IOSurface> create(IntSize, ColorSpace);
+    WEBCORE_EXPORT static std::unique_ptr<IOSurface> createFromSendRight(const MachSendRight&, ColorSpace);
+    static std::unique_ptr<IOSurface> createFromSurface(IOSurfaceRef, ColorSpace);
+    WEBCORE_EXPORT static std::unique_ptr<IOSurface> createFromImage(CGImageRef);
 
     static IntSize maximumSize();
 
index 11ab20da96b6f87c08e12a1e8633eda801c1db36..5c4ce2eb78e86bfef1a86a6dad8be775cd516910 100644 (file)
@@ -41,25 +41,25 @@ CGImageRef CGIOSurfaceContextCreateImage(CGContextRef);
 
 using namespace WebCore;
 
-PassRefPtr<IOSurface> IOSurface::create(IntSize size, ColorSpace colorSpace)
+std::unique_ptr<IOSurface> IOSurface::create(IntSize size, ColorSpace colorSpace)
 {
-    if (RefPtr<IOSurface> cachedSurface = IOSurfacePool::sharedPool().takeSurface(size, colorSpace))
-        return cachedSurface.release();
-    return adoptRef(new IOSurface(size, colorSpace));
+    if (std::unique_ptr<IOSurface> cachedSurface = IOSurfacePool::sharedPool().takeSurface(size, colorSpace))
+        return cachedSurface;
+    return std::unique_ptr<IOSurface>(new IOSurface(size, colorSpace));
 }
 
-PassRefPtr<IOSurface> IOSurface::createFromSendRight(const MachSendRight& sendRight, ColorSpace colorSpace)
+std::unique_ptr<IOSurface> IOSurface::createFromSendRight(const MachSendRight& sendRight, ColorSpace colorSpace)
 {
     RetainPtr<IOSurfaceRef> surface = adoptCF(IOSurfaceLookupFromMachPort(sendRight.sendRight()));
     return IOSurface::createFromSurface(surface.get(), colorSpace);
 }
 
-PassRefPtr<IOSurface> IOSurface::createFromSurface(IOSurfaceRef surface, ColorSpace colorSpace)
+std::unique_ptr<IOSurface> IOSurface::createFromSurface(IOSurfaceRef surface, ColorSpace colorSpace)
 {
-    return adoptRef(new IOSurface(surface, colorSpace));
+    return std::unique_ptr<IOSurface>(new IOSurface(surface, colorSpace));
 }
 
-PassRefPtr<IOSurface> IOSurface::createFromImage(CGImageRef image)
+std::unique_ptr<IOSurface> IOSurface::createFromImage(CGImageRef image)
 {
     if (!image)
         return nullptr;
@@ -67,12 +67,12 @@ PassRefPtr<IOSurface> IOSurface::createFromImage(CGImageRef image)
     size_t width = CGImageGetWidth(image);
     size_t height = CGImageGetHeight(image);
 
-    RefPtr<IOSurface> surface = IOSurface::create(IntSize(width, height), ColorSpaceDeviceRGB);
+    std::unique_ptr<IOSurface> surface = IOSurface::create(IntSize(width, height), ColorSpaceDeviceRGB);
     auto surfaceContext = surface->ensurePlatformContext();
     CGContextDrawImage(surfaceContext, CGRectMake(0, 0, width, height), image);
     CGContextFlush(surfaceContext);
 
-    return surface.release();
+    return surface;
 }
 
 IOSurface::IOSurface(IntSize size, ColorSpace colorSpace)
index 0f14a7807a7973f2dba3efb99504bb087a7ce8f6..ae4cc13bcb42dd48b30e4a9b2874a52d50997da4 100644 (file)
@@ -1,3 +1,26 @@
+2015-02-13  Timothy Horton  <timothy_horton@apple.com>
+
+        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.
+
 2015-02-13  Brent Fulgham  <bfulgham@apple.com>
 
         [iOS] Unreviewed build fix after r180076.
index d025c16893c9193c5f143fd6d0b5e09f5512b256..bae090b1a915252ec9cda46be2ff8d20f1bc0229 100644 (file)
@@ -110,7 +110,7 @@ private:
     struct Buffer {
         RefPtr<ShareableBitmap> bitmap;
 #if USE(IOSURFACE)
-        RefPtr<WebCore::IOSurface> surface;
+        std::unique_ptr<WebCore::IOSurface> surface;
         bool isVolatile = false;
 #endif
 
index af6ec59d30ca89fb43aa95be6eb174b787b1b09a..8a02ece9181464c6881022236f36768b0ce88389 100644 (file)
@@ -444,8 +444,7 @@ void RemoteLayerBackingStore::Buffer::discard()
 {
 #if USE(IOSURFACE)
     if (surface)
-        IOSurfacePool::sharedPool().addSurface(surface.get());
-    surface = nullptr;
+        IOSurfacePool::sharedPool().addSurface(WTF::move(surface));
     isVolatile = false;
 #endif
     bitmap = nullptr;
index b67d9e2c3eb4f46a6296a8a4f0580493d7b68ce3..24eb5f6173bec4f7e942498aad7b9fe264fd8190 100644 (file)
@@ -3231,7 +3231,7 @@ static void* keyValueObservingContext = &keyValueObservingContext;
         return nullptr;
     surface->setIsVolatile(true);
 
-    return ViewSnapshot::create(surface.get(), surface->size(), surface->totalBytes());
+    return ViewSnapshot::create(WTF::move(surface));
 }
 
 - (void)_wheelEventWasNotHandledByWebCore:(NSEvent *)event
index ec18f0f8f7e2c7333a6e40b0dcebc708482bf524..64619a8286575902a90eb5dee0793088b2cc63d9 100644 (file)
@@ -160,7 +160,7 @@ private:
     RunLoop::Timer<ViewGestureController> m_swipeWatchdogTimer;
 
 #if USE(IOSURFACE)
-    RefPtr<WebCore::IOSurface> m_currentSwipeSnapshotSurface;
+    RefPtr<ViewSnapshot> m_currentSwipeSnapshot;
 #endif
 
 #if PLATFORM(MAC)
index 2c302b2f851023cdc059a7f8601dfb2b87a9e3ef..9ed7f833da9b39b7cd2e4966c4f8ff4fb00cd804 100644 (file)
@@ -554,7 +554,7 @@ void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem
         if (coreColor.isValid())
             backgroundColor = cachedCGColor(coreColor, ColorSpaceDeviceRGB);
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
-        m_currentSwipeSnapshotSurface = snapshot->surface();
+        m_currentSwipeSnapshot = snapshot;
 #endif
     }
 
@@ -772,9 +772,9 @@ void ViewGestureController::removeSwipeSnapshot()
         return;
 
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
-    if (m_currentSwipeSnapshotSurface)
-        m_currentSwipeSnapshotSurface->setIsVolatile(true);
-    m_currentSwipeSnapshotSurface = nullptr;
+    if (m_currentSwipeSnapshot)
+        m_currentSwipeSnapshot->surface()->setIsVolatile(true);
+    m_currentSwipeSnapshot = nullptr;
 #endif
 
     for (const auto& layer : m_currentSwipeLiveLayers)
index 3dc91f293d5ad311af5d15ac904a310c190a1de8..305adb3a74c068b9b98dfd387720c8e063682a1b 100644 (file)
@@ -62,7 +62,7 @@ class WebPageProxy;
 class ViewSnapshot : public RefCounted<ViewSnapshot> {
 public:
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
-    static PassRefPtr<ViewSnapshot> create(WebCore::IOSurface*, WebCore::IntSize, size_t imageSizeInBytes);
+    static PassRefPtr<ViewSnapshot> create(std::unique_ptr<WebCore::IOSurface>);
 #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
     static PassRefPtr<ViewSnapshot> create(uint32_t slotID, WebCore::IntSize, size_t imageSizeInBytes);
 #endif
@@ -90,13 +90,13 @@ public:
 
 private:
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
-    explicit ViewSnapshot(WebCore::IOSurface*, WebCore::IntSize, size_t imageSizeInBytes);
+    explicit ViewSnapshot(std::unique_ptr<WebCore::IOSurface>);
 #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
     explicit ViewSnapshot(uint32_t slotID, WebCore::IntSize, size_t imageSizeInBytes);
 #endif
 
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
-    RefPtr<WebCore::IOSurface> m_surface;
+    std::unique_ptr<WebCore::IOSurface> m_surface;
 #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
     uint32_t m_slotID;
 #endif
index 35d1f3548b1e9c6e716ce589a3bc3993e1d63091..9d87e281d443e76ddc12eda6fdc519fd11524065 100644 (file)
@@ -134,9 +134,9 @@ void ViewSnapshotStore::discardSnapshotImages()
 
 
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
-PassRefPtr<ViewSnapshot> ViewSnapshot::create(IOSurface* surface, IntSize size, size_t imageSizeInBytes)
+PassRefPtr<ViewSnapshot> ViewSnapshot::create(std::unique_ptr<IOSurface> surface)
 {
-    return adoptRef(new ViewSnapshot(surface, size, imageSizeInBytes));
+    return adoptRef(new ViewSnapshot(WTF::move(surface)));
 }
 #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
 PassRefPtr<ViewSnapshot> ViewSnapshot::create(uint32_t slotID, IntSize size, size_t imageSizeInBytes)
@@ -146,14 +146,16 @@ PassRefPtr<ViewSnapshot> ViewSnapshot::create(uint32_t slotID, IntSize size, siz
 #endif
 
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
-ViewSnapshot::ViewSnapshot(IOSurface* surface, IntSize size, size_t imageSizeInBytes)
-    : m_surface(surface)
+ViewSnapshot::ViewSnapshot(std::unique_ptr<IOSurface> surface)
+    : m_surface(WTF::move(surface))
+    , m_imageSizeInBytes(m_surface->totalBytes())
+    , m_size(m_surface->size())
 #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
 ViewSnapshot::ViewSnapshot(uint32_t slotID, IntSize size, size_t imageSizeInBytes)
     : m_slotID(slotID)
-#endif
     , m_imageSizeInBytes(imageSizeInBytes)
     , m_size(size)
+#endif
 {
     if (hasImage())
         ViewSnapshotStore::singleton().didAddImageToSnapshot(*this);
@@ -167,7 +169,7 @@ ViewSnapshot::~ViewSnapshot()
 bool ViewSnapshot::hasImage() const
 {
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
-    return m_surface;
+    return !!m_surface;
 #elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
     return m_slotID;
 #endif