Title: [170925] trunk/Source
Revision
170925
Author
timothy_hor...@apple.com
Date
2014-07-09 12:31:33 -0700 (Wed, 09 Jul 2014)

Log Message

Use IOSurface ViewSnapshots everywhere on Mac, remove JPEG encoding path
https://bugs.webkit.org/show_bug.cgi?id=134773

Reviewed by Anders Carlsson.

* UIProcess/API/mac/WKView.mm:
(-[WKView _takeViewSnapshot]):
* UIProcess/mac/ViewSnapshotStore.h:
* UIProcess/mac/ViewSnapshotStore.mm:
(WebKit::ViewSnapshotStore::ViewSnapshotStore):
(WebKit::ViewSnapshotStore::~ViewSnapshotStore):
(WebKit::ViewSnapshotStore::recordSnapshot):
(WebKit::ViewSnapshot::clearImage):
(WebKit::ViewSnapshot::asLayerContents):
(WebKit::createIOSurfaceFromImage): Deleted.
(WebKit::compressImageAsJPEG): Deleted.
(WebKit::ViewSnapshotStore::reduceSnapshotMemoryCost): Deleted.
(WebKit::ViewSnapshotStore::didCompressSnapshot): Deleted.
Remove all ViewSnapshot(Store) code related to JPEG-encoded snapshots.
Remove the "image" member on ViewSnapshot; Mac will always start out with an IOSurface instead.
Adopt WebCore::IOSurface::createFromImage to make that happen.
Add a comment noting that if a snapshot comes back empty, we should throw it away completely.

* WebCore.exp.in:
* platform/graphics/cocoa/IOSurface.h:
* platform/graphics/cocoa/IOSurface.mm:
(IOSurface::createFromImage):
Move make-an-IOSurface-from-a-CGImageRef into WebCore::IOSurface.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (170924 => 170925)


--- trunk/Source/WebCore/ChangeLog	2014-07-09 19:11:47 UTC (rev 170924)
+++ trunk/Source/WebCore/ChangeLog	2014-07-09 19:31:33 UTC (rev 170925)
@@ -1,3 +1,16 @@
+2014-07-09  Tim Horton  <timothy_hor...@apple.com>
+
+        Use IOSurface ViewSnapshots everywhere on Mac, remove JPEG encoding path
+        https://bugs.webkit.org/show_bug.cgi?id=134773
+
+        Reviewed by Anders Carlsson.
+
+        * WebCore.exp.in:
+        * platform/graphics/cocoa/IOSurface.h:
+        * platform/graphics/cocoa/IOSurface.mm:
+        (IOSurface::createFromImage):
+        Move make-an-IOSurface-from-a-CGImageRef into WebCore::IOSurface.
+
 2014-07-09  Enrica Casucci  <enr...@apple.com>
 
         Implement Editor::fontAttributesForSelectionStart() or iOS.

Modified: trunk/Source/WebCore/WebCore.exp.in (170924 => 170925)


--- trunk/Source/WebCore/WebCore.exp.in	2014-07-09 19:11:47 UTC (rev 170924)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-07-09 19:31:33 UTC (rev 170925)
@@ -1479,6 +1479,7 @@
 __ZN7WebCore9HTMLNames9styleAttrE
 __ZN7WebCore9HTMLNames9titleAttrE
 __ZN7WebCore9HTMLNames9valueAttrE
+__ZN7WebCore9IOSurface15createFromImageEP7CGImage
 __ZN7WebCore9InlineBox14adjustPositionEff
 __ZN7WebCore9InlineBox14dirtyLineBoxesEv
 __ZN7WebCore9InlineBox14selectionStateEv

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h (170924 => 170925)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2014-07-09 19:11:47 UTC (rev 170924)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2014-07-09 19:31:33 UTC (rev 170925)
@@ -40,6 +40,7 @@
     static PassRefPtr<IOSurface> create(IntSize, ColorSpace);
     static PassRefPtr<IOSurface> createFromMachPort(mach_port_t, ColorSpace);
     static PassRefPtr<IOSurface> createFromSurface(IOSurfaceRef, ColorSpace);
