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 <register.eclipse@brychcy.de>
Signed-off-by: Lakshmi Shanmugam <lshanmug@in.ibm.com>
Signed-off-by: Arun Thondapu <arunkumar.thondapu@in.ibm.com>
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 adcb6f8..caf1ab4 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 @@
 }
 #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 @@
 }
 #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 0bea382..a7572aa 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 @@
 	"NSBeep",
 	"NSBitsPerPixelFromDepth",
 	"NSCalibratedRGBColorSpace",
-	"NSCopyBits",
 	"NSCountWindows",
 	"NSCursorAttributeName",
 	"NSDefaultRunLoopMode",
@@ -872,6 +871,11 @@
 	"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
 	"objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Z",
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 dabf7e2..d178829 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 @@
 	NSBeep_FUNC,
 	NSBitsPerPixelFromDepth_FUNC,
 	NSCalibratedRGBColorSpace_FUNC,
-	NSCopyBits_FUNC,
 	NSCountWindows_FUNC,
 	NSCursorAttributeName_FUNC,
 	NSDefaultRunLoopMode_FUNC,
@@ -882,6 +881,11 @@
 	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
 	objc_1msgSend__JJLorg_eclipse_swt_internal_cocoa_NSRect_2Z_FUNC,
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 290c4a5..81e2830 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 @@
 			<arg swt_gen="true"></arg>
 			<retval swt_gen="true"></retval>
 		</method>
+		<method selector="scrollRect:by:" swt_gen="true">
+			<arg swt_gen="true"></arg>
+			<arg swt_gen="true"></arg>
+			<retval swt_gen="true"></retval>
+		</method>
 		<method selector="scrollRectToVisible:" swt_gen="true">
 			<arg swt_gen="true"></arg>
 			<retval swt_gen="true"></retval>
@@ -5034,12 +5039,6 @@
 		<arg swt_gen="true"></arg>
 		<retval swt_gen="true"></retval>
 	</function>
-	<function name="NSCopyBits" swt_gen="true">
-		<arg swt_gen="true"></arg>
-		<arg swt_gen="true"></arg>
-		<arg swt_gen="true"></arg>
-		<retval></retval>
-	</function>
 	<function name="NSCountWindows" swt_gen="true">
 		<arg swt_gen="true" swt_java_type="int[]" swt_java_type64="long[]"></arg>
 		<retval></retval>
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 61efe09..2aa6305 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 @@
 	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 ff722d7..6aa6b7c 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_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:");
@@ -3256,12 +3257,6 @@
  */
 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*)
  */
 public static final native void NSCountWindows(long[] /*int[]*/ count);
@@ -3996,6 +3991,12 @@
 /**
  * @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
  */
 public static final native long /*int*/ objc_msgSend(long /*int*/ id, long /*int*/ sel, NSRect arg0, boolean arg1);
 /**
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 1d2870a..802653a 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 @@
 			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 27f048d..819ff40 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 @@
 		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);