From 94b9e5b93a88d81049fd9be69cda3e0ec503d36d Mon Sep 17 00:00:00 2001 From: Till Brychcy Date: Thu, 29 Sep 2016 22:53:41 +0200 Subject: Bug 502711 - [Cocoa] crashes on „macOS Sierra“ related to NSCopyBits Replaced the calls to deprecated method NSCopyBits with NSView.scrollRect() in GC.copyArea and Canvas.scroll. Removed the native code for NSCopyBits. Disable generation of code for deprecated method NSCopyBits as it is not used anymore Change-Id: I206c76cd6af9230857967fb23641f0773f90e5de Signed-off-by: Till Brychcy Signed-off-by: Lakshmi Shanmugam Signed-off-by: Arun Thondapu --- .../Eclipse SWT PI/cocoa/library/os.c | 47 ++++++++++++++-------- .../Eclipse SWT PI/cocoa/library/os_stats.c | 6 ++- .../Eclipse SWT PI/cocoa/library/os_stats.h | 6 ++- .../internal/cocoa/AppKitFull.bridgesupport.extras | 11 +++-- .../org/eclipse/swt/internal/cocoa/NSView.java | 4 ++ .../cocoa/org/eclipse/swt/internal/cocoa/OS.java | 13 +++--- .../cocoa/org/eclipse/swt/graphics/GC.java | 5 ++- .../cocoa/org/eclipse/swt/widgets/Canvas.java | 5 ++- 8 files changed, 64 insertions(+), 33 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c index adcb6f8f79..caf1ab405b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c @@ -4555,23 +4555,6 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(NSCalibratedRGBColorSpace) } #endif -#ifndef NO_NSCopyBits -JNIEXPORT void JNICALL OS_NATIVE(NSCopyBits) - (JNIEnv *env, jclass that, jintLong arg0, jobject arg1, jobject arg2) -{ - NSRect _arg1, *lparg1=NULL; - NSPoint _arg2, *lparg2=NULL; - OS_NATIVE_ENTER(env, that, NSCopyBits_FUNC); - if (arg1) if ((lparg1 = getNSRectFields(env, arg1, &_arg1)) == NULL) goto fail; - if (arg2) if ((lparg2 = getNSPointFields(env, arg2, &_arg2)) == NULL) goto fail; - NSCopyBits((NSInteger)arg0, *lparg1, *lparg2); -fail: - if (arg2 && lparg2) setNSPointFields(env, arg2, lparg2); - if (arg1 && lparg1) setNSRectFields(env, arg1, lparg1); - OS_NATIVE_EXIT(env, that, NSCopyBits_FUNC); -} -#endif - #ifndef NO_NSCountWindows JNIEXPORT void JNICALL OS_NATIVE(NSCountWindows) (JNIEnv *env, jclass that, jintLongArray arg0) @@ -8469,6 +8452,36 @@ fail: } #endif +#if (!defined(NO_objc_1msgSend__IILorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2) && !defined(JNI64)) || (!defined(NO_objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2) && defined(JNI64)) +#ifndef JNI64 +JNIEXPORT jintLong JNICALL OS_NATIVE(objc_1msgSend__IILorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jobject arg2, jobject arg3) +#else +JNIEXPORT jintLong JNICALL OS_NATIVE(objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jobject arg2, jobject arg3) +#endif +{ + NSRect _arg2, *lparg2=NULL; + NSSize _arg3, *lparg3=NULL; + jintLong rc = 0; +#ifndef JNI64 + OS_NATIVE_ENTER(env, that, objc_1msgSend__IILorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2_FUNC); +#else + OS_NATIVE_ENTER(env, that, objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2_FUNC); +#endif + if (arg2) if ((lparg2 = getNSRectFields(env, arg2, &_arg2)) == NULL) goto fail; + if (arg3) if ((lparg3 = getNSSizeFields(env, arg3, &_arg3)) == NULL) goto fail; + rc = (jintLong)((jintLong (*)(jintLong, jintLong, NSRect, NSSize))objc_msgSend)(arg0, arg1, *lparg2, *lparg3); +fail: + if (arg3 && lparg3) setNSSizeFields(env, arg3, lparg3); + if (arg2 && lparg2) setNSRectFields(env, arg2, lparg2); +#ifndef JNI64 + OS_NATIVE_EXIT(env, that, objc_1msgSend__IILorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2_FUNC); +#else + OS_NATIVE_EXIT(env, that, objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2_FUNC); +#endif + return rc; +} +#endif + #if (!defined(NO_objc_1msgSend__IILorg_eclipse_swt_internal_cocoa_NSRect_2Z) && !defined(JNI64)) || (!defined(NO_objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Z) && defined(JNI64)) #ifndef JNI64 JNIEXPORT jintLong JNICALL OS_NATIVE(objc_1msgSend__IILorg_eclipse_swt_internal_cocoa_NSRect_2Z)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jobject arg2, jboolean arg3) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c index 0bea38227f..a7572aac02 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.c @@ -340,7 +340,6 @@ char * OS_nativeFunctionNames[] = { "NSBeep", "NSBitsPerPixelFromDepth", "NSCalibratedRGBColorSpace", - "NSCopyBits", "NSCountWindows", "NSCursorAttributeName", "NSDefaultRunLoopMode", @@ -871,6 +870,11 @@ char * OS_nativeFunctionNames[] = { #else "objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSRect_2JD", #endif +#ifndef JNI64 + "objc_1msgSend__IILorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2", +#else + "objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2", +#endif #ifndef JNI64 "objc_1msgSend__IILorg_eclipse_swt_internal_cocoa_NSRect_2Z", #else diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h index dabf7e2a72..d1788297c5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os_stats.h @@ -350,7 +350,6 @@ typedef enum { NSBeep_FUNC, NSBitsPerPixelFromDepth_FUNC, NSCalibratedRGBColorSpace_FUNC, - NSCopyBits_FUNC, NSCountWindows_FUNC, NSCursorAttributeName_FUNC, NSDefaultRunLoopMode_FUNC, @@ -881,6 +880,11 @@ typedef enum { #else objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSRect_2JD_FUNC, #endif +#ifndef JNI64 + objc_1msgSend__IILorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2_FUNC, +#else + objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Lorg_eclipse_swt_internal_cocoa_NSSize_2_FUNC, +#endif #ifndef JNI64 objc_1msgSend__IILorg_eclipse_swt_internal_cocoa_NSRect_2Z_FUNC, #else 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 290c4a5091..81e2830288 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 @@ -4102,6 +4102,11 @@ + + + + + @@ -5034,12 +5039,6 @@ - - - - - - diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java index 61efe09316..2aa630582e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSView.java @@ -256,6 +256,10 @@ public void scrollPoint(NSPoint aPoint) { OS.objc_msgSend(this.id, OS.sel_scrollPoint_, aPoint); } +public void scrollRect(NSRect aRect, NSSize delta) { + OS.objc_msgSend(this.id, OS.sel_scrollRect_by_, aRect, delta); +} + public boolean scrollRectToVisible(NSRect aRect) { return OS.objc_msgSend_bool(this.id, OS.sel_scrollRectToVisible_, aRect); } 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 ff722d7bb2..6aa6b7c621 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 @@ -1793,6 +1793,7 @@ public static final long /*int*/ sel_scrollClipView_toPoint_ = sel_registerName( public static final long /*int*/ sel_scrollColumnToVisible_ = sel_registerName("scrollColumnToVisible:"); public static final long /*int*/ sel_scrollPoint_ = sel_registerName("scrollPoint:"); public static final long /*int*/ sel_scrollRangeToVisible_ = sel_registerName("scrollRangeToVisible:"); +public static final long /*int*/ sel_scrollRect_by_ = sel_registerName("scrollRect:by:"); public static final long /*int*/ sel_scrollRectToVisible_ = sel_registerName("scrollRectToVisible:"); public static final long /*int*/ sel_scrollRowToVisible_ = sel_registerName("scrollRowToVisible:"); public static final long /*int*/ sel_scrollToPoint_ = sel_registerName("scrollToPoint:"); @@ -3255,12 +3256,6 @@ public static final native void NSBeep(); * @param depth cast=(NSWindowDepth) */ public static final native long /*int*/ NSBitsPerPixelFromDepth(int depth); -/** - * @param srcGState cast=(NSInteger) - * @param srcRect flags=struct - * @param destPoint flags=struct - */ -public static final native void NSCopyBits(long /*int*/ srcGState, NSRect srcRect, NSPoint destPoint); /** * @param count cast=(NSInteger*) */ @@ -3993,6 +3988,12 @@ public static final native long /*int*/ objc_msgSend(long /*int*/ id, long /*int * @param arg1 flags=struct */ public static final native long /*int*/ objc_msgSend(long /*int*/ id, long /*int*/ sel, NSRect arg0, NSRect arg1, long /*int*/ arg2, double /*float*/ arg3); +/** + * @method flags=cast + * @param arg0 flags=struct + * @param arg1 flags=struct + */ +public static final native long /*int*/ objc_msgSend(long /*int*/ id, long /*int*/ sel, NSRect arg0, NSSize arg1); /** * @method flags=cast * @param arg0 flags=struct 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 1d2870a909..802653a116 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 @@ -629,7 +629,10 @@ public void copyArea(int srcX, int srcY, int width, int height, int destX, int d dest.y = destY; view.lockFocus(); - OS.NSCopyBits(0, damage , dest); + NSSize delta = new NSSize(); + delta.width = deltaX; + delta.height = deltaY; + view.scrollRect(damage, delta); view.unlockFocus(); if (paint) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java index 27f048d200..819ff40749 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java @@ -425,7 +425,10 @@ public void scroll (int destX, int destY, int x, int y, int width, int height, b dest.y = destY; view.lockFocus(); - OS.NSCopyBits(0, damage , dest); + NSSize delta = new NSSize(); + delta.width = deltaX; + delta.height = deltaY; + view.scrollRect(damage, delta); view.unlockFocus(); boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY); -- cgit v1.2.3