Title: [184758] branches/safari-601.1.32.2-branch/Source/WebKit2
Revision
184758
Author
[email protected]
Date
2015-05-21 23:35:57 -0700 (Thu, 21 May 2015)

Log Message

Merged r184739.  rdar://problem/20892362

Modified Paths

Diff

Modified: branches/safari-601.1.32.2-branch/Source/WebKit2/ChangeLog (184757 => 184758)


--- branches/safari-601.1.32.2-branch/Source/WebKit2/ChangeLog	2015-05-22 06:35:05 UTC (rev 184757)
+++ branches/safari-601.1.32.2-branch/Source/WebKit2/ChangeLog	2015-05-22 06:35:57 UTC (rev 184758)
@@ -1,5 +1,26 @@
 2015-05-21  Babak Shafiei  <[email protected]>
 
+        Merge r184739.
+
+    2015-05-21  Enrica Casucci  <[email protected]>
+
+            [iOS] Crash when taking a snapshot of a large PDF.
+            https://bugs.webkit.org/show_bug.cgi?id=145286
+            rdar://problem/20892362
+
+            Reviewed by Tim Horton.
+
+            The code for the PDF case was incorrectly computing the snapshot rect.
+            On top of that drawViewHierarchyInRect was ignoring the rect and
+            always creating an image using the view bounds causing the crash.
+            We are now always using the IOSurface if we are parented or
+            an image context when we are not.
+
+            * UIProcess/API/Cocoa/WKWebView.mm:
+            (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
+
+2015-05-21  Babak Shafiei  <[email protected]>
+
         Merge r184738.
 
     2015-05-21  Anders Carlsson  <[email protected]>

Modified: branches/safari-601.1.32.2-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (184757 => 184758)


--- branches/safari-601.1.32.2-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2015-05-22 06:35:05 UTC (rev 184757)
+++ branches/safari-601.1.32.2-branch/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2015-05-22 06:35:57 UTC (rev 184758)
@@ -2713,6 +2713,20 @@
     CGFloat imageHeight = imageScale * snapshotRectInContentCoordinates.size.height;
     CGSize imageSize = CGSizeMake(imageWidth, imageHeight);
 
+#if USE(IOSURFACE)
+    // If we are parented and thus won't incur a significant penalty from paging in tiles, snapshot the view hierarchy directly.
+    if (self.window) {
+        auto surface = WebCore::IOSurface::create(WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebCore::ColorSpaceDeviceRGB);
+        CGFloat imageScaleInViewCoordinates = imageWidth / rectInViewCoordinates.size.width;
+        CATransform3D transform = CATransform3DMakeScale(imageScaleInViewCoordinates, imageScaleInViewCoordinates, 1);
+        transform = CATransform3DTranslate(transform, -rectInViewCoordinates.origin.x, -rectInViewCoordinates.origin.y, 0);
+        CARenderServerRenderLayerWithTransform(MACH_PORT_NULL, self.layer.context.contextId, reinterpret_cast<uint64_t>(self.layer), surface->surface(), 0, 0, &transform);
+        completionHandler(surface->createImage().get());
+
+        return;
+    }
+#endif
+    
     if (_customContentView) {
         UIGraphicsBeginImageContextWithOptions(imageSize, YES, 1);
 
@@ -2720,41 +2734,18 @@
         [customContentView.backgroundColor set];
         UIRectFill(CGRectMake(0, 0, imageWidth, imageHeight));
 
-        CGRect destinationRect = customContentView.bounds;
-        destinationRect.origin.x = -snapshotRectInContentCoordinates.origin.x * imageScale;
-        destinationRect.origin.y = -snapshotRectInContentCoordinates.origin.y * imageScale;
-        destinationRect.size.width *= imageScale;
-        destinationRect.size.height *= imageScale;
+        CGContextRef context = UIGraphicsGetCurrentContext();
+        CGContextTranslateCTM(context, -snapshotRectInContentCoordinates.origin.x * imageScale, -snapshotRectInContentCoordinates.origin.y * imageScale);
+        CGContextScaleCTM(context, imageScale, imageScale);
+        [customContentView.layer renderInContext:context];
 
-        if ([_customContentView window])
-            [customContentView drawViewHierarchyInRect:destinationRect afterScreenUpdates:NO];
-        else {
-            CGContextRef context = UIGraphicsGetCurrentContext();
-            CGContextTranslateCTM(context, destinationRect.origin.x, destinationRect.origin.y);
-            CGContextScaleCTM(context, imageScale, imageScale);
-            [customContentView.layer renderInContext:context];
-        }
-
         completionHandler([UIGraphicsGetImageFromCurrentImageContext() CGImage]);
 
         UIGraphicsEndImageContext();
         return;
     }
 
-#if USE(IOSURFACE)
-    // If we are parented and thus won't incur a significant penalty from paging in tiles, snapshot the view hierarchy directly.
-    if (self.window) {
-        auto surface = WebCore::IOSurface::create(WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebCore::ColorSpaceDeviceRGB);
-        CGFloat imageScaleInViewCoordinates = imageWidth / rectInViewCoordinates.size.width;
-        CATransform3D transform = CATransform3DMakeScale(imageScaleInViewCoordinates, imageScaleInViewCoordinates, 1);
-        transform = CATransform3DTranslate(transform, -rectInViewCoordinates.origin.x, -rectInViewCoordinates.origin.y, 0);
-        CARenderServerRenderLayerWithTransform(MACH_PORT_NULL, self.layer.context.contextId, reinterpret_cast<uint64_t>(self.layer), surface->surface(), 0, 0, &transform);
-        completionHandler(surface->createImage().get());
 
-        return;
-    }
-#endif
-
     void(^copiedCompletionHandler)(CGImageRef) = [completionHandler copy];
     _page->takeSnapshot(WebCore::enclosingIntRect(snapshotRectInContentCoordinates), WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebKit::SnapshotOptionsExcludeDeviceScaleFactor, [=](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error) {
         if (imageHandle.isNull()) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to