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: http://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 816de7d..fe46baf 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 7844b47..d71fc1e 100644 (file)
@@ -3231,7 +3231,7 @@ __ZN7WebCore5ColorC1ERKN3WTF6StringE
 #endif
 
 #if USE(IOSURFACE)
-__ZN7WebCore13IOSurfacePool10addSurfaceEPNS_9IOSurfaceE
+__ZN7WebCore13IOSurfacePool10addSurfaceENSt3__110unique_ptrINS_9IOSurfaceENS1_14default_deleteIS3_EEEE
 __ZN7WebCore13IOSurfacePool10sharedPoolEv
 __ZN7WebCore13IOSurfacePool11setPoolSizeEm
 __ZN7WebCore9IOSurface11createImageEv
index 2ea8dcf..ff20ed3 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 98ea9e9..cf83b82 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 f5fb25d..0d132fe 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 11ab20d..5c4ce2e 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 0f14a78..ae4cc13 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 d025c16..bae090b 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 af6ec59..8a02ece 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 b67d9e2..24eb5f6 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 ec18f0f..64619a8 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 2c302b2..9ed7f83 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 3dc91f2..305adb3 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 35d1f35..9d87e28 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