changeset 3767:0da32bf95d30

iOS: Native library loading fixed for iOS. Adding missing JNI_OnLoad_*() functions, etc. Reviewed by David Pulkrabek.
author Oldrich Maticka <oldrich.maticka@oracle.com>
date Thu, 30 May 2013 11:56:03 +0200
parents 55c9c3a55f58
children b29ce522d568
files glass/glass-lib-ios/src/GlassApplication.m glass/glass/src/com/sun/glass/utils/NativeLibLoader.java javafx-iio-native/src/ios/com_sun_javafx_iio_ios_IosImageLoader.m javafx-iio-native/src/jpegloader.c prism-common-native/src/Helpers.c prism-es2-native/src/ios/IOSGLFactory.c
diffstat 6 files changed, 68 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/glass/glass-lib-ios/src/GlassApplication.m	Thu May 30 10:35:03 2013 +0100
+++ b/glass/glass-lib-ios/src/GlassApplication.m	Thu May 30 11:56:03 2013 +0200
@@ -109,6 +109,16 @@
 static int postEventPipe[2];
 static int haveIDs = 0;
 
+//Library entrypoint
+jint JNI_OnLoad_glass(JavaVM *vm, void *reserved)
+{
+#ifdef JNI_VERSION_1_8
+    //min. returned JNI_VERSION required by JDK8 for builtin libraries
+    return JNI_VERSION_1_8;
+#else
+    return JNI_VERSION_1_4;
+#endif
+}
 
 /*
  * Function to set the context class loader for the main glass event thread.
--- a/glass/glass/src/com/sun/glass/utils/NativeLibLoader.java	Thu May 30 10:35:03 2013 +0100
+++ b/glass/glass/src/com/sun/glass/utils/NativeLibLoader.java	Thu May 30 11:56:03 2013 +0200
@@ -128,6 +128,20 @@
                             + libraryName + ") as a fallback");
                 }
             } catch (UnsatisfiedLinkError ex2) {
+                //On iOS we link all libraries staticaly. Presence of library 
+                //is recognized by existence of JNI_OnLoad_libraryname() C function.
+                //If libraryname contains hyphen, it needs to be translated 
+                //to underscore to form valid C function indentifier.
+                if ("iOS".equals(System.getProperty("os.name"))
+                        && libraryName.contains("-")) {
+                    libraryName = libraryName.replace("-", "_");
+                    try {
+                        System.loadLibrary(libraryName);
+                        return;
+                    } catch (UnsatisfiedLinkError ex3) {
+                        throw ex3;
+                    }
+                }
                 // Rethrow original exception
                 throw ex;
             }
--- a/javafx-iio-native/src/ios/com_sun_javafx_iio_ios_IosImageLoader.m	Thu May 30 10:35:03 2013 +0100
+++ b/javafx-iio-native/src/ios/com_sun_javafx_iio_ios_IosImageLoader.m	Thu May 30 11:56:03 2013 +0200
@@ -50,6 +50,17 @@
     static jmethodID IosImageLoader_setInputParametersID;
     static jmethodID IosImageLoader_updateImageProgressID;
 
+    JNIEXPORT jint JNICALL
+    JNI_OnLoad_nativeiio(JavaVM *vm, void *reserved) {
+#ifdef JNI_VERSION_1_8
+        //min. returned JNI_VERSION required by JDK8 for builtin libraries
+        return JNI_VERSION_1_8;
+#else
+        return JNI_VERSION_1_2;
+#endif
+    }
+
+
     /*
      * Class:     com_sun_javafx_iio_ios_IosImageLoader
      * Method:    initNativeLoading
--- a/javafx-iio-native/src/jpegloader.c	Thu May 30 10:35:03 2013 +0100
+++ b/javafx-iio-native/src/jpegloader.c	Thu May 30 11:56:03 2013 +0200
@@ -101,7 +101,12 @@
 JNIEXPORT jint JNICALL
 JNI_OnLoad_javafx_iio(JavaVM *vm, void *reserved) {
     jvm = vm;
+#ifdef JNI_VERSION_1_8
+    //min. returned JNI_VERSION required by JDK8 for builtin libraries
+    return JNI_VERSION_1_8;
+#else
     return JNI_VERSION_1_2;
+#endif
 }
 
 #else
--- a/prism-common-native/src/Helpers.c	Thu May 30 10:35:03 2013 +0100
+++ b/prism-common-native/src/Helpers.c	Thu May 30 11:56:03 2013 +0200
@@ -29,6 +29,24 @@
 #include "Helpers.h"
 #include "PathConsumer.h"
 
+#ifdef __APPLE__
+
+#include <TargetConditionals.h>
+
+#if TARGET_OS_IPHONE /* iOS */
+
+JNIEXPORT jint JNICALL
+ JNI_OnLoad_prism_common(JavaVM* vm, void* reserved) {
+#ifdef JNI_VERSION_1_8
+    return JNI_VERSION_1_8;
+#else
+    return JNI_VERSION_1_4;
+#endif
+}
+
+#endif
+#endif
+
 void PathConsumer_init(PathConsumer *pConsumer,
                        MoveToFunc       *moveTo,
                        LineToFunc       *lineTo,
--- a/prism-es2-native/src/ios/IOSGLFactory.c	Thu May 30 10:35:03 2013 +0100
+++ b/prism-es2-native/src/ios/IOSGLFactory.c	Thu May 30 11:56:03 2013 +0200
@@ -33,6 +33,16 @@
 #include "PrismES2Defs.h"
 #include "com_sun_prism_es2_IOSGLFactory.h"
 
+//Builtin library entrypoint
+JNIEXPORT jint JNICALL
+JNI_OnLoad_prism_es2(JavaVM *vm, void * reserved) {
+#ifdef JNI_VERSION_1_8
+    return JNI_VERSION_1_8;
+#else
+    return JNI_VERSION_1_4;
+#endif
+}
+
 void printAndReleaseResources(jlong pf, jlong ctx, const char *message)
 {
     fprintf(stderr, "%s\n", message);