From 254001e25f58faa55172860a194a95bd31b61565 Mon Sep 17 00:00:00 2001 From: Silenio Quarti Date: Wed, 10 Oct 2012 15:39:18 -0400 Subject: Bug 387755 - GC.copyArea() not work correctly on Mac retina screen --- .../internal/cocoa/AppKitFull.bridgesupport.extras | 3 +++ .../org/eclipse/swt/internal/cocoa/NSScreen.java | 6 ++++- .../cocoa/org/eclipse/swt/internal/cocoa/OS.java | 1 + .../cocoa/org/eclipse/swt/graphics/GC.java | 28 +++++++++++++++++----- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras index 59a008c494..50174a722f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras @@ -2748,6 +2748,9 @@ + + + diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSScreen.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSScreen.java index 4bae3a6527..27b8fc9c1e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSScreen.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSScreen.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -24,6 +24,10 @@ public NSScreen(id id) { super(id); } +public double /*float*/ backingScaleFactor() { + return (double /*float*/)OS.objc_msgSend_fpret(this.id, OS.sel_backingScaleFactor); +} + public int depth() { return (int)/*64*/OS.objc_msgSend(this.id, OS.sel_depth); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java index 4f7e502538..fa3aa66870 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java @@ -1020,6 +1020,7 @@ public static final long /*int*/ sel_availableFonts = sel_registerName("availabl public static final long /*int*/ sel_availableMembersOfFontFamily_ = sel_registerName("availableMembersOfFontFamily:"); public static final long /*int*/ sel_availableTypeFromArray_ = sel_registerName("availableTypeFromArray:"); public static final long /*int*/ sel_backgroundColor = sel_registerName("backgroundColor"); +public static final long /*int*/ sel_backingScaleFactor = sel_registerName("backingScaleFactor"); public static final long /*int*/ sel_badgeLabel = sel_registerName("badgeLabel"); public static final long /*int*/ sel_baselineOffsetInLayoutManager_glyphIndex_ = sel_registerName("baselineOffsetInLayoutManager:glyphIndex:"); public static final long /*int*/ sel_becomeFirstResponder = sel_registerName("becomeFirstResponder"); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java index 00c8c62d65..812cdf8cf1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java @@ -475,6 +475,12 @@ public void copyArea(Image image, int x, int y) { if (handle.isDrawingToScreen()) { NSImage imageHandle = image.handle; NSSize size = imageHandle.size(); + NSArray screens = null; + NSString key = null; + if (OS.VERSION >= 0x1070) { + screens = NSScreen.screens(); + key = NSString.stringWith("NSScreenNumber"); + } CGRect rect = new CGRect(); rect.origin.x = x; rect.origin.y = y; @@ -488,6 +494,16 @@ public void copyArea(Image image, int x, int y) { for (int i = 0; i < count[0]; i++) { OS.memmove(display, displays + (i * 4), 4); OS.CGDisplayBounds(display[0], rect); + double /*float*/ scaling = 1; + if (OS.VERSION >= 0x1070) { + for (int j = 0; j < screens.count(); j++) { + NSScreen screen = new NSScreen(screens.objectAtIndex(j)); + if (display[0] == new NSNumber(screen.deviceDescription().objectForKey(key)).intValue()) { + scaling = screen.backingScaleFactor(); + break; + } + } + } long /*int*/ srcImage = 0; long /*int*/ address = OS.VERSION >= 0x1070 ? 0 : OS.CGDisplayBaseAddress(display[0]); if (address != 0) { @@ -518,7 +534,7 @@ public void copyArea(Image image, int x, int y) { if (OS.VERSION >= 0x1060) srcImage = OS.CGDisplayCreateImage(display[0]); } if (srcImage != 0) { - copyArea(image, x - (int)rect.origin.x, y - (int)rect.origin.y, srcImage); + copyArea(image, (int)(x * scaling - rect.origin.x), (int)(y * scaling - rect.origin.y), srcImage, scaling); OS.CGImageRelease(srcImage); } } @@ -530,7 +546,7 @@ public void copyArea(Image image, int x, int y) { } } -void copyArea (Image image, int x, int y, long /*int*/ srcImage) { +void copyArea (Image image, int x, int y, long /*int*/ srcImage, double /*float*/ scaling) { if (srcImage == 0) return; NSBitmapImageRep rep = image.getRepresentation(); long /*int*/ bpc = rep.bitsPerSample(); @@ -550,10 +566,10 @@ void copyArea (Image image, int x, int y, long /*int*/ srcImage) { OS.CGColorSpaceRelease(colorspace); if (context != 0) { CGRect rect = new CGRect(); - rect.origin.x = -x; - rect.origin.y = y; - rect.size.width = OS.CGImageGetWidth(srcImage); - rect.size.height = OS.CGImageGetHeight(srcImage); + rect.origin.x = -x / scaling; + rect.origin.y = y / scaling; + rect.size.width = OS.CGImageGetWidth(srcImage) / scaling; + rect.size.height = OS.CGImageGetHeight(srcImage) / scaling; OS.CGContextTranslateCTM(context, 0, -(rect.size.height - height)); OS.CGContextDrawImage(context, rect, srcImage); OS.CGContextRelease(context); -- cgit