+    static PassRefPtr<IOSurface> createFromImage(CGImageRef);
 
     static IntSize maximumSize();
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (170924 => 170925)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm	2014-07-09 19:11:47 UTC (rev 170924)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm	2014-07-09 19:31:33 UTC (rev 170925)
@@ -70,6 +70,19 @@
     return adoptRef(new IOSurface(surface, colorSpace));
 }
 
+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);
+    auto surfaceContext = surface->ensurePlatformContext();
+    CGContextDrawImage(surfaceContext, CGRectMake(0, 0, width, height), image);
+    CGContextFlush(surfaceContext);
+
+    return surface.release();
+}
+
 IOSurface::IOSurface(IntSize size, ColorSpace colorSpace)
     : m_colorSpace(colorSpace)
     , m_size(size)

Modified: trunk/Source/WebKit2/ChangeLog (170924 => 170925)


--- trunk/Source/WebKit2/ChangeLog	2014-07-09 19:11:47 UTC (rev 170924)
+++ trunk/Source/WebKit2/ChangeLog	2014-07-09 19:31:33 UTC (rev 170925)
@@ -1,3 +1,28 @@
+2014-07-09  Tim Horton  <timothy_hor...@apple.com>
+
+        Use IOSurface ViewSnapshots everywhere on Mac, remove JPEG encoding path
+        https://bugs.webkit.org/show_bug.cgi?id=134773
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _takeViewSnapshot]):
+        * UIProcess/mac/ViewSnapshotStore.h:
+        * UIProcess/mac/ViewSnapshotStore.mm:
+        (WebKit::ViewSnapshotStore::ViewSnapshotStore):
+        (WebKit::ViewSnapshotStore::~ViewSnapshotStore):
+        (WebKit::ViewSnapshotStore::recordSnapshot):
+        (WebKit::ViewSnapshot::clearImage):
+        (WebKit::ViewSnapshot::asLayerContents):
+        (WebKit::createIOSurfaceFromImage): Deleted.
+        (WebKit::compressImageAsJPEG): Deleted.
+        (WebKit::ViewSnapshotStore::reduceSnapshotMemoryCost): Deleted.
+        (WebKit::ViewSnapshotStore::didCompressSnapshot): Deleted.
+        Remove all ViewSnapshot(Store) code related to JPEG-encoded snapshots.
+        Remove the "image" member on ViewSnapshot; Mac will always start out with an IOSurface instead.
+        Adopt WebCore::IOSurface::createFromImage to make that happen.
+        Add a comment noting that if a snapshot comes back empty, we should throw it away completely.
+
 2014-07-09  Anders Carlsson  <ander...@apple.com>
 
         RemoteLayerBackingStore::ensureBackingStore should ensure that the entire backing store gets redrawn

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (170924 => 170925)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2014-07-09 19:11:47 UTC (rev 170924)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2014-07-09 19:31:33 UTC (rev 170925)
@@ -3141,7 +3141,8 @@
 
     auto croppedSnapshotImage = adoptCF(CGImageCreateWithImageInRect(windowSnapshotImage.get(), NSRectToCGRect([window convertRectToBacking:croppedImageRect])));
 
-    snapshot.image = croppedSnapshotImage.get();
+    snapshot.surface = IOSurface::createFromImage(croppedSnapshotImage.get());
+    snapshot.surface->setIsVolatile(true);
 
     IntSize imageSize(CGImageGetWidth(croppedSnapshotImage.get()), CGImageGetHeight(croppedSnapshotImage.get()));
     snapshot.size = imageSize;

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h (170924 => 170925)


--- trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h	2014-07-09 19:11:47 UTC (rev 170924)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h	2014-07-09 19:31:33 UTC (rev 170925)
@@ -37,17 +37,10 @@
 
 OBJC_CLASS CAContext;
 
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
-#define USE_JPEG_VIEW_SNAPSHOTS false
+#if PLATFORM(MAC)
 #define USE_IOSURFACE_VIEW_SNAPSHOTS true
 #define USE_RENDER_SERVER_VIEW_SNAPSHOTS false
-#elif PLATFORM(MAC)
-// Mountain Lion and before do not support IOSurface purgeability.
-#define USE_JPEG_VIEW_SNAPSHOTS true
-#define USE_IOSURFACE_VIEW_SNAPSHOTS false
-#define USE_RENDER_SERVER_VIEW_SNAPSHOTS false
 #else
