JOCL v2.6.0-rc-20250722
JOCL, OpenCL® API Binding for Java™ (public API).
CLDynamicLibraryBundleInfo.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opencl.llb.impl;
30
31import com.jogamp.common.jvm.JNILibLoaderBase;
32import com.jogamp.common.os.DynamicLibraryBundle;
33import com.jogamp.common.os.DynamicLibraryBundleInfo;
34import com.jogamp.common.os.Platform;
35import com.jogamp.common.util.RunnableExecutor;
36import com.jogamp.common.util.cache.TempJarCache;
37
38import java.security.AccessController;
39import java.security.PrivilegedAction;
40import java.util.*;
41
42import jogamp.common.os.PlatformPropsImpl;
43
44public final class CLDynamicLibraryBundleInfo implements DynamicLibraryBundleInfo {
45 private static final boolean isAndroid;
46 private static final List<String> glueLibNames;
47
48 static {
49 AccessController.doPrivileged(new PrivilegedAction<Object>() {
50 @Override
51 public Object run() {
52 Platform.initSingleton();
53
54 if( TempJarCache.isInitialized(true) ) {
55 // only: jocl.jar -> jocl-natives-<os.and.arch>.jar
56 JNILibLoaderBase.addNativeJarLibs(new Class<?>[] { jogamp.opencl.Debug.class }, null );
57 }
58 return null;
59 }
60 });
61 isAndroid = Platform.OSType.ANDROID == PlatformPropsImpl.OS_TYPE;
62
63 glueLibNames = new ArrayList<String>();
64 glueLibNames.add("jocl");
65 }
66
68 }
69
70 /**
71 * <p>
72 * Returns <code>true</code>,
73 * since we might load the library and allow symbol access to subsequent libs.
74 * </p>
75 */
76 @Override
77 public final boolean shallLinkGlobal() { return true; }
78
79 /**
80 * {@inheritDoc}
81 * Returns <code>true</code> on <code>Android</code>,
82 * and <code>false</code> otherwise.
83 */
84 @Override
85 public final boolean shallLookupGlobal() {
86 if ( isAndroid ) {
87 // Android requires global symbol lookup
88 return true;
89 }
90 // default behavior for other platforms
91 return false;
92 }
93
94 @Override
95 public final List<String> getGlueLibNames() {
96 return glueLibNames;
97 }
98
99 @Override
100 public final boolean searchToolLibInSystemPath() {
101 return true;
102 }
103
104 @Override
105 public final boolean searchToolLibSystemPathFirst() {
106 return true;
107 }
108
109 @Override
110 public final List<List<String>> getToolLibNames() {
111 final List<List<String>> libNamesList = new ArrayList<List<String>>();
112
113 final List<String> libCL = new ArrayList<String>();
114 {
115 // this is the default OpenCL lib name, according to the spec
116 libCL.add("libOpenCL.so.1"); // unix
117 libCL.add("OpenCL"); // windows, OSX
118
119 if( isAndroid ) {
120 libCL.add("libPVROCL.so");
121 libCL.add("/system/vendor/lib/libPVROCL.so");
122 } else {
123 // try this one as well, if spec fails
124 libCL.add("libGL.so.1");
125 }
126
127 // ES2: This is the default lib name, according to the spec
128 libCL.add("libGLESv2.so.2");
129
130 // ES2: Try these as well, if spec fails
131 libCL.add("libGLESv2.so");
132 libCL.add("GLESv2");
133
134 }
135 libNamesList.add(libCL);
136
137 return libNamesList;
138 }
139 @Override
140 public List<String> getSymbolForToolLibPath() { return Arrays.asList("clCreateContext"); }
141
142 @Override
143 public final List<String> getToolGetProcAddressFuncNameList() {
144 final List<String> res = new ArrayList<String>();
145 res.add("clGetExtensionFunctionAddress");
146 return res;
147 }
148
149 private static String Impl_str = "Impl";
150 private static int Impl_len = Impl_str.length();
151
152 @Override
153 public final long toolGetProcAddress(final long toolGetProcAddressHandle, String funcName) {
154 //FIXME workaround to fix a gluegen issue
155 if( funcName.endsWith(Impl_str) ) {
156 funcName = funcName.substring(0, funcName.length() - Impl_len);
157 }
158 if( funcName.endsWith("KHR") || funcName.endsWith("EXT") ) {
159 return CLImpl11.clGetExtensionFunctionAddress(toolGetProcAddressHandle, funcName);
160 }
161 return 0; // on libs ..
162 }
163
164 @Override
165 public final boolean useToolGetProcAdressFirst(final String funcName) {
166 return true;
167 }
168
169 @Override
170 public final RunnableExecutor getLibLoaderExecutor() {
171 return DynamicLibraryBundle.getDefaultRunnableExecutor();
172 }
173}
174
175
final long toolGetProcAddress(final long toolGetProcAddressHandle, String funcName)
final boolean shallLookupGlobal()
Returns true on Android, and false otherwise.
Java bindings to OpenCL, the Open Computing Language (generated).
Definition: CLImpl11.java:32