REGRESSION (r181910): WKWebView incorrectly scales snapshot
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 May 2015 00:21:46 +0000 (00:21 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 May 2015 00:21:46 +0000 (00:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145076

Patch by James Savage <james.savage@apple.com> on 2015-05-15
Reviewed by Tim Horton.

We added a fast path to snapshotting using IOSurfaces with
http://trac.webkit.org/changeset/181910 which incorrectly determined
scale and transform and resulted in bad snapshots in some situations.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
When snapshotting an IOSurface we need to compute our scale based off of
the rect in the WKWebView coordinates, we also failed to account for
non-zero origins in the snapshot rect. Remove an unused varible while
we're here.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

index 511f00e..db2454c 100644 (file)
@@ -1,3 +1,21 @@
+2015-05-15  James Savage  <james.savage@apple.com>
+
+        REGRESSION (r181910): WKWebView incorrectly scales snapshot
+        https://bugs.webkit.org/show_bug.cgi?id=145076
+
+        Reviewed by Tim Horton.
+
+        We added a fast path to snapshotting using IOSurfaces with
+        http://trac.webkit.org/changeset/181910 which incorrectly determined
+        scale and transform and resulted in bad snapshots in some situations.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
+        When snapshotting an IOSurface we need to compute our scale based off of
+        the rect in the WKWebView coordinates, we also failed to account for
+        non-zero origins in the snapshot rect. Remove an unused varible while
+        we're here.
+
 2015-05-15  Alex Christensen  <achristensen@webkit.org>
 
         [Content Extensions] Fail to load old content extension files
index ebbe3c1..3550428 100644 (file)
@@ -2725,16 +2725,10 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
 #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) {
-        float deviceScaleFactor = _page->deviceScaleFactor();
-
-        CGRect imageRectInPoints;
-        imageRectInPoints.size.width = imageWidth / deviceScaleFactor;
-        imageRectInPoints.size.height = imageRectInPoints.size.width / rectInViewCoordinates.size.width * rectInViewCoordinates.size.height;
-        imageRectInPoints.origin.x = rectInViewCoordinates.origin.x / deviceScaleFactor;
-        imageRectInPoints.origin.y = rectInViewCoordinates.origin.y / deviceScaleFactor;
-
         auto surface = WebCore::IOSurface::create(WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebCore::ColorSpaceDeviceRGB);
-        CATransform3D transform = CATransform3DMakeScale(deviceScaleFactor, deviceScaleFactor, 1);
+        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());