diff options
author | Sven Gothel <[email protected]> | 2013-10-19 06:47:48 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-10-19 06:47:48 +0200 |
commit | 6be41a8e457ec2881f4ce351395ba84748a737b6 (patch) | |
tree | 057311ecf74b576f0dd5187f8d44e507ff2cc07e /resources/clImplCustomCode.java | |
parent | 412dd81be138c49f8c683f9d350aa16322605281 (diff) |
Bug 773 - Device specific JOCL dynamic library look-up on Android - Part 1/2
Use DynamicLibraryBundleInfo w/ alternative native library names,
drop manual coding of loading and binding, i.e. JOCLJNILibLoader.
After trying opencl native libs (and failing), try GL libs ..
We use a manual impl. to CL's 'clGetExtensionFunctionAddress' similar to JOAL, JOGL ...
Diffstat (limited to 'resources/clImplCustomCode.java')
-rw-r--r-- | resources/clImplCustomCode.java | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/resources/clImplCustomCode.java b/resources/clImplCustomCode.java index 1826da86..bee53425 100644 --- a/resources/clImplCustomCode.java +++ b/resources/clImplCustomCode.java @@ -1,6 +1,53 @@ - protected final CLProcAddressTable addressTable; + static final DynamicLibraryBundle dynamicLookupHelper; + protected static final CLProcAddressTable addressTable; - public CLAbstractImpl(CLProcAddressTable addressTable) { - this.addressTable = addressTable; + static { + addressTable = new CLProcAddressTable(); + if(null==addressTable) { + throw new RuntimeException("Couldn't instantiate ALProcAddressTable"); + } + + dynamicLookupHelper = AccessController.doPrivileged(new PrivilegedAction<DynamicLibraryBundle>() { + public DynamicLibraryBundle run() { + final DynamicLibraryBundle bundle = new DynamicLibraryBundle(new CLDynamicLibraryBundleInfo()); + if(null==bundle) { + throw new RuntimeException("Null CLDynamicLookupHelper"); + } + if(!bundle.isToolLibLoaded()) { + throw new RuntimeException("Couln't load native CL library"); + } + if(!bundle.isLibComplete()) { + throw new RuntimeException("Couln't load native CL/JNI glue library"); + } + addressTable.reset(bundle); + return bundle; + } } ); } + + public static CLProcAddressTable getCLProcAddressTable() { return addressTable; } + + static long clGetExtensionFunctionAddress(long clGetExtensionFunctionAddressHandle, java.lang.String procname) + { + if (clGetExtensionFunctionAddressHandle == 0) { + throw new RuntimeException("Passed null pointer for method \"clGetExtensionFunctionAddress\""); + } + return dispatch_clGetExtensionFunctionAddressStatic(procname, clGetExtensionFunctionAddressHandle); + } + + public CLAbstractImpl() { + } + + /** Entry point (through function pointer) to C language function: <br> <code> void* clGetExtensionFunctionAddress(const char * fname); </code> */ + long clGetExtensionFunctionAddress(String fname) { + + final long __addr_ = addressTable._addressof_clGetExtensionFunctionAddress; + if (__addr_ == 0) { + throw new UnsupportedOperationException("Method \"clGetExtensionFunctionAddress\" not available"); + } + return dispatch_clGetExtensionFunctionAddressStatic(fname, __addr_); + } + + /** Entry point (through function pointer) to C language function: <br> <code> void* clGetExtensionFunctionAddress(const char * fname); </code> */ + private static native long dispatch_clGetExtensionFunctionAddressStatic(String fname, long procAddress); + |