View snapshots are sometimes taken at the wrong scale
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Jun 2014 06:25:08 +0000 (06:25 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Jun 2014 06:25:08 +0000 (06:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133419
<rdar://problem/17087497>

Reviewed by Sam Weinig.

* UIProcess/API/mac/WKView.mm:
(-[WKView _takeViewSnapshot]):
Work around <rdar://problem/17084993> by re-requesting the snapshot at
kCGWindowImageNominalResolution if it was captured at the wrong scale.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/mac/WKView.mm

index 52df018..298d3d0 100644 (file)
@@ -1,3 +1,16 @@
+2014-05-31  Timothy Horton  <timothy_horton@apple.com>
+
+        View snapshots are sometimes taken at the wrong scale
+        https://bugs.webkit.org/show_bug.cgi?id=133419
+        <rdar://problem/17087497>
+
+        Reviewed by Sam Weinig.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _takeViewSnapshot]):
+        Work around <rdar://problem/17084993> by re-requesting the snapshot at
+        kCGWindowImageNominalResolution if it was captured at the wrong scale.
+
 2014-05-31  Dan Bernstein  <mitz@apple.com>
 
         [iOS] WebKit2.framework is unused
index 00f0912..22ec7a2 100644 (file)
 
 #if defined(__has_include) && __has_include(<CoreGraphics/CoreGraphicsPrivate.h>)
 #import <CoreGraphics/CoreGraphicsPrivate.h>
-#import <CoreGraphics/CGSCapture.h>
 #endif
 
 extern "C" {
@@ -134,7 +133,6 @@ typedef uint32_t CGSConnectionID;
 typedef uint32_t CGSWindowID;
 CGSConnectionID CGSMainConnectionID(void);
 CGError CGSGetScreenRectForWindow(CGSConnectionID cid, CGSWindowID wid, CGRect *rect);
-CGError CGSCaptureWindowsContentsToRect(CGSConnectionID cid, const CGSWindowID windows[], uint32_t windowCount, CGRect rect, CGImageRef *outImage);
 };
 
 using namespace WebKit;
@@ -3053,14 +3051,16 @@ static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, Sandb
 
     ViewSnapshot snapshot;
 
-    if (![window windowNumber])
+    CGSWindowID windowID = (CGSWindowID)[window windowNumber];
+    if (!windowID)
         return snapshot;
 
-    // FIXME: This should use CGWindowListCreateImage once <rdar://problem/15709646> is resolved.
-    CGSWindowID windowID = [window windowNumber];
-    CGImageRef cgWindowImage = nullptr;
-    CGSCaptureWindowsContentsToRect(CGSMainConnectionID(), &windowID, 1, CGRectNull, &cgWindowImage);
-    RetainPtr<CGImageRef> windowSnapshotImage = adoptCF(cgWindowImage);
+    RetainPtr<CGImageRef> windowSnapshotImage = adoptCF(CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, windowID, kCGWindowImageBoundsIgnoreFraming | kCGWindowImageShouldBeOpaque));
+
+    // Work around <rdar://problem/17084993>; re-request the snapshot at kCGWindowImageNominalResolution if it was captured at the wrong scale.
+    CGFloat desiredSnapshotWidth = window.frame.size.width * window.screen.backingScaleFactor;
+    if (CGImageGetWidth(windowSnapshotImage.get()) != desiredSnapshotWidth)
+        windowSnapshotImage = adoptCF(CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, windowID, kCGWindowImageBoundsIgnoreFraming | kCGWindowImageShouldBeOpaque | kCGWindowImageNominalResolution));
 
     [self _ensureGestureController];