-#define USE_JPEG_VIEW_SNAPSHOTS false
 #define USE_IOSURFACE_VIEW_SNAPSHOTS false
 #define USE_RENDER_SERVER_VIEW_SNAPSHOTS true
 #endif
@@ -58,9 +51,8 @@
 class WebPageProxy;
 
 struct ViewSnapshot {
-#if USE_JPEG_VIEW_SNAPSHOTS || USE_IOSURFACE_VIEW_SNAPSHOTS
+#if USE_IOSURFACE_VIEW_SNAPSHOTS
     RefPtr<WebCore::IOSurface> surface;
-    RetainPtr<CGImageRef> image;
 #endif
 #if USE_RENDER_SERVER_VIEW_SNAPSHOTS
     uint32_t slotID = 0;
@@ -101,13 +93,7 @@
 private:
     void pruneSnapshots(WebPageProxy&);
     void removeSnapshotImage(ViewSnapshot&);
-    void reduceSnapshotMemoryCost(const String& uuid);
 
-#if USE_JPEG_VIEW_SNAPSHOTS
-    void didCompressSnapshot(const String& uuid, RetainPtr<CGImageRef> newImage, size_t newImageSize);
-    dispatch_queue_t m_compressionQueue;
-#endif
-
     HashMap<String, ViewSnapshot> m_snapshotMap;
 
     bool m_enabled;

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm (170924 => 170925)


--- trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm	2014-07-09 19:11:47 UTC (rev 170924)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm	2014-07-09 19:31:33 UTC (rev 170925)
@@ -40,8 +40,8 @@
 
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
 static const size_t maximumSnapshotCacheSize = 400 * (1024 * 1024);
-#elif USE_JPEG_VIEW_SNAPSHOTS || USE_RENDER_SERVER_VIEW_SNAPSHOTS
-// Because non-IOSurface snapshots are not purgeable, we should keep fewer around.
+#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
+// Because render server snapshots are not purgeable, we should keep fewer around.
 static const size_t maximumSnapshotCacheSize = 50 * (1024 * 1024);
 #endif
 
@@ -51,16 +51,10 @@
     : m_enabled(true)
     , m_snapshotCacheSize(0)
 {
-#if USE_JPEG_VIEW_SNAPSHOTS
-    m_compressionQueue = dispatch_queue_create("com.apple.WebKit.ViewSnapshotStore.CompressionQueue", nullptr);
-#endif
 }
 
 ViewSnapshotStore::~ViewSnapshotStore()
 {
-#if USE_JPEG_VIEW_SNAPSHOTS
-    dispatch_release(m_compressionQueue);
-#endif
     discardSnapshots();
 }
 
@@ -185,8 +179,6 @@
 
     m_snapshotMap.add(item->snapshotUUID(), snapshot);
     m_snapshotCacheSize += snapshot.imageSizeInBytes;
-
-    reduceSnapshotMemoryCost(item->snapshotUUID());
 }
 
 bool ViewSnapshotStore::getSnapshot(WebBackForwardListItem* item, ViewSnapshot& snapshot)
@@ -207,84 +199,6 @@
         removeSnapshotImage(snapshot);
 }
 
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
-static RefPtr<IOSurface> createIOSurfaceFromImage(CGImageRef image)
-{
-    size_t width = CGImageGetWidth(image);
-    size_t height = CGImageGetHeight(image);
-
-    RefPtr<IOSurface> surface = IOSurface::create(IntSize(width, height), ColorSpaceDeviceRGB);
-    RetainPtr<CGContextRef> surfaceContext = surface->ensurePlatformContext();
-    CGContextDrawImage(surfaceContext.get(), CGRectMake(0, 0, width, height), image);
-    CGContextFlush(surfaceContext.get());
-
-    surface->setIsVolatile(true);
-
-    return surface;
-}
-#endif
-
-#if USE_JPEG_VIEW_SNAPSHOTS
-static std::pair<RetainPtr<CGImageRef>, size_t> compressImageAsJPEG(CGImageRef image)
-{
-    RetainPtr<NSData> compressedData = adoptNS([[NSMutableData alloc] init]);
-    RetainPtr<CGImageDestinationRef> destination = adoptCF(CGImageDestinationCreateWithData((CFMutableDataRef)compressedData.get(), kUTTypeJPEG, 1, 0));
-
-    RetainPtr<NSDictionary> options = @{
-        (NSString*)kCGImageDestinationLossyCompressionQuality: @0.9
-    };
-
-    CGImageDestinationAddImage(destination.get(), image, (CFDictionaryRef)options.get());
-    CGImageDestinationFinalize(destination.get());
-
-    RetainPtr<CGImageSourceRef> imageSourceRef = adoptCF(CGImageSourceCreateWithData((CFDataRef)compressedData.get(), 0));
-    RetainPtr<CGImageRef> compressedSnapshot = adoptCF(CGImageSourceCreateImageAtIndex(imageSourceRef.get(), 0, 0));
-    
-    return std::make_pair(compressedSnapshot, [compressedData length]);
-}
-#endif
-
-void ViewSnapshotStore::reduceSnapshotMemoryCost(const String& uuid)
-{
-    const auto& snapshotIterator = m_snapshotMap.find(uuid);
-    if (snapshotIterator == m_snapshotMap.end())
-        return;
-    ViewSnapshot& snapshot = snapshotIterator->value;
-    if (!snapshot.hasImage())
-        return;
-
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
-    snapshot.surface = createIOSurfaceFromImage(snapshot.image.get());
-    snapshot.image = nullptr;
-#elif USE_JPEG_VIEW_SNAPSHOTS
-    RetainPtr<CGImageRef> originalImage = snapshot.image.get();
-    dispatch_async(m_compressionQueue, [uuid, originalImage] {
-        auto imageAndBytes = compressImageAsJPEG(originalImage.get());
-        dispatch_async(dispatch_get_main_queue(), [uuid, imageAndBytes] {
-            ViewSnapshotStore::shared().didCompressSnapshot(uuid, imageAndBytes.first, imageAndBytes.second);
-        });
-    });
-#endif
-}
-
-#if USE_JPEG_VIEW_SNAPSHOTS
-void ViewSnapshotStore::didCompressSnapshot(const String& uuid, RetainPtr<CGImageRef> newImage, size_t newImageSize)
-{
-    const auto& snapshotIterator = m_snapshotMap.find(uuid);
-    if (snapshotIterator == m_snapshotMap.end())
-        return;
-    ViewSnapshot& snapshot = snapshotIterator->value;
-
-    size_t originalImageSize = snapshot.imageSizeInBytes;
-    if (!newImage || newImageSize > originalImageSize)
-        return;
-    snapshot.image = newImage;
-    snapshot.imageSizeInBytes = newImageSize;
-    m_snapshotCacheSize += newImageSize;
-    m_snapshotCacheSize -= originalImageSize;
-}
-#endif
-
 bool ViewSnapshot::hasImage() const
 {
     return imageSizeInBytes;
@@ -294,11 +208,7 @@
 {
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
     surface = nullptr;
-#endif
-#if USE_IOSURFACE_VIEW_SNAPSHOTS || USE_JPEG_VIEW_SNAPSHOTS
-    image = nullptr;
-#endif
-#if USE_RENDER_SERVER_VIEW_SNAPSHOTS
+#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
     if (slotID)
         [ViewSnapshotStore::snapshottingContext() deleteSlot:slotID];
     slotID = 0;
@@ -309,17 +219,15 @@
 id ViewSnapshot::asLayerContents()
 {
 #if USE_IOSURFACE_VIEW_SNAPSHOTS
-    if (surface) {
-        if (surface->setIsVolatile(false) != IOSurface::SurfaceState::Valid)
-            return nullptr;
+    if (!surface)
+        return nullptr;
 
-        return (id)surface->surface();
-    }
-#endif
-#if USE_IOSURFACE_VIEW_SNAPSHOTS || USE_JPEG_VIEW_SNAPSHOTS
-    return (id)image.get();
-#endif
-#if USE_RENDER_SERVER_VIEW_SNAPSHOTS
+    // FIXME: This should destroy the surface and inform the ViewSnapshotStore to reduce m_snapshotCacheSize.
+    if (surface->setIsVolatile(false) != IOSurface::SurfaceState::Valid)
+        return nullptr;
+
+    return (id)surface->surface();
+#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
     return [CAContext objectForSlot:slotID];
 #endif
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to