Clean-up
This commit is contained in:
parent
0b89143608
commit
b53c59b989
|
@ -455,7 +455,8 @@
|
|||
<!-- Compiles the Java source code -->
|
||||
<target name="compile+NoGen" description="Compiles the java source code" depends="-initialize">
|
||||
<javac debug="yes" destdir="${lwjgl.target.gen.classes}" nativeHeaderDir="${lwjgl.target.gen.headers}" source="1.8" target="1.8" classpath="${lwjgl.lib}/jinput.jar:${lwjgl.lib}/AppleJavaExtensions.jar:${lwjgl.lib}/asm-debug-all.jar" taskname="core">
|
||||
<!--<compilerarg value="-Xlint:unchecked"/>-->
|
||||
<compilerarg value="-Xlint:deprecation"/>
|
||||
<compilerarg value="-Xlint:unchecked"/>
|
||||
<src path="${lwjgl.src.java}"/>
|
||||
<src path="${lwjgl.target.gen.java}"/>
|
||||
<exclude name="org/lwjgl/util/generator/**"/>
|
||||
|
|
|
@ -21,9 +21,16 @@
|
|||
<target name="generate-all" depends="-generate-common" description="Generates java and native source">
|
||||
<parallel>
|
||||
<antcall target="generate-openal"/>
|
||||
<antcall target="generate-opengl"/>
|
||||
<antcall target="generate-opengles"/>
|
||||
<antcall target="generate-opencl"/>
|
||||
|
||||
<sequential>
|
||||
<antcall target="-compile-opencl-helpers"/>
|
||||
|
||||
<parallel>
|
||||
<antcall target="generate-opengl"/>
|
||||
<antcall target="generate-opencl"/>
|
||||
</parallel>
|
||||
</sequential>
|
||||
</parallel>
|
||||
</target>
|
||||
|
||||
|
@ -34,7 +41,7 @@
|
|||
**************************************************************************** -->
|
||||
|
||||
<!-- Generate OpenAL -->
|
||||
<target name="generate-openal" depends="-generate-common" description="Generates java and native source for AL">
|
||||
<target name="generate-openal" description="Generates java and native source for AL">
|
||||
<mkdir dir="${lwjgl.target.gen.native}/openal"/>
|
||||
|
||||
<javac debug="yes" srcdir="${lwjgl.src.java}" destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" includes="org/lwjgl/util/generator/**.java" taskname="generator">
|
||||
|
@ -53,8 +60,8 @@
|
|||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-Agenpath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenJavaPath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenNativePath=${lwjgl.target.gen.native}/openal"/>
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.openal.ALTypeMap"/>
|
||||
<compilerarg value="${javac.args.debug}"/>
|
||||
<src>
|
||||
|
@ -72,7 +79,7 @@
|
|||
**************************************************************************** -->
|
||||
|
||||
<!-- Generate OpenGL -->
|
||||
<target name="generate-opengl" depends="-generate-common, -compile-opencl-helpers" description="Generates java and native source for GL">
|
||||
<target name="generate-opengl" description="Generates java and native source for GL">
|
||||
<mkdir dir="${lwjgl.target.gen.native}/opengl"/>
|
||||
|
||||
<javac debug="yes" srcdir="${lwjgl.src.java}" destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" includes="org/lwjgl/util/generator/**.java" taskname="generator">
|
||||
|
@ -88,65 +95,71 @@
|
|||
<include name="org/lwjgl/opengl/KHRDebugCallback.java"/>
|
||||
</javac>
|
||||
|
||||
<javac destdir="${lwjgl.target.gen.native}/opengl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processorGL">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
|
||||
<compilerarg value="-processorpath"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-Agenpath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="${javac.args.debug}"/>
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.opengl.GLTypeMap"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<parallel>
|
||||
<javac destdir="${lwjgl.target.gen.native}/opengl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processorGL">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
|
||||
<compilerarg value="-processorpath"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenJavaPath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenNativePath=${lwjgl.target.gen.native}/opengl"/>
|
||||
<compilerarg value="${javac.args.debug}"/>
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.opengl.GLTypeMap"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
|
||||
<!-- Generate OpenGL references -->
|
||||
<javac destdir="${lwjgl.target.gen.native}/opengl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opengl.GLReferencesGeneratorProcessor"/>
|
||||
<compilerarg value="-processorpath"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<!-- Generate OpenGL references -->
|
||||
<javac destdir="${lwjgl.target.gen.native}/opengl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opengl.GLReferencesGeneratorProcessor"/>
|
||||
<compilerarg value="-processorpath"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenJavaPath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenNativePath=${lwjgl.target.gen.native}/opengl"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
|
||||
<!-- Generate OpenGL context capabilities -->
|
||||
<javac destdir="${lwjgl.target.gen.native}/opengl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opengl.GLGeneratorProcessor"/>
|
||||
<compilerarg value="-processorpath"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="${javac.args.debug}"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<!-- Generate OpenGL context capabilities -->
|
||||
<javac destdir="${lwjgl.target.gen.native}/opengl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opengl.GLGeneratorProcessor"/>
|
||||
<compilerarg value="-processorpath"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenJavaPath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenNativePath=${lwjgl.target.gen.native}/opengl"/>
|
||||
<compilerarg value="${javac.args.debug}"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
</parallel>
|
||||
</target>
|
||||
|
||||
<!-- ********************************************************************************
|
||||
|
@ -156,7 +169,7 @@
|
|||
**************************************************************************** -->
|
||||
|
||||
<!-- Generate OpenGL ES -->
|
||||
<target name="generate-opengles" depends="-generate-common" description="Generates java and native source for GL ES">
|
||||
<target name="generate-opengles" description="Generates java and native source for GL ES">
|
||||
<mkdir dir="${lwjgl.target.gen.native}/opengles"/>
|
||||
|
||||
<javac debug="yes" srcdir="${lwjgl.src.java}" destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" includes="org/lwjgl/util/generator/**.java" taskname="generator">
|
||||
|
@ -180,8 +193,8 @@
|
|||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-Agenpath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenJavaPath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenNativePath=${lwjgl.target.gen.native}/opengles"/>
|
||||
<compilerarg value="${javac.args.debug}"/>
|
||||
<!--<compilerarg value="-Acontextspecific"/>-->
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.opengl.GLESTypeMap"/>
|
||||
|
@ -203,6 +216,8 @@
|
|||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenJavaPath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenNativePath=${lwjgl.target.gen.native}/opengles"/>
|
||||
<compilerarg value="${javac.args.debug}"/>
|
||||
<!--<compilerarg value="-Acontextspecific"/>-->
|
||||
<src>
|
||||
|
@ -219,7 +234,7 @@
|
|||
*********************************************************************************
|
||||
**************************************************************************** -->
|
||||
|
||||
<target name="-compile-opencl-helpers" depends="-generate-common" description="Compiles java helpers for CL">
|
||||
<target name="-compile-opencl-helpers" description="Compiles java helpers for CL">
|
||||
<!-- Compile helper classes used by the templates -->
|
||||
<javac debug="yes" srcdir="${lwjgl.src.java}" destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" taskname="generator">
|
||||
<include name="org/lwjgl/opencl/CLPlatform.java"/>
|
||||
|
@ -233,7 +248,7 @@
|
|||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="generate-opencl" depends="-generate-common, -compile-opencl-helpers" description="Generates java and native source for CL">
|
||||
<target name="generate-opencl" description="Generates java and native source for CL">
|
||||
<mkdir dir="${lwjgl.target.gen.native}/opencl"/>
|
||||
|
||||
<javac debug="yes" srcdir="${lwjgl.src.java}" destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" includes="org/lwjgl/util/generator/**.java" taskname="generator">
|
||||
|
@ -251,8 +266,8 @@
|
|||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-Agenpath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenJavaPath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenNativePath=${lwjgl.target.gen.native}/opencl"/>
|
||||
<compilerarg value="${javac.args.debug}"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.opencl.CLTypeMap"/>
|
||||
|
@ -274,6 +289,8 @@
|
|||
<compilerarg path="${lwjgl.target.gen.classes}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenJavaPath=${lwjgl.target.gen.java}"/>
|
||||
<compilerarg value="-AgenNativePath=${lwjgl.target.gen.native}/opencl"/>
|
||||
<compilerarg value="${javac.args.debug}"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<src>
|
||||
|
|
|
@ -36,10 +36,6 @@ import java.lang.reflect.Field;
|
|||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
@ -426,19 +422,15 @@ public class LWJGLUtil {
|
|||
}
|
||||
|
||||
static void execPrivileged(String... cmd_array) throws Exception {
|
||||
try {
|
||||
Process process = AccessController.doPrivileged((PrivilegedExceptionAction<Process>) () -> Runtime.getRuntime().exec(cmd_array));
|
||||
// Close unused streams to make sure the child process won't hang
|
||||
process.getInputStream().close();
|
||||
process.getOutputStream().close();
|
||||
process.getErrorStream().close();
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (Exception)e.getCause();
|
||||
}
|
||||
Process process = Runtime.getRuntime().exec(cmd_array);
|
||||
// Close unused streams to make sure the child process won't hang
|
||||
process.getInputStream().close();
|
||||
process.getOutputStream().close();
|
||||
process.getErrorStream().close();
|
||||
}
|
||||
|
||||
private static String getPrivilegedProperty(String property_name) {
|
||||
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property_name));
|
||||
return System.getProperty(property_name);
|
||||
}
|
||||
|
||||
/** Gets a boolean property as a privileged action. */
|
||||
|
@ -466,11 +458,9 @@ public class LWJGLUtil {
|
|||
* @return the property value
|
||||
*/
|
||||
public static Integer getPrivilegedInteger(final String property_name) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<Integer>() {
|
||||
public Integer run() {
|
||||
return Integer.getInteger(property_name);
|
||||
}
|
||||
});
|
||||
String s = getPrivilegedProperty(property_name);
|
||||
if (s == null) return null;
|
||||
return Integer.decode(s);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -481,12 +471,10 @@ public class LWJGLUtil {
|
|||
*
|
||||
* @return the property value
|
||||
*/
|
||||
public static Integer getPrivilegedInteger(final String property_name, final int default_val) {
|
||||
return AccessController.doPrivileged(new PrivilegedAction<Integer>() {
|
||||
public Integer run() {
|
||||
return Integer.getInteger(property_name, default_val);
|
||||
}
|
||||
});
|
||||
public static int getPrivilegedInteger(final String property_name, final int default_val) {
|
||||
String s = getPrivilegedProperty(property_name);
|
||||
if (s == null) return default_val;
|
||||
return Integer.decode(s);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -511,14 +499,12 @@ public class LWJGLUtil {
|
|||
while (c != null) {
|
||||
final Class<?> clazz = c;
|
||||
try {
|
||||
return AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> {
|
||||
Method findLibrary = clazz.getDeclaredMethod("findLibrary", String.class);
|
||||
findLibrary.setAccessible(true);
|
||||
String path = (String)findLibrary.invoke(classloader, libname);
|
||||
return path;
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
logger().log(() -> "Failed to locate findLibrary method on " + clazz, e.getCause());
|
||||
Method findLibrary = clazz.getDeclaredMethod("findLibrary", String.class);
|
||||
findLibrary.setAccessible(true);
|
||||
String path = (String)findLibrary.invoke(classloader, libname);
|
||||
return path;
|
||||
} catch (Exception e) {
|
||||
logger().log(() -> "Failed to locate findLibrary method on " + clazz, e);
|
||||
c = c.getSuperclass();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,6 @@
|
|||
*/
|
||||
package org.lwjgl;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.lang.UnsatisfiedLinkError;
|
||||
import java.lang.annotation.Native;
|
||||
|
||||
|
@ -52,17 +49,12 @@ final class LinuxSysImplementation extends J2SESysImplementation {
|
|||
java.awt.Toolkit.getDefaultToolkit();
|
||||
|
||||
// manually load libjawt.so into vm, needed since Java 7
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
try {
|
||||
System.loadLibrary("jawt");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
// catch and ignore an already loaded in another classloader
|
||||
// exception, as vm already has it loaded
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
try {
|
||||
System.loadLibrary("jawt");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
// catch and ignore an already loaded in another classloader
|
||||
// exception, as vm already has it loaded
|
||||
}
|
||||
}
|
||||
|
||||
public int getRequiredJNIVersion() {
|
||||
|
|
|
@ -32,10 +32,6 @@
|
|||
package org.lwjgl;
|
||||
|
||||
import com.apple.eio.FileManager;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.lang.UnsatisfiedLinkError;
|
||||
import java.lang.annotation.Native;
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,9 +35,6 @@ import java.io.File;
|
|||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
|
@ -63,17 +60,12 @@ public final class Sys {
|
|||
private static final boolean is64Bit;
|
||||
|
||||
private static void doLoadLibrary(final String lib_name) {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
String library_path = System.getProperty("org.lwjgl.librarypath");
|
||||
if (library_path != null) {
|
||||
System.load(library_path + File.separator + LWJGLUtil.mapLibraryName(lib_name));
|
||||
} else {
|
||||
System.loadLibrary(lib_name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
String library_path = System.getProperty("org.lwjgl.librarypath");
|
||||
if (library_path != null) {
|
||||
System.load(library_path + File.separator + LWJGLUtil.mapLibraryName(lib_name));
|
||||
} else {
|
||||
System.loadLibrary(lib_name);
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadLibrary(final String lib_name) {
|
||||
|
@ -234,18 +226,10 @@ public final class Sys {
|
|||
try {
|
||||
// Lookup the javax.jnlp.BasicService object
|
||||
final Class<?> serviceManagerClass = Class.forName("javax.jnlp.ServiceManager");
|
||||
Method lookupMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
|
||||
public Method run() throws Exception {
|
||||
return serviceManagerClass.getMethod("lookup", String.class);
|
||||
}
|
||||
});
|
||||
Method lookupMethod = serviceManagerClass.getMethod("lookup", String.class);
|
||||
Object basicService = lookupMethod.invoke(serviceManagerClass, new Object[] {"javax.jnlp.BasicService"});
|
||||
final Class<?> basicServiceClass = Class.forName("javax.jnlp.BasicService");
|
||||
Method showDocumentMethod = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
|
||||
public Method run() throws Exception {
|
||||
return basicServiceClass.getMethod("showDocument", URL.class);
|
||||
}
|
||||
});
|
||||
Method showDocumentMethod = basicServiceClass.getMethod("showDocument", URL.class);
|
||||
try {
|
||||
Boolean ret = (Boolean)showDocumentMethod.invoke(basicService, new URL(url));
|
||||
return ret;
|
||||
|
|
|
@ -32,9 +32,6 @@
|
|||
package org.lwjgl;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.AccessController;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
@ -76,18 +73,14 @@ final class WindowsSysImplementation extends DefaultSysImplementation {
|
|||
* public
|
||||
*/
|
||||
try {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<Long>() {
|
||||
public Long run() throws Exception {
|
||||
Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation");
|
||||
getImplementation_method.setAccessible(true);
|
||||
Object display_impl = getImplementation_method.invoke(null);
|
||||
Class<?> WindowsDisplay_class = Class.forName("org.lwjgl.opengl.WindowsDisplay");
|
||||
Method getHwnd_method = WindowsDisplay_class.getDeclaredMethod("getHwnd");
|
||||
getHwnd_method.setAccessible(true);
|
||||
return (Long)getHwnd_method.invoke(display_impl);
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation");
|
||||
getImplementation_method.setAccessible(true);
|
||||
Object display_impl = getImplementation_method.invoke(null);
|
||||
Class<?> WindowsDisplay_class = Class.forName("org.lwjgl.opengl.WindowsDisplay");
|
||||
Method getHwnd_method = WindowsDisplay_class.getDeclaredMethod("getHwnd");
|
||||
getHwnd_method.setAccessible(true);
|
||||
return (Long)getHwnd_method.invoke(display_impl);
|
||||
} catch (Exception e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ package org.lwjgl.input;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
|
@ -36,9 +36,6 @@ import org.lwjgl.opengl.Display;
|
|||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
|
||||
/**
|
||||
* This class contains utilities for accessing the org.lwjgl.opengl
|
||||
|
@ -49,14 +46,10 @@ final class OpenGLPackageAccess {
|
|||
|
||||
static {
|
||||
try {
|
||||
global_lock = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws Exception {
|
||||
Field lock_field = Class.forName("org.lwjgl.opengl.GlobalLock").getDeclaredField("lock");
|
||||
lock_field.setAccessible(true);
|
||||
return lock_field.get(null);
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
Field lock_field = Class.forName("org.lwjgl.opengl.GlobalLock").getDeclaredField("lock");
|
||||
lock_field.setAccessible(true);
|
||||
global_lock = lock_field.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
@ -66,14 +59,10 @@ final class OpenGLPackageAccess {
|
|||
* public
|
||||
*/
|
||||
try {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<InputImplementation>() {
|
||||
public InputImplementation run() throws Exception {
|
||||
Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation");
|
||||
getImplementation_method.setAccessible(true);
|
||||
return (InputImplementation)getImplementation_method.invoke(null);
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
Method getImplementation_method = Display.class.getDeclaredMethod("getImplementation");
|
||||
getImplementation_method.setAccessible(true);
|
||||
return (InputImplementation)getImplementation_method.invoke(null);
|
||||
} catch (Exception e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,9 +34,6 @@ package org.lwjgl.opengl;
|
|||
import java.awt.Canvas;
|
||||
import java.awt.Component;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
@ -53,8 +50,6 @@ final class AWTSurfaceLock {
|
|||
|
||||
private final ByteBuffer lock_buffer;
|
||||
|
||||
private boolean firstLockSucceeded;
|
||||
|
||||
AWTSurfaceLock() {
|
||||
lock_buffer = createHandle();
|
||||
}
|
||||
|
@ -62,7 +57,7 @@ final class AWTSurfaceLock {
|
|||
private static native ByteBuffer createHandle();
|
||||
|
||||
public ByteBuffer lockAndGetHandle(Canvas component) throws LWJGLException {
|
||||
while (!privilegedLockAndInitHandle(component)) {
|
||||
while (!lockAndInitHandle(lock_buffer, component)) {
|
||||
LWJGLUtil.log("Could not get drawing surface info, retrying...");
|
||||
try {
|
||||
Thread.sleep(WAIT_DELAY_MILLIS);
|
||||
|
@ -74,28 +69,6 @@ final class AWTSurfaceLock {
|
|||
return lock_buffer;
|
||||
}
|
||||
|
||||
private boolean privilegedLockAndInitHandle(final Canvas component) throws LWJGLException {
|
||||
// Workaround for Sun JDK bug 4796548 which still exists in java for OS X
|
||||
// We need to elevate privileges because of an AWT bug. Please see
|
||||
// http://192.18.37.44/forums/index.php?topic=10572 for a discussion.
|
||||
// It is only needed on first call, so we avoid it on all subsequent calls
|
||||
// due to performance..
|
||||
|
||||
if (firstLockSucceeded)
|
||||
return lockAndInitHandle(lock_buffer, component);
|
||||
else
|
||||
try {
|
||||
firstLockSucceeded = AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {
|
||||
public Boolean run() throws LWJGLException {
|
||||
return lockAndInitHandle(lock_buffer, component);
|
||||
}
|
||||
});
|
||||
return firstLockSucceeded;
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (LWJGLException) e.getException();
|
||||
}
|
||||
}
|
||||
|
||||
private static native boolean lockAndInitHandle(ByteBuffer lock_buffer, Canvas component) throws LWJGLException;
|
||||
|
||||
void unlock() throws LWJGLException {
|
||||
|
|
|
@ -48,9 +48,6 @@ import java.awt.Robot;
|
|||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.IntBuffer;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
@ -87,12 +84,8 @@ final class AWTUtil {
|
|||
|
||||
public static Robot createRobot(final Component component) {
|
||||
try {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<Robot>() {
|
||||
public Robot run() throws Exception {
|
||||
return new Robot(component.getGraphicsConfiguration().getDevice());
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
return new Robot(component.getGraphicsConfiguration().getDevice());
|
||||
} catch (Exception e) {
|
||||
LWJGLUtil.log("Got exception while creating robot: " + e.getCause());
|
||||
return null;
|
||||
}
|
||||
|
@ -111,11 +104,7 @@ final class AWTUtil {
|
|||
try {
|
||||
final GraphicsConfiguration config = component.getGraphicsConfiguration();
|
||||
if (config != null) {
|
||||
PointerInfo pointer_info = AccessController.doPrivileged(new PrivilegedExceptionAction<PointerInfo>() {
|
||||
public PointerInfo run() throws Exception {
|
||||
return MouseInfo.getPointerInfo();
|
||||
}
|
||||
});
|
||||
PointerInfo pointer_info = MouseInfo.getPointerInfo();
|
||||
GraphicsDevice device = pointer_info.getDevice();
|
||||
if (device == config.getDevice()) {
|
||||
return pointer_info.getLocation();
|
||||
|
@ -123,7 +112,7 @@ final class AWTUtil {
|
|||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LWJGLUtil.log("Failed to query pointer location: " + e.getCause());
|
||||
LWJGLUtil.logger().log("Failed to query pointer location", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -57,8 +57,6 @@ import java.awt.event.ComponentEvent;
|
|||
import java.awt.event.ComponentListener;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.HashSet;
|
||||
|
@ -300,13 +298,15 @@ public final class Display {
|
|||
* A native context must exist, and it will be attached to the window.
|
||||
*/
|
||||
private static void createWindow() throws LWJGLException {
|
||||
if ( window_created ) {
|
||||
if (window_created) {
|
||||
return;
|
||||
}
|
||||
Canvas tmp_parent = isFullscreen() ? null : parent;
|
||||
if ( tmp_parent != null && !tmp_parent.isDisplayable() ) // Only a best effort check, since the parent can turn undisplayable hereafter
|
||||
if (tmp_parent != null && !tmp_parent.isDisplayable()) {
|
||||
// Only a best effort check, since the parent can turn undisplayable hereafter
|
||||
throw new LWJGLException("Parent.isDisplayable() must be true");
|
||||
if ( tmp_parent != null ) {
|
||||
}
|
||||
if (tmp_parent != null) {
|
||||
tmp_parent.addComponentListener(component_listener);
|
||||
}
|
||||
DisplayMode mode = getEffectiveMode();
|
||||
|
@ -360,7 +360,7 @@ public final class Display {
|
|||
}
|
||||
|
||||
private static void switchDisplayMode() throws LWJGLException {
|
||||
if ( !current_mode.isFullscreenCapable() ) {
|
||||
if (!current_mode.isFullscreenCapable()) {
|
||||
throw new IllegalStateException("Only modes acquired from getAvailableDisplayModes() can be used for fullscreen display");
|
||||
}
|
||||
display_impl.switchDisplayMode(current_mode);
|
||||
|
@ -696,17 +696,11 @@ public final class Display {
|
|||
}
|
||||
|
||||
private static void removeShutdownHook() {
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
Runtime.getRuntime().removeShutdownHook(shutdown_hook);
|
||||
return null;
|
||||
});
|
||||
Runtime.getRuntime().removeShutdownHook(shutdown_hook);
|
||||
}
|
||||
|
||||
private static void registerShutdownHook() {
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
Runtime.getRuntime().addShutdownHook(shutdown_hook);
|
||||
return null;
|
||||
});
|
||||
Runtime.getRuntime().addShutdownHook(shutdown_hook);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -794,13 +788,13 @@ public final class Display {
|
|||
*/
|
||||
public static void create(PixelFormat pixel_format, Drawable shared_drawable, ContextAttribs attribs) throws LWJGLException {
|
||||
synchronized ( GlobalLock.lock ) {
|
||||
if ( isCreated() )
|
||||
if (isCreated())
|
||||
throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time.");
|
||||
if ( pixel_format == null )
|
||||
if (pixel_format == null)
|
||||
throw new NullPointerException("pixel_format cannot be null");
|
||||
removeShutdownHook();
|
||||
registerShutdownHook();
|
||||
if ( isFullscreen() )
|
||||
if (isFullscreen())
|
||||
switchDisplayMode();
|
||||
|
||||
final DrawableGL drawable = new DrawableGL() {
|
||||
|
@ -1001,7 +995,7 @@ public final class Display {
|
|||
} catch (OpenGLException e) {
|
||||
LWJGLUtil.logger().log("OpenGL error during context creation", e);
|
||||
}
|
||||
setSwapInterval(swap_interval);
|
||||
drawable.setSwapInterval(Display.swap_interval);
|
||||
}
|
||||
|
||||
private static void initContext() {
|
||||
|
@ -1068,11 +1062,10 @@ public final class Display {
|
|||
* @param value The swap interval in frames, 0 to disable
|
||||
*/
|
||||
public static void setSwapInterval(int value) throws LWJGLException {
|
||||
if (value != swap_interval) {
|
||||
swap_interval = value;
|
||||
if (isCreated()) {
|
||||
drawable.setSwapInterval(value);
|
||||
}
|
||||
if (value == swap_interval) return;
|
||||
swap_interval = value;
|
||||
if (isCreated()) {
|
||||
drawable.setSwapInterval(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,9 +38,6 @@ import org.lwjgl.Sys;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.*;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
@ -178,11 +175,7 @@ public final class GLContext {
|
|||
* with a name dependent on the current platform
|
||||
*/
|
||||
static long getPlatformSpecificFunctionAddress(String function_prefix, String[] os_prefixes, String[] os_function_prefixes, String function) {
|
||||
String os_name = AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
return System.getProperty("os.name");
|
||||
}
|
||||
});
|
||||
String os_name = System.getProperty("os.name");
|
||||
for ( int i = 0; i < os_prefixes.length; i++ )
|
||||
if ( os_name.startsWith(os_prefixes[i]) ) {
|
||||
String platform_function_name = function.replaceFirst(function_prefix, os_function_prefixes[i]);
|
||||
|
@ -299,17 +292,12 @@ public final class GLContext {
|
|||
*/
|
||||
static void initNativeStubs(final Class<?> extension_class, Set supported_extensions, String ext_name) {
|
||||
resetNativeStubs(extension_class);
|
||||
if ( supported_extensions.contains(ext_name) ) {
|
||||
if (supported_extensions.contains(ext_name)) {
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws Exception {
|
||||
Method init_stubs_method = extension_class.getDeclaredMethod("initNativeStubs");
|
||||
init_stubs_method.invoke(null);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
Method init_stubs_method = extension_class.getDeclaredMethod("initNativeStubs");
|
||||
init_stubs_method.invoke(null);
|
||||
} catch (Exception e) {
|
||||
LWJGLUtil.log("Failed to initialize extension " + extension_class + " - exception: " + e);
|
||||
LWJGLUtil.logger().log(() -> "Failed to initialize extension " + extension_class + " - exception", e);
|
||||
supported_extensions.remove(ext_name);
|
||||
}
|
||||
}
|
||||
|
@ -412,4 +400,4 @@ public final class GLContext {
|
|||
Thread owner;
|
||||
ContextCapabilities capabilities;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,6 @@ import java.awt.GraphicsConfiguration;
|
|||
import java.awt.GraphicsDevice;
|
||||
import java.awt.Canvas;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
@ -50,11 +48,7 @@ import org.lwjgl.LWJGLUtil;
|
|||
final class LinuxCanvasImplementation implements AWTCanvasImplementation {
|
||||
static int getScreenFromDevice(final GraphicsDevice device) throws LWJGLException {
|
||||
try {
|
||||
Method getScreen_method = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
|
||||
public Method run() throws Exception {
|
||||
return device.getClass().getMethod("getScreen");
|
||||
}
|
||||
});
|
||||
Method getScreen_method = device.getClass().getMethod("getScreen");
|
||||
Integer screen = (Integer)getScreen_method.invoke(device);
|
||||
return screen;
|
||||
} catch (Exception e) {
|
||||
|
@ -64,11 +58,7 @@ final class LinuxCanvasImplementation implements AWTCanvasImplementation {
|
|||
|
||||
private static int getVisualIDFromConfiguration(final GraphicsConfiguration configuration) throws LWJGLException {
|
||||
try {
|
||||
Method getVisual_method = AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
|
||||
public Method run() throws Exception {
|
||||
return configuration.getClass().getMethod("getVisual");
|
||||
}
|
||||
});
|
||||
Method getVisual_method = configuration.getClass().getMethod("getVisual");
|
||||
Integer visual = (Integer)getVisual_method.invoke(configuration);
|
||||
return visual;
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -45,12 +45,18 @@ import java.awt.event.FocusEvent;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
@ -58,11 +64,6 @@ import org.lwjgl.MemoryUtil;
|
|||
import org.lwjgl.opengl.XRandR.Screen;
|
||||
import org.lwjgl.opengles.EGL;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
final class LinuxDisplay implements DisplayImplementation {
|
||||
/* X11 constants */
|
||||
public static final int CurrentTime = 0;
|
||||
|
@ -624,21 +625,14 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
|
||||
public void resetDisplayMode() {
|
||||
try (LinuxDisplay.AWTLock _lock = awtLock()) {
|
||||
if( current_displaymode_extension == XRANDR )
|
||||
{
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
XRandR.restoreConfiguration();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (current_displaymode_extension == XRANDR) {
|
||||
XRandR.restoreConfiguration();
|
||||
} else {
|
||||
switchDisplayMode(saved_mode);
|
||||
}
|
||||
if (isXF86VidModeSupported())
|
||||
if (isXF86VidModeSupported()) {
|
||||
doSetGamma(saved_gamma);
|
||||
}
|
||||
|
||||
Compiz.setLegacyFullscreenSupport(false);
|
||||
} catch (LWJGLException e) {
|
||||
|
@ -717,11 +711,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
throw new LWJGLException("No modes available");
|
||||
switch (current_displaymode_extension) {
|
||||
case XRANDR:
|
||||
saved_mode = AccessController.doPrivileged(new PrivilegedAction<DisplayMode>() {
|
||||
public DisplayMode run() {
|
||||
return XRandR.ScreentoDisplayMode(XRandR.getConfiguration());
|
||||
}
|
||||
});
|
||||
saved_mode = XRandR.ScreentoDisplayMode(XRandR.getConfiguration());
|
||||
break;
|
||||
case XF86VIDMODE:
|
||||
saved_mode = modes[0];
|
||||
|
@ -1073,17 +1063,9 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
if (current_window_mode == FULLSCREEN_NETWM) {
|
||||
nIconifyWindow(getDisplay(), getWindow(), getDefaultScreen());
|
||||
try {
|
||||
if( current_displaymode_extension == XRANDR )
|
||||
{
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
if (current_displaymode_extension == XRANDR) {
|
||||
XRandR.restoreConfiguration();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
switchDisplayModeOnTmpDisplay(saved_mode);
|
||||
}
|
||||
setGammaRampOnTmpDisplay(saved_gamma);
|
||||
|
@ -1414,164 +1396,172 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
static void init() {
|
||||
if ( LWJGLUtil.getPrivilegedBoolean("org.lwjgl.opengl.Window.nocompiz_lfs") )
|
||||
return;
|
||||
if (LWJGLUtil.getPrivilegedBoolean("org.lwjgl.opengl.Window.nocompiz_lfs")) return;
|
||||
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
try {
|
||||
// Check if Compiz is active
|
||||
if ( !isProcessActive("compiz") )
|
||||
return null;
|
||||
try {
|
||||
// Check if Compiz is active
|
||||
if (!isProcessActive("compiz")) return;
|
||||
|
||||
provider = null;
|
||||
provider = null;
|
||||
|
||||
String providerName = null;
|
||||
String providerName = null;
|
||||
|
||||
// Check if Dbus is available
|
||||
if ( isProcessActive("dbus-daemon") ) {
|
||||
providerName = "Dbus";
|
||||
provider = new Provider() {
|
||||
// Check if Dbus is available
|
||||
if (isProcessActive("dbus-daemon")) {
|
||||
providerName = "Dbus";
|
||||
provider = new Provider() {
|
||||
private static final String KEY = "/org/freedesktop/compiz/workarounds/allscreens/legacy_fullscreen";
|
||||
|
||||
private static final String KEY = "/org/freedesktop/compiz/workarounds/allscreens/legacy_fullscreen";
|
||||
public boolean hasLegacyFullscreenSupport() throws LWJGLException {
|
||||
final List<String> output = Compiz.runLines(
|
||||
"dbus-send", "--print-reply", "--type=method_call", "--dest=org.freedesktop.compiz", KEY, "org.freedesktop.compiz.get"
|
||||
);
|
||||
|
||||
public boolean hasLegacyFullscreenSupport() throws LWJGLException {
|
||||
final List output = Compiz.run(
|
||||
"dbus-send", "--print-reply", "--type=method_call", "--dest=org.freedesktop.compiz", KEY, "org.freedesktop.compiz.get"
|
||||
);
|
||||
if (output == null || output.size() < 2) {
|
||||
throw new LWJGLException("Invalid Dbus reply.");
|
||||
}
|
||||
|
||||
if ( output == null || output.size() < 2 )
|
||||
throw new LWJGLException("Invalid Dbus reply.");
|
||||
String line = (String)output.get(0);
|
||||
|
||||
String line = (String)output.get(0);
|
||||
if (!line.startsWith("method return")) {
|
||||
throw new LWJGLException("Invalid Dbus reply.");
|
||||
}
|
||||
|
||||
if ( !line.startsWith("method return") )
|
||||
throw new LWJGLException("Invalid Dbus reply.");
|
||||
line = ((String)output.get(1)).trim(); // value
|
||||
if (!line.startsWith("boolean") || line.length() < 12) {
|
||||
throw new LWJGLException("Invalid Dbus reply.");
|
||||
}
|
||||
|
||||
line = ((String)output.get(1)).trim(); // value
|
||||
if ( !line.startsWith("boolean") || line.length() < 12)
|
||||
throw new LWJGLException("Invalid Dbus reply.");
|
||||
return "true".equalsIgnoreCase(line.substring("boolean".length() + 1));
|
||||
}
|
||||
|
||||
return "true".equalsIgnoreCase(line.substring("boolean".length() + 1));
|
||||
}
|
||||
|
||||
public void setLegacyFullscreenSupport(final boolean state) throws LWJGLException {
|
||||
if ( Compiz.run(
|
||||
"dbus-send", "--type=method_call", "--dest=org.freedesktop.compiz", KEY, "org.freedesktop.compiz.set", "boolean:" + Boolean.toString(state)
|
||||
) == null )
|
||||
throw new LWJGLException("Failed to apply Compiz LFS workaround.");
|
||||
}
|
||||
};
|
||||
} else {
|
||||
try {
|
||||
// Check if Gconf is available
|
||||
Runtime.getRuntime().exec("gconftool");
|
||||
|
||||
providerName = "gconftool";
|
||||
provider = new Provider() {
|
||||
|
||||
private static final String KEY = "/apps/compiz/plugins/workarounds/allscreens/options/legacy_fullscreen";
|
||||
|
||||
public boolean hasLegacyFullscreenSupport() throws LWJGLException {
|
||||
final List output = Compiz.run(new String[] {
|
||||
"gconftool", "-g", KEY
|
||||
});
|
||||
|
||||
if ( output == null || output.size() == 0 )
|
||||
throw new LWJGLException("Invalid gconftool reply.");
|
||||
|
||||
return Boolean.parseBoolean(((String)output.get(0)).trim());
|
||||
}
|
||||
|
||||
public void setLegacyFullscreenSupport(final boolean state) throws LWJGLException {
|
||||
if ( Compiz.run(new String[] {
|
||||
"gconftool", "-s", KEY, "-s", Boolean.toString(state), "-t", "bool"
|
||||
}) == null )
|
||||
throw new LWJGLException("Failed to apply Compiz LFS workaround.");
|
||||
|
||||
if ( state ) {
|
||||
try {
|
||||
// gconftool will not apply the workaround immediately, sleep a bit
|
||||
// to make sure it will be ok when we create the window.
|
||||
Thread.sleep(200); // 100 is too low, 150 works, set to 200 to be safe.
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
public void setLegacyFullscreenSupport(final boolean state) throws LWJGLException {
|
||||
if (Compiz.run("dbus-send", "--type=method_call", "--dest=org.freedesktop.compiz", KEY, "org.freedesktop.compiz.set", "boolean:" + state) != 0) {
|
||||
throw new LWJGLException("Failed to apply Compiz LFS workaround.");
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
try {
|
||||
// Check if Gconf is available
|
||||
Runtime.getRuntime().exec("gconftool");
|
||||
|
||||
if ( provider != null && !provider.hasLegacyFullscreenSupport() ) { // No need to do anything if LFS is already enabled.
|
||||
applyFix = true;
|
||||
LWJGLUtil.log("Using " + providerName + " to apply Compiz LFS workaround.");
|
||||
}
|
||||
} catch (LWJGLException e) {
|
||||
providerName = "gconftool";
|
||||
provider = new Provider() {
|
||||
private static final String KEY = "/apps/compiz/plugins/workarounds/allscreens/options/legacy_fullscreen";
|
||||
|
||||
public boolean hasLegacyFullscreenSupport() throws LWJGLException {
|
||||
final List<String> output = Compiz.runLines("gconftool", "-g", KEY);
|
||||
|
||||
if (output == null || output.size() == 0) {
|
||||
throw new LWJGLException("Invalid gconftool reply.");
|
||||
}
|
||||
|
||||
return Boolean.parseBoolean(((String)output.get(0)).trim());
|
||||
}
|
||||
|
||||
public void setLegacyFullscreenSupport(final boolean state) throws LWJGLException {
|
||||
if (Compiz.run("gconftool", "-s", KEY, "-s", Boolean.toString(state), "-t", "bool") != 0) {
|
||||
throw new LWJGLException("Failed to apply Compiz LFS workaround.");
|
||||
}
|
||||
|
||||
if (state) {
|
||||
try {
|
||||
// gconftool will not apply the workaround immediately, sleep a bit
|
||||
// to make sure it will be ok when we create the window.
|
||||
Thread.sleep(200); // 100 is too low, 150 works, set to 200 to be safe.
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
} finally {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (provider != null && !provider.hasLegacyFullscreenSupport()) {
|
||||
// No need to do anything if LFS is already enabled.
|
||||
applyFix = true;
|
||||
String providerName1 = providerName;
|
||||
LWJGLUtil.logger().log(() -> "Using " + providerName1 + " to apply Compiz LFS workaround.");
|
||||
}
|
||||
} catch (LWJGLException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
static void setLegacyFullscreenSupport(final boolean enabled) {
|
||||
if ( !applyFix )
|
||||
if (!applyFix)
|
||||
return;
|
||||
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
try {
|
||||
provider.setLegacyFullscreenSupport(enabled);
|
||||
} catch (LWJGLException e) {
|
||||
LWJGLUtil.log("Failed to change Compiz Legacy Fullscreen Support. Reason: " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
try {
|
||||
provider.setLegacyFullscreenSupport(enabled);
|
||||
} catch (LWJGLException e) {
|
||||
LWJGLUtil.logger().log(() -> "Failed to change Compiz Legacy Fullscreen Support. Reason: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> run(final String... command) throws LWJGLException {
|
||||
final List<String> output = new ArrayList<String>();
|
||||
private static List<String> runLines(final String... command) throws LWJGLException {
|
||||
List<String> output = new ArrayList<>();
|
||||
|
||||
try {
|
||||
final Process p = Runtime.getRuntime().exec(command);
|
||||
try {
|
||||
final int exitValue = p.waitFor();
|
||||
if ( exitValue != 0 )
|
||||
return null;
|
||||
} catch (InterruptedException e) {
|
||||
throw new LWJGLException("Process interrupted.", e);
|
||||
}
|
||||
|
||||
final BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
|
||||
String line;
|
||||
while ( (line = br.readLine()) != null )
|
||||
output.add(line);
|
||||
|
||||
br.close();
|
||||
} catch (final IOException e) {
|
||||
throw new LWJGLException("Process failed.", e);
|
||||
}
|
||||
if (run(output::add, command) != 0) return null;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private static boolean isProcessActive(final String processName) throws LWJGLException {
|
||||
final List<String> output = run(new String[] { "ps", "-C", processName });
|
||||
if ( output == null )
|
||||
return false;
|
||||
private static int run(final String... command) throws LWJGLException {
|
||||
try {
|
||||
final Process p = Runtime.getRuntime().exec(command);
|
||||
|
||||
for ( final String line : output ) {
|
||||
if ( line.contains(processName) )
|
||||
return true;
|
||||
try {
|
||||
return p.waitFor();
|
||||
} catch (InterruptedException e) {
|
||||
throw new LWJGLException("Process interrupted.", e);
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
throw new LWJGLException("Process failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static int run(Consumer<String> lineConsumer, final String... command) throws LWJGLException {
|
||||
try {
|
||||
final Process p = Runtime.getRuntime().exec(command);
|
||||
|
||||
final BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
lineConsumer.accept(line);
|
||||
}
|
||||
|
||||
br.close();
|
||||
|
||||
try {
|
||||
return p.waitFor();
|
||||
} catch (InterruptedException e) {
|
||||
throw new LWJGLException("Process interrupted.", e);
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
throw new LWJGLException("Process failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isProcessActive(final String processName) throws LWJGLException {
|
||||
class LineFindingConsumer implements Consumer<String> {
|
||||
boolean found = false;
|
||||
|
||||
@Override
|
||||
public void accept(String line) {
|
||||
if (found) return;
|
||||
found = line.contains(processName);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
LineFindingConsumer consumer = new LineFindingConsumer();
|
||||
run(consumer, "ps", "-C", processName);
|
||||
return consumer.found;
|
||||
}
|
||||
|
||||
private interface Provider {
|
||||
|
|
|
@ -46,9 +46,6 @@ import java.awt.Robot;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -182,22 +179,16 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
public void doHandleQuit() {
|
||||
synchronized (this) {
|
||||
close_requested = true;
|
||||
}
|
||||
close_requested = true;
|
||||
}
|
||||
|
||||
public void mouseInsideWindow(boolean inside) {
|
||||
synchronized (this) {
|
||||
mouseInsideWindow = inside;
|
||||
}
|
||||
mouseInsideWindow = inside;
|
||||
updateNativeCursor = true;
|
||||
}
|
||||
|
||||
public void setScaleFactor(float scale) {
|
||||
synchronized (this) {
|
||||
scaleFactor = scale;
|
||||
}
|
||||
scaleFactor = scale;
|
||||
}
|
||||
|
||||
public native void nDestroyCALayer(ByteBuffer peer_info_handle);
|
||||
|
@ -287,11 +278,8 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
public boolean isCloseRequested() {
|
||||
boolean result;
|
||||
synchronized (this) {
|
||||
result = close_requested;
|
||||
close_requested = false;
|
||||
}
|
||||
boolean result = close_requested;
|
||||
close_requested = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ import java.awt.GraphicsDevice;
|
|||
import java.awt.Toolkit;
|
||||
import java.awt.Canvas;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.AccessController;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
@ -51,19 +50,13 @@ final class WindowsCanvasImplementation implements AWTCanvasImplementation {
|
|||
static {
|
||||
// Make sure the awt stuff is properly initialised (the jawt library in particular)
|
||||
Toolkit.getDefaultToolkit();
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
try {
|
||||
System.loadLibrary("jawt");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
/* It is probably already loaded, potentially by a different ClassLoader
|
||||
* so just log the exception and continue
|
||||
*/
|
||||
LWJGLUtil.log("Failed to load jawt: " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
try {
|
||||
System.loadLibrary("jawt");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
// It is probably already loaded, potentially by a different ClassLoader
|
||||
// so just log the exception and continue
|
||||
LWJGLUtil.logger().log("Failed to load jawt", e);
|
||||
}
|
||||
}
|
||||
|
||||
public PeerInfo createPeerInfo(Canvas component, PixelFormat pixel_format, ContextAttribs attribs) throws LWJGLException {
|
||||
|
|
|
@ -37,9 +37,6 @@ import org.lwjgl.Sys;
|
|||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
@ -213,19 +210,12 @@ public final class GLContext {
|
|||
|
||||
static void doInitNativeStubs(final Class<?> extension_class) throws LWJGLException {
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
public Object run() throws Exception {
|
||||
Method init_stubs_method = extension_class.getDeclaredMethod("initNativeStubs");
|
||||
init_stubs_method.invoke(null);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
final Throwable c = e.getCause();
|
||||
if ( c instanceof InvocationTargetException )
|
||||
throw new LWJGLException(c.getCause());
|
||||
else
|
||||
throw new LWJGLException(c);
|
||||
Method init_stubs_method = extension_class.getDeclaredMethod("initNativeStubs");
|
||||
init_stubs_method.invoke(null);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new LWJGLException(e.getCause());
|
||||
} catch (Exception e) {
|
||||
throw new LWJGLException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ public class WindowCreationTest {
|
|||
|
||||
// no need to run at full speed
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(10);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ package org.lwjgl.util;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
@ -47,9 +48,6 @@ import org.lwjgl.opengl.DisplayMode;
|
|||
* $Id$
|
||||
*/
|
||||
public final class Display {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
/**
|
||||
* Determine the available display modes that match the specified minimum and maximum criteria.
|
||||
* If any given criterium is specified as -1 then it is ignored.
|
||||
|
@ -70,15 +68,19 @@ public final class Display {
|
|||
// First get the available display modes
|
||||
DisplayMode[] modes = org.lwjgl.opengl.Display.getAvailableDisplayModes();
|
||||
|
||||
if (LWJGLUtil.DEBUG || DEBUG) {
|
||||
System.out.println("Available screen modes:");
|
||||
for ( DisplayMode mode : modes ) {
|
||||
System.out.println(mode);
|
||||
}
|
||||
if (LWJGLUtil.DEBUG) {
|
||||
LWJGLUtil.logger().log(() -> {
|
||||
StringBuilder sb = new StringBuilder("Available display modes:");
|
||||
for (DisplayMode mode : modes) {
|
||||
sb.append('\n').append(mode);
|
||||
}
|
||||
return sb.toString();
|
||||
});
|
||||
}
|
||||
|
||||
ArrayList<DisplayMode> matches = new ArrayList<DisplayMode>(modes.length);
|
||||
DisplayMode[] matches = new DisplayMode[modes.length];
|
||||
|
||||
int j = 0;
|
||||
for (int i = 0; i < modes.length; i ++) {
|
||||
assert modes[i] != null : ""+i+" "+modes.length;
|
||||
if (minWidth != -1 && modes[i].getWidth() < minWidth)
|
||||
|
@ -101,21 +103,52 @@ public final class Display {
|
|||
if (maxFreq != -1 && modes[i].getFrequency() > maxFreq)
|
||||
continue;
|
||||
}
|
||||
matches.add(modes[i]);
|
||||
matches[j++] = modes[i];
|
||||
}
|
||||
|
||||
DisplayMode[] ret = new DisplayMode[matches.size()];
|
||||
matches.toArray(ret);
|
||||
if (LWJGLUtil.DEBUG && DEBUG) {
|
||||
System.out.println("Filtered screen modes:");
|
||||
for ( DisplayMode mode : ret ) {
|
||||
System.out.println(mode);
|
||||
}
|
||||
DisplayMode[] ret = Arrays.copyOf(matches, j);
|
||||
if (LWJGLUtil.DEBUG) {
|
||||
LWJGLUtil.logger().log(() -> {
|
||||
StringBuilder sb = new StringBuilder("Filtered display modes:");
|
||||
for (DisplayMode mode : ret) {
|
||||
sb.append('\n').append(mode);
|
||||
}
|
||||
return sb.toString();
|
||||
});
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static final class FieldAccessor {
|
||||
final ToIntFunction<DisplayMode> func;
|
||||
final int order;
|
||||
final int preferred;
|
||||
final boolean usePreferred;
|
||||
|
||||
FieldAccessor(ToIntFunction<DisplayMode> func, int order, int preferred, boolean usePreferred) {
|
||||
this.func = func;
|
||||
this.order = order;
|
||||
this.preferred = preferred;
|
||||
this.usePreferred = usePreferred;
|
||||
}
|
||||
|
||||
static ToIntFunction<DisplayMode> funcByName(String fieldName) {
|
||||
switch (fieldName) {
|
||||
case "width":
|
||||
return DisplayMode::getWidth;
|
||||
case "height":
|
||||
return DisplayMode::getHeight;
|
||||
case "freq":
|
||||
return DisplayMode::getFrequency;
|
||||
case "bpp":
|
||||
return DisplayMode::getBitsPerPixel;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown field " + fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the display by choosing from a list of display modes based on an order of preference.
|
||||
* You must supply a list of allowable display modes, probably by calling getAvailableDisplayModes(),
|
||||
|
@ -130,49 +163,20 @@ public final class Display {
|
|||
* @see org.lwjgl.opengl.DisplayMode
|
||||
*/
|
||||
public static DisplayMode setDisplayMode(DisplayMode[] dm, final String[] param) throws Exception {
|
||||
|
||||
class FieldAccessor {
|
||||
final String fieldName;
|
||||
final int order;
|
||||
final int preferred;
|
||||
final boolean usePreferred;
|
||||
FieldAccessor(String fieldName, int order, int preferred, boolean usePreferred) {
|
||||
this.fieldName = fieldName;
|
||||
this.order = order;
|
||||
this.preferred = preferred;
|
||||
this.usePreferred = usePreferred;
|
||||
}
|
||||
int getInt(DisplayMode mode) {
|
||||
if ("width".equals(fieldName)) {
|
||||
return mode.getWidth();
|
||||
}
|
||||
if ("height".equals(fieldName)) {
|
||||
return mode.getHeight();
|
||||
}
|
||||
if ("freq".equals(fieldName)) {
|
||||
return mode.getFrequency();
|
||||
}
|
||||
if ("bpp".equals(fieldName)) {
|
||||
return mode.getBitsPerPixel();
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown field "+fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
class Sorter implements Comparator<DisplayMode> {
|
||||
|
||||
final FieldAccessor[] accessors;
|
||||
|
||||
Sorter() {
|
||||
accessors = new FieldAccessor[param.length];
|
||||
for (int i = 0; i < accessors.length; i ++) {
|
||||
int idx = param[i].indexOf('=');
|
||||
ToIntFunction<DisplayMode> func;
|
||||
if (idx > 0) {
|
||||
accessors[i] = new FieldAccessor(param[i].substring(0, idx), 0, Integer.parseInt(param[i].substring(idx + 1, param[i].length())), true);
|
||||
accessors[i] = new FieldAccessor(FieldAccessor.funcByName(param[i].substring(0, idx)), 0, Integer.parseInt(param[i].substring(idx + 1, param[i].length())), true);
|
||||
} else if (param[i].charAt(0) == '-') {
|
||||
accessors[i] = new FieldAccessor(param[i].substring(1), -1, 0, false);
|
||||
accessors[i] = new FieldAccessor(FieldAccessor.funcByName(param[i].substring(1)), -1, 0, false);
|
||||
} else {
|
||||
accessors[i] = new FieldAccessor(param[i], 1, 0, false);
|
||||
accessors[i] = new FieldAccessor(FieldAccessor.funcByName(param[i]), 1, 0, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,9 +185,9 @@ public final class Display {
|
|||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public int compare(DisplayMode dm1, DisplayMode dm2) {
|
||||
for ( FieldAccessor accessor : accessors ) {
|
||||
int f1 = accessor.getInt(dm1);
|
||||
int f2 = accessor.getInt(dm2);
|
||||
for (FieldAccessor accessor : accessors) {
|
||||
int f1 = accessor.func.applyAsInt(dm1);
|
||||
int f2 = accessor.func.applyAsInt(dm2);
|
||||
|
||||
if ( accessor.usePreferred && f1 != f2 ) {
|
||||
if ( f1 == accessor.preferred )
|
||||
|
@ -217,23 +221,24 @@ public final class Display {
|
|||
Arrays.sort(dm, new Sorter());
|
||||
|
||||
// Try them out in the appropriate order
|
||||
if (LWJGLUtil.DEBUG || DEBUG) {
|
||||
System.out.println("Sorted display modes:");
|
||||
for ( DisplayMode aDm : dm ) {
|
||||
System.out.println(aDm);
|
||||
}
|
||||
if (LWJGLUtil.DEBUG) {
|
||||
LWJGLUtil.logger().log(() -> {
|
||||
StringBuilder sb = new StringBuilder("Sorted display modes:");
|
||||
for (DisplayMode mode : dm) {
|
||||
sb.append('\n').append(mode);
|
||||
}
|
||||
return sb.toString();
|
||||
});
|
||||
}
|
||||
for ( DisplayMode aDm : dm ) {
|
||||
for (DisplayMode aDm : dm) {
|
||||
try {
|
||||
if ( LWJGLUtil.DEBUG || DEBUG )
|
||||
System.out.println("Attempting to set displaymode: " + aDm);
|
||||
if (LWJGLUtil.DEBUG) {
|
||||
LWJGLUtil.logger().log(() -> "Attempting to set display mode: " + aDm);
|
||||
}
|
||||
org.lwjgl.opengl.Display.setDisplayMode(aDm);
|
||||
return aDm;
|
||||
} catch (Exception e) {
|
||||
if ( LWJGLUtil.DEBUG || DEBUG ) {
|
||||
System.out.println("Failed to set display mode to " + aDm);
|
||||
e.printStackTrace();
|
||||
}
|
||||
LWJGLUtil.logger().log(() -> "Failed to set display mode to " + aDm, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.lwjgl.util.generator;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.type.*;
|
||||
import javax.lang.model.util.SimpleTypeVisitor6;
|
||||
|
||||
/**
|
||||
* A TypeVisitor that translates (annotated) TypeMirrors to type descriptors.
|
||||
*/
|
||||
public final class DescriptorTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
|
||||
private String descriptor;
|
||||
|
||||
public void descriptor(String descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
}
|
||||
|
||||
public String descriptor() {
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitArray(ArrayType t, Void o) {
|
||||
final DescriptorTypeTranslator translator = new DescriptorTypeTranslator();
|
||||
translator.visit(t.getComponentType());
|
||||
descriptor(forArray(translator.descriptor()));
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void p) {
|
||||
descriptor(forPrimitive(t.getKind()));
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitDeclared(DeclaredType t, Void o) {
|
||||
ElementKind kind = t.asElement().getKind();
|
||||
if (kind.isClass() || kind.isInterface()) {
|
||||
descriptor(forClass(t.toString()));
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
throw new RuntimeException(t.asElement().getKind() + " is not allowed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitNoType(NoType t, Void p) {
|
||||
descriptor(forClass(void.class));
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public static String forArray(String componentType) {
|
||||
return '[' + componentType;
|
||||
}
|
||||
|
||||
public static String forClass(String qualName) {
|
||||
return 'L' + qualName.replace('.', '/') + ';';
|
||||
}
|
||||
|
||||
public static String forPrimitive(TypeKind kind) {
|
||||
switch (kind) {
|
||||
case LONG:
|
||||
return forClass(long.class);
|
||||
case INT:
|
||||
return forClass(int.class);
|
||||
case DOUBLE:
|
||||
return forClass(double.class);
|
||||
case FLOAT:
|
||||
return forClass(float.class);
|
||||
case SHORT:
|
||||
return forClass(short.class);
|
||||
case BYTE:
|
||||
return forClass(byte.class);
|
||||
case BOOLEAN:
|
||||
return forClass(boolean.class);
|
||||
case CHAR:
|
||||
return forClass(char.class);
|
||||
default:
|
||||
throw new RuntimeException(kind + " is not a primitive");
|
||||
}
|
||||
}
|
||||
|
||||
public static String forClass(Class<?> clazz) {
|
||||
if (clazz == long.class) return "J";
|
||||
else if (clazz == int.class) return "I";
|
||||
else if (clazz == double.class) return "D";
|
||||
else if (clazz == float.class) return "F";
|
||||
else if (clazz == short.class) return "S";
|
||||
else if (clazz == byte.class) return "B";
|
||||
else if (clazz == boolean.class) return "Z";
|
||||
else if (clazz == char.class) return "C";
|
||||
else if (clazz == void.class) return "V";
|
||||
else if (clazz.isArray()) return forArray(forClass(clazz.componentType()));
|
||||
return forClass(clazz.getName());
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@ package org.lwjgl.util.generator;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -43,6 +44,8 @@ import javax.lang.model.element.TypeElement;
|
|||
import javax.lang.model.util.ElementFilter;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
import static org.lwjgl.util.generator.Utils.getRequiredOption;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the java classes and native code from an
|
||||
* annotated template java interface.
|
||||
|
@ -52,7 +55,7 @@ import javax.tools.Diagnostic;
|
|||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||
@SupportedOptions({ "binpath", "genpath", "typemap", "generatechecks", "nogeneratechecks", "contextspecific" })
|
||||
@SupportedOptions({ "genJavaPath", "genNativePath", "typemap", "generatechecks", "nogeneratechecks", "contextspecific" })
|
||||
public class GeneratorProcessor extends AbstractProcessor {
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
@ -64,82 +67,25 @@ public class GeneratorProcessor extends AbstractProcessor {
|
|||
return true;
|
||||
}
|
||||
Map<String, String> options = processingEnv.getOptions();
|
||||
String typemap_classname = options.get("typemap");
|
||||
String bin_path = options.get("binpath");
|
||||
String gen_path = options.get("genpath");
|
||||
String typemap_classname = getRequiredOption(options, "typemap", "the name of a TypeMap class.");
|
||||
Path gen_java_path = Path.of(getRequiredOption(options, "genJavaPath", "a path."));
|
||||
Path gen_native_path = Path.of(getRequiredOption(options, "genNativePath", "a path."));
|
||||
boolean generate_error_checks = options.containsKey("generatechecks") && !options.containsKey("nogeneratechecks");
|
||||
boolean context_specific = options.containsKey("contextspecific");
|
||||
if ( bin_path == null ) {
|
||||
throw new RuntimeException("No path specified for the bin directory with -Abinpath=<path>");
|
||||
}
|
||||
|
||||
if ( gen_path == null ) {
|
||||
throw new RuntimeException("No path specified for the gen directory with -Agenpath=<path>");
|
||||
}
|
||||
|
||||
if ( typemap_classname == null ) {
|
||||
throw new RuntimeException("No TypeMap class name specified with -Atypemap=<class-name>");
|
||||
}
|
||||
|
||||
Element lastFile = null;
|
||||
try {
|
||||
long generatorLM = getGeneratorLastModified(bin_path);
|
||||
TypeMap type_map = (TypeMap)(Class.forName(typemap_classname).newInstance());
|
||||
for ( Iterator<TypeElement> it = ElementFilter.typesIn(roundEnv.getRootElements()).iterator(); it.hasNext(); ) {
|
||||
lastFile = it.next();
|
||||
lastFile.accept(new GeneratorVisitor(processingEnv, gen_path, type_map, generate_error_checks, context_specific, generatorLM), null);
|
||||
}
|
||||
ElementFilter.typesIn(roundEnv.getRootElements()).stream().sequential().forEach(file -> {
|
||||
try {
|
||||
file.accept(new GeneratorVisitor(processingEnv, gen_java_path, gen_native_path, type_map, generate_error_checks, context_specific), null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("\n-- Failed to process template: " + file.asType().toString() + " --", e);
|
||||
}
|
||||
});
|
||||
first_round = false;
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
if ( lastFile == null ) {
|
||||
throw new RuntimeException(e);
|
||||
} else {
|
||||
throw new RuntimeException("\n-- Failed to process template: " + lastFile.asType().toString() + " --", e);
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time of the latest change on the Generator classes.
|
||||
*
|
||||
* @return time of the latest change
|
||||
*/
|
||||
private static long getGeneratorLastModified(final String bin_path) {
|
||||
long lastModified = getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator");
|
||||
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/openal"));
|
||||
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/opengl"));
|
||||
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/opencl"));
|
||||
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
private static long getDirectoryLastModified(final String bin_path, final String path) {
|
||||
final File pck = new File(bin_path + path);
|
||||
if ( !pck.exists() || !pck.isDirectory() ) {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
final File[] classes = pck.listFiles(new FileFilter() {
|
||||
public boolean accept(final File pathname) {
|
||||
return pathname.isFile() && pathname.getName().endsWith(".class");
|
||||
}
|
||||
});
|
||||
|
||||
if ( classes == null || classes.length == 0 ) {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
long lastModified = 0;
|
||||
|
||||
for ( File clazz : classes ) {
|
||||
long lm = clazz.lastModified();
|
||||
if ( lastModified < lm ) {
|
||||
lastModified = lm;
|
||||
}
|
||||
}
|
||||
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -67,19 +67,19 @@ import javax.tools.StandardLocation;
|
|||
public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
||||
|
||||
private final ProcessingEnvironment env;
|
||||
private final String gen_path;
|
||||
private final Path gen_java_path;
|
||||
private final Path gen_native_path;
|
||||
private final TypeMap type_map;
|
||||
private final boolean generate_error_checks;
|
||||
private final boolean context_specific;
|
||||
private final long generatorLM;
|
||||
|
||||
public GeneratorVisitor(ProcessingEnvironment env, String gen_path, TypeMap type_map, boolean generate_error_checks, boolean context_specific, long generatorLM) {
|
||||
public GeneratorVisitor(ProcessingEnvironment env, Path gen_java_path, Path gen_native_path, TypeMap type_map, boolean generate_error_checks, boolean context_specific) {
|
||||
this.env = env;
|
||||
this.gen_path = gen_path;
|
||||
this.gen_java_path = gen_java_path;
|
||||
this.gen_native_path = gen_native_path;
|
||||
this.type_map = type_map;
|
||||
this.generate_error_checks = generate_error_checks;
|
||||
this.context_specific = context_specific;
|
||||
this.generatorLM = generatorLM;
|
||||
}
|
||||
|
||||
private void validateMethod(ExecutableElement method) {
|
||||
|
@ -122,7 +122,7 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
private void validateType(ExecutableElement method, Class<? extends Annotation> annotation_type, Class type) {
|
||||
Class[] valid_types = type_map.getValidAnnotationTypes(type);
|
||||
for ( Class valid_type : valid_types ) {
|
||||
if ( valid_type.equals(annotation_type) ) {
|
||||
if ( valid_type.getName().equals(annotation_type) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -130,41 +130,48 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
+ " in method " + method);
|
||||
}
|
||||
|
||||
private void validateType(ExecutableElement method, Class<? extends Annotation> annotation_type, String type) {
|
||||
// TODO: reimplement this if we even care
|
||||
}
|
||||
|
||||
private void validateTypes(ExecutableElement method, List<? extends AnnotationMirror> annotations, TypeMirror type_mirror) {
|
||||
for ( AnnotationMirror annotation : annotations ) {
|
||||
NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
|
||||
if ( native_type_annotation != null ) {
|
||||
Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
|
||||
Class type = Utils.getJavaType(type_mirror);
|
||||
if ( Buffer.class.equals(type) ) {
|
||||
String desc = Utils.getDescriptor(type_mirror);
|
||||
if ( BUFFER_DESC.equals(desc) ) {
|
||||
continue;
|
||||
}
|
||||
validateType(method, annotation_type, type);
|
||||
validateType(method, annotation_type, desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String BUFFER_DESC = DescriptorTypeTranslator.forClass(Buffer.class);
|
||||
private static final String CHAR_SEQUENCE_DESC = DescriptorTypeTranslator.forClass(CharSequence.class);
|
||||
private static final String CHAR_SEQUENCE_ARRAY_DESC = DescriptorTypeTranslator.forArray(CHAR_SEQUENCE_DESC);
|
||||
|
||||
private void validateParameters(ExecutableElement method) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
for (VariableElement param : method.getParameters()) {
|
||||
validateTypes(method, param.getAnnotationMirrors(), param.asType());
|
||||
Class<?> param_type = Utils.getJavaType(param.asType());
|
||||
if ( Utils.getNIOBufferType(param.asType()) != null && param_type != CharSequence.class && param_type != CharSequence[].class ) {
|
||||
String param_type = Utils.getDescriptor(param.asType());
|
||||
if (Utils.getNIOBufferType(param.asType()) != null && !CHAR_SEQUENCE_DESC.equals(param_type) && !CHAR_SEQUENCE_ARRAY_DESC.equals(param_type)) {
|
||||
Check parameter_check_annotation = param.getAnnotation(Check.class);
|
||||
NullTerminated null_terminated_annotation = param.getAnnotation(NullTerminated.class);
|
||||
if ( parameter_check_annotation == null && null_terminated_annotation == null ) {
|
||||
if (parameter_check_annotation == null && null_terminated_annotation == null) {
|
||||
boolean found_auto_size_param = false;
|
||||
for ( VariableElement inner_param : method.getParameters() ) {
|
||||
for (VariableElement inner_param : method.getParameters()) {
|
||||
AutoSize auto_size_annotation = inner_param.getAnnotation(AutoSize.class);
|
||||
if ( auto_size_annotation != null
|
||||
&& auto_size_annotation.value().equals(param.getSimpleName().toString()) ) {
|
||||
if (auto_size_annotation != null && auto_size_annotation.value().equals(param.getSimpleName().toString())) {
|
||||
found_auto_size_param = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( !found_auto_size_param
|
||||
if (!found_auto_size_param
|
||||
&& param.getAnnotation(Result.class) == null
|
||||
&& param.getAnnotation(Constant.class) == null
|
||||
&& !Utils.isReturnParameter(method, param) ) {
|
||||
&& !Utils.isReturnParameter(method, param)) {
|
||||
throw new RuntimeException(param + " has no Check, Result nor Constant annotation, is not the return parameter and no other parameter has"
|
||||
+ " an @AutoSize annotation on it in method " + method);
|
||||
}
|
||||
|
@ -206,14 +213,14 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
private void generateJavaSource(TypeElement d, PrintWriter java_writer) throws IOException {
|
||||
java_writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
java_writer.println();
|
||||
java_writer.println("package " + env.getElementUtils().getPackageOf(d).getQualifiedName().toString() + ";");
|
||||
java_writer.append("package ").append(env.getElementUtils().getPackageOf(d).getQualifiedName().toString()).append(";\n");
|
||||
java_writer.println();
|
||||
java_writer.println("import org.lwjgl.*;");
|
||||
java_writer.println("import java.nio.*;");
|
||||
Imports imports = d.getAnnotation(Imports.class);
|
||||
if ( imports != null ) {
|
||||
for ( String i : imports.value() ) {
|
||||
java_writer.println("import " + i + ";");
|
||||
java_writer.append("import ").append(i).append(";\n");
|
||||
}
|
||||
}
|
||||
java_writer.println();
|
||||
|
@ -232,59 +239,59 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
}
|
||||
if ( super_interfaces.size() == 1 ) {
|
||||
TypeMirror super_interface = super_interfaces.iterator().next();
|
||||
java_writer.print(" extends " + Utils.getSimpleClassName(env.getElementUtils().getTypeElement(super_interface.toString())));
|
||||
java_writer.append(" extends ").append(Utils.getSimpleClassName(env.getElementUtils().getTypeElement(super_interface.toString())));
|
||||
}
|
||||
java_writer.println(" {");
|
||||
FieldsGenerator.generateFields(env, java_writer, Utils.getFields(d));
|
||||
java_writer.println();
|
||||
if ( is_final ) {
|
||||
// Write private constructor to avoid instantiation
|
||||
java_writer.println("\tprivate " + Utils.getSimpleClassName(d) + "() {}");
|
||||
java_writer.append("\tprivate ").append(Utils.getSimpleClassName(d)).append("() {}\n");
|
||||
}
|
||||
if ( Utils.getMethods(d).size() > 0 && !context_specific ) {
|
||||
java_writer.println();
|
||||
java_writer.println("\tstatic native void " + Utils.STUB_INITIALIZER_NAME + "() throws LWJGLException;");
|
||||
java_writer.append("\tstatic native void ").append(Utils.STUB_INITIALIZER_NAME).append("() throws LWJGLException;\n");
|
||||
}
|
||||
JavaMethodsGenerator.generateMethodsJava(env, type_map, java_writer, d, generate_error_checks, context_specific);
|
||||
java_writer.println("}");
|
||||
}
|
||||
|
||||
private void generateNativeSource(TypeElement d) throws IOException {
|
||||
private void generateNativeSource(TypeElement d, long startTime) throws IOException {
|
||||
if ( d.getKind().equals(ElementKind.ANNOTATION_TYPE) ) {
|
||||
return;
|
||||
}
|
||||
String qualified_interface_name = Utils.getQualifiedClassName(d);
|
||||
String qualified_native_name = Utils.getNativeQualifiedName(qualified_interface_name) + ".c";
|
||||
try (PrintWriter native_writer = new PrintWriter(env.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", qualified_native_name).openWriter())) {
|
||||
native_writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
native_writer.println();
|
||||
native_writer.println("#include <jni.h>");
|
||||
type_map.printNativeIncludes(native_writer);
|
||||
native_writer.println();
|
||||
TypedefsGenerator.generateNativeTypedefs(type_map, native_writer, Utils.getMethods(d));
|
||||
native_writer.println();
|
||||
if ( !context_specific ) {
|
||||
generateMethodsNativePointers(native_writer, Utils.getMethods(d));
|
||||
native_writer.println();
|
||||
}
|
||||
NativeMethodStubsGenerator.generateNativeMethodStubs(env, type_map, native_writer, d, generate_error_checks, context_specific);
|
||||
if ( !context_specific ) {
|
||||
native_writer.print("JNIEXPORT void JNICALL " + Utils.getQualifiedNativeMethodName(qualified_interface_name, Utils.STUB_INITIALIZER_NAME));
|
||||
native_writer.println("(JNIEnv *env, jclass clazz) {");
|
||||
native_writer.println("\tJavaMethodAndExtFunction functions[] = {");
|
||||
RegisterStubsGenerator.generateMethodsNativeStubBind(native_writer, d, generate_error_checks, context_specific);
|
||||
native_writer.println("\t};");
|
||||
native_writer.println("\tint num_functions = NUMFUNCTIONS(functions);");
|
||||
native_writer.print("\t");
|
||||
native_writer.print(type_map.getRegisterNativesFunctionName());
|
||||
native_writer.println("(env, clazz, num_functions, functions);");
|
||||
native_writer.println("}");
|
||||
}
|
||||
}
|
||||
env.getMessager().printMessage(Kind.NOTE, "Generated C source " + qualified_interface_name);
|
||||
StringWriter native_writer1 = new StringWriter();
|
||||
PrintWriter native_writer = new PrintWriter(native_writer1);
|
||||
|
||||
native_writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
native_writer.println();
|
||||
native_writer.println("#include <jni.h>");
|
||||
type_map.printNativeIncludes(native_writer);
|
||||
native_writer.println();
|
||||
TypedefsGenerator.generateNativeTypedefs(type_map, native_writer, Utils.getMethods(d));
|
||||
native_writer.println();
|
||||
if (!context_specific) {
|
||||
generateMethodsNativePointers(native_writer, Utils.getMethods(d));
|
||||
native_writer.println();
|
||||
}
|
||||
NativeMethodStubsGenerator.generateNativeMethodStubs(env, type_map, native_writer, d, generate_error_checks, context_specific);
|
||||
if (!context_specific) {
|
||||
native_writer.print("JNIEXPORT void JNICALL " + Utils.getQualifiedNativeMethodName(qualified_interface_name, Utils.STUB_INITIALIZER_NAME));
|
||||
native_writer.println("(JNIEnv *env, jclass clazz) {");
|
||||
native_writer.println("\tJavaMethodAndExtFunction functions[] = {");
|
||||
RegisterStubsGenerator.generateMethodsNativeStubBind(native_writer, d, generate_error_checks, context_specific);
|
||||
native_writer.println("\t};");
|
||||
native_writer.println("\tint num_functions = NUMFUNCTIONS(functions);");
|
||||
native_writer.print("\t");
|
||||
native_writer.print(type_map.getRegisterNativesFunctionName());
|
||||
native_writer.println("(env, clazz, num_functions, functions);");
|
||||
native_writer.println("}");
|
||||
}
|
||||
saveGeneratedCSource(env, this.gen_native_path, d, native_writer1.toString(), startTime);
|
||||
}
|
||||
|
||||
private boolean isFileExistingAndIdentical(Path file, String expected) throws IOException {
|
||||
private static boolean isFileExistingAndIdentical(ProcessingEnvironment env, Path file, String expected) throws IOException {
|
||||
if (!Files.exists(file)) return false;
|
||||
|
||||
try (Reader existingIs = Files.newBufferedReader(file, Charset.forName("UTF-8"))) {
|
||||
|
@ -295,14 +302,15 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
if (c == -1) return i == expected.length();
|
||||
if (expected.length() <= i || c != expected.charAt(i++)) {
|
||||
if (expected.length() > (i-1)) {
|
||||
env.getMessager().printMessage(Kind.NOTE, "mismatch at " + i + ": " + c);
|
||||
env.getMessager().printMessage(Kind.NOTE, "mismatch at " + i + ": '" + ((char) c) + '\'');
|
||||
} else {
|
||||
env.getMessager().printMessage(Kind.NOTE, "mismatch at " + i + ": EOF");
|
||||
env.getMessager().printMessage(Kind.NOTE, "mismatch at " + i + ": EOF in expected");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} while (c != -1);
|
||||
if (i != expected.length()) {
|
||||
env.getMessager().printMessage(Kind.NOTE, "mismatch at " + i + ": EOF in existing");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -312,6 +320,7 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
|
||||
@Override
|
||||
public Void visitTypeAsInterface(TypeElement e, Void p) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
final File input = new File("src/templates/" + e.getQualifiedName().toString().replace('.', '/') + ".java");
|
||||
final Collection<? extends ExecutableElement> methods = Utils.getMethods(e);
|
||||
if (methods.isEmpty() && Utils.getFields(e).isEmpty()) {
|
||||
|
@ -323,51 +332,74 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
validateMethod(method);
|
||||
}
|
||||
|
||||
// TODO: Back-port LWJGL 3's generation file handling (generate in-memory and avoid touching files if nothing has changed)
|
||||
StringWriter java_writer = new StringWriter();
|
||||
try {
|
||||
generateJavaSource(e, new PrintWriter(java_writer));
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Failed to generate the Java sources for " + e, ex);
|
||||
}
|
||||
Thread javaGenThread = new Thread((Runnable) () -> {
|
||||
StringWriter java_writer = new StringWriter();
|
||||
try {
|
||||
generateJavaSource(e, new PrintWriter(java_writer));
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Failed to generate the Java sources for " + e, ex);
|
||||
}
|
||||
saveGeneratedJavaSource(env, this.gen_java_path, e, java_writer.toString(), startTime);
|
||||
});
|
||||
javaGenThread.start();
|
||||
|
||||
saveGeneratedJavaSource(e, java_writer);
|
||||
|
||||
if (methods.size() > 0) {
|
||||
boolean noNative = true;
|
||||
for (ExecutableElement method : methods) {
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
if ((alt_annotation == null || alt_annotation.nativeAlt()) && method.getAnnotation(Reuse.class) == null) {
|
||||
noNative = false;
|
||||
break;
|
||||
Thread cGenThread = new Thread((Runnable) () -> {
|
||||
long startTime1 = System.currentTimeMillis();
|
||||
if (methods.size() > 0) {
|
||||
boolean noNative = true;
|
||||
for (ExecutableElement method : methods) {
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
if ((alt_annotation == null || alt_annotation.nativeAlt()) && method.getAnnotation(Reuse.class) == null) {
|
||||
noNative = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!noNative) {
|
||||
try {
|
||||
generateNativeSource(e, startTime1);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (noNative) {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
});
|
||||
cGenThread.start();
|
||||
|
||||
try {
|
||||
generateNativeSource(e);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
try {
|
||||
javaGenThread.join();
|
||||
cGenThread.join();
|
||||
} catch (Throwable ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
private void saveGeneratedJavaSource(TypeElement e, StringWriter java_writer) {
|
||||
public static void saveGeneratedJavaSource(ProcessingEnvironment env, Path gen_java_path, TypeElement e, String content, long startTime) {
|
||||
String qualified_interface_name = Utils.getQualifiedClassName(e);
|
||||
final Path output = Path.of(this.gen_path + "/" + qualified_interface_name.replace('.', '/') + ".java");
|
||||
String newStr = java_writer.toString();
|
||||
saveGeneratedSource(qualified_interface_name, output, newStr);
|
||||
saveGeneratedJavaSource(env, gen_java_path, qualified_interface_name, content, startTime);
|
||||
}
|
||||
|
||||
private void saveGeneratedSource(String name, Path output, String newStr) {
|
||||
public static void saveGeneratedJavaSource(ProcessingEnvironment env, Path gen_java_path, String qualified_interface_name, String content, long startTime) {
|
||||
final Path output = gen_java_path.resolve(qualified_interface_name.replace('.', '/') + ".java");
|
||||
saveGeneratedSource(env, "java", qualified_interface_name, output, content, startTime);
|
||||
}
|
||||
|
||||
public static void saveGeneratedCSource(ProcessingEnvironment env, Path gen_native_path, TypeElement e, String content, long startTime) {
|
||||
String qualified_interface_name = Utils.getQualifiedClassName(e);
|
||||
final Path output = gen_native_path.resolve(Utils.getNativeQualifiedName(qualified_interface_name) + ".c");
|
||||
saveGeneratedSource(env, "c", qualified_interface_name, output, content, startTime);
|
||||
}
|
||||
|
||||
public static void saveGeneratedSource(ProcessingEnvironment env, String type, String name, Path output, String newStr, long startTime) {
|
||||
try {
|
||||
if (isFileExistingAndIdentical(output, newStr)) {
|
||||
if (isFileExistingAndIdentical(env, output, newStr)) {
|
||||
long elapsed = System.currentTimeMillis() - startTime;
|
||||
env.getMessager().printMessage(Diagnostic.Kind.NOTE, "Skipped identical '." + type + "' " + name + " at " + output + " in " + elapsed + " ms.");
|
||||
return;
|
||||
}
|
||||
Files.createDirectories(output.getParent());
|
||||
Files.deleteIfExists(output);
|
||||
Files.createFile(output);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Failed to create the output file for " + name, ex);
|
||||
|
@ -375,10 +407,16 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
//try (Writer java_file_writer = env.getFiler().createSourceFile(Utils.getQualifiedClassName(e), env.getElementUtils().getPackageOf(e)).openWriter()) {
|
||||
try (Writer java_file_writer = new FileWriter(output.toFile())) {
|
||||
java_file_writer.write(newStr);
|
||||
env.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generated class " + name);
|
||||
java_file_writer.flush();
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
long elapsed = System.currentTimeMillis() - startTime;
|
||||
if (elapsed > 5) {
|
||||
env.getMessager().printMessage(Diagnostic.Kind.WARNING, "Generated '." + type + "' " + name + " at " + output + " in " + elapsed + " ms.\n\t**** SIGNIFICANT AMOUNT OF TIME");
|
||||
} else {
|
||||
env.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generated '." + type + "' " + name + " at " + output + " in " + elapsed + " ms.");
|
||||
}
|
||||
}
|
||||
|
||||
private static ByteBuffer readFile(final File file) throws IOException {
|
||||
|
|
|
@ -41,6 +41,7 @@ package org.lwjgl.util.generator;
|
|||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.util.generator.opengl.GLreturn;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.*;
|
||||
import java.util.*;
|
||||
|
@ -59,9 +60,12 @@ public class JavaMethodsGenerator {
|
|||
private static final String SAVED_PARAMETER_POSTFIX = "_saved";
|
||||
|
||||
public static void generateMethodsJava(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement interface_decl, boolean generate_error_checks, boolean context_specific) {
|
||||
for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
|
||||
generateMethodJava(env, type_map, writer, interface_decl, method, generate_error_checks, context_specific);
|
||||
}
|
||||
Utils.getMethods(interface_decl).stream().parallel().map(method -> {
|
||||
StringWriter writer1 = new StringWriter();
|
||||
PrintWriter writer2 = new PrintWriter(writer1);
|
||||
generateMethodJava(env, type_map, writer2, interface_decl, method, generate_error_checks, context_specific);
|
||||
return writer1.toString();
|
||||
}).sequential().forEach(writer::append);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -73,6 +73,14 @@ public class Utils {
|
|||
public static final String CACHED_BUFFER_NAME = "old_buffer";
|
||||
private static final String OVERLOADED_METHOD_PREFIX = "n";
|
||||
|
||||
public static String getRequiredOption(Map<String, String> options, String name, String description) {
|
||||
String optionValue = options.get(name);
|
||||
if (optionValue == null) {
|
||||
throw new IllegalArgumentException("No value specified for the '" + name + "' option. Expected " + description);
|
||||
}
|
||||
return optionValue;
|
||||
}
|
||||
|
||||
public static String getTypedefName(ExecutableElement method) {
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
return (alt_annotation == null ? method.getSimpleName() : alt_annotation.value()) + TYPEDEF_POSTFIX;
|
||||
|
@ -147,12 +155,19 @@ public class Utils {
|
|||
return Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) || CharSequence.class.isAssignableFrom(type);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Class getJavaType(TypeMirror type_mirror) {
|
||||
JavaTypeTranslator translator = new JavaTypeTranslator();
|
||||
type_mirror.accept((TypeVisitor)translator, null);
|
||||
return translator.getType();
|
||||
}
|
||||
|
||||
public static String getDescriptor(TypeMirror type_mirror) {
|
||||
DescriptorTypeTranslator translator = new DescriptorTypeTranslator();
|
||||
type_mirror.accept((TypeVisitor)translator, null);
|
||||
return translator.descriptor();
|
||||
}
|
||||
|
||||
private static boolean hasParameterMultipleTypes(VariableElement param) {
|
||||
int num_native_annotations = 0;
|
||||
for ( AnnotationMirror annotation : param.getAnnotationMirrors() ) {
|
||||
|
@ -164,7 +179,7 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static boolean isParameterMultiTyped(VariableElement param) {
|
||||
boolean result = Buffer.class.equals(Utils.getJavaType(param.asType()));
|
||||
boolean result = DescriptorTypeTranslator.forClass(Buffer.class).equals(Utils.getDescriptor(param.asType()));
|
||||
if ( !result && hasParameterMultipleTypes(param) ) {
|
||||
throw new RuntimeException(param + " not defined as java.nio.Buffer but has multiple types");
|
||||
}
|
||||
|
@ -244,10 +259,8 @@ public class Utils {
|
|||
return true;
|
||||
}
|
||||
|
||||
private static final Pattern DOT_PATTERN = Pattern.compile("\\.");
|
||||
|
||||
public static String getNativeQualifiedName(String qualified_name) {
|
||||
return DOT_PATTERN.matcher(qualified_name).replaceAll("_");
|
||||
return qualified_name.replace('.', '_');
|
||||
}
|
||||
|
||||
public static String getQualifiedNativeMethodName(String qualified_class_name, String method_name) {
|
||||
|
@ -394,7 +407,7 @@ public class Utils {
|
|||
throw new RuntimeException("The parameter specified in @GLreturn is annotated with @Check in method: " + method);
|
||||
}
|
||||
|
||||
if ( param.getAnnotation(GLchar.class) != null && Utils.getJavaType(param.asType()).equals(ByteBuffer.class) && string_annotation.maxLength().length() == 0 ) {
|
||||
if ( param.getAnnotation(GLchar.class) != null && DescriptorTypeTranslator.forClass(ByteBuffer.class).equals(Utils.getDescriptor(param.asType())) && string_annotation.maxLength().length() == 0 ) {
|
||||
throw new RuntimeException("The @GLreturn annotation is missing a maxLength parameter in method: " + method);
|
||||
}
|
||||
|
||||
|
@ -412,15 +425,15 @@ public class Utils {
|
|||
continue;
|
||||
}
|
||||
|
||||
final Class type = Utils.getJavaType(p.asType());
|
||||
if ( type.equals(CharSequence.class) ) {
|
||||
final String type = Utils.getDescriptor(p.asType());
|
||||
if (DescriptorTypeTranslator.forClass(CharSequence.class).equals(type)) {
|
||||
if ( offset == null ) {
|
||||
offset = p.getSimpleName() + ".length()";
|
||||
} else {
|
||||
offset += " + " + p.getSimpleName() + ".length()";
|
||||
}
|
||||
//if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + 1";
|
||||
} else if ( type.equals(CharSequence[].class) ) {
|
||||
} else if (DescriptorTypeTranslator.forArray(DescriptorTypeTranslator.forClass(CharSequence.class)).equals(type)) {
|
||||
if ( offset == null ) {
|
||||
offset = "APIUtil.getTotalLength(" + p.getSimpleName() + ")";
|
||||
} else {
|
||||
|
|
|
@ -37,13 +37,19 @@ import org.lwjgl.opencl.CLPlatform;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.file.Path;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
|
||||
import static org.lwjgl.util.generator.GeneratorVisitor.saveGeneratedJavaSource;
|
||||
import static org.lwjgl.util.generator.Utils.getRequiredOption;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the OpenCL capabilities classes
|
||||
*
|
||||
|
@ -51,7 +57,7 @@ import javax.lang.model.util.ElementFilter;
|
|||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||
@SupportedOptions({ "generatechecks", "contextspecific" })
|
||||
@SupportedOptions({ "genJavaPath", "generatechecks", "contextspecific" })
|
||||
public class CLGeneratorProcessor extends AbstractProcessor {
|
||||
|
||||
public static final String CLCAPS_CLASS_NAME = "CLCapabilities";
|
||||
|
@ -77,15 +83,19 @@ public class CLGeneratorProcessor extends AbstractProcessor {
|
|||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
Map<String, String> options = processingEnv.getOptions();
|
||||
Path genJavaPath = Path.of(getRequiredOption(options, "genJavaPath", "a path."));
|
||||
|
||||
try {
|
||||
Set<TypeElement> templates = ElementFilter.typesIn(roundEnv.getRootElements());
|
||||
/**
|
||||
* provide the full set of ex-InterfaceDeclaration
|
||||
* annotated templates elements
|
||||
*/
|
||||
generateCLCapabilitiesSource(templates);
|
||||
generateCLPDCapabilitiesSource(templates, CLPlatformExtension.class, PLATFORM_CAPS_CLASS_NAME, CLPlatform.class, "platform");
|
||||
generateCLPDCapabilitiesSource(templates, CLDeviceExtension.class, DEVICE_CAPS_CLASS_NAME, CLDevice.class, "device");
|
||||
generateCLCapabilitiesSource(genJavaPath, templates);
|
||||
generateCLPDCapabilitiesSource(genJavaPath, templates, CLPlatformExtension.class, PLATFORM_CAPS_CLASS_NAME, CLPlatform.class, "platform");
|
||||
generateCLPDCapabilitiesSource(genJavaPath, templates, CLDeviceExtension.class, DEVICE_CAPS_CLASS_NAME, CLDevice.class, "device");
|
||||
first_round = false;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
|
@ -100,8 +110,10 @@ public class CLGeneratorProcessor extends AbstractProcessor {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
private void generateCLCapabilitiesSource(Set<TypeElement> templates) throws IOException {
|
||||
final PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opencl." + CLCAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opencl")).openWriter());
|
||||
private void generateCLCapabilitiesSource(Path genJavaPath, Set<TypeElement> templates) throws IOException {
|
||||
long startTime = System.currentTimeMillis();
|
||||
StringWriter writer1 = new StringWriter();
|
||||
PrintWriter writer = new PrintWriter(writer1);
|
||||
printHeader(writer);
|
||||
|
||||
CLCapabilitiesGenerator.generateClassPrologue(writer);
|
||||
|
@ -122,11 +134,13 @@ public class CLGeneratorProcessor extends AbstractProcessor {
|
|||
}
|
||||
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
saveGeneratedJavaSource(processingEnv, genJavaPath, "org.lwjgl.opencl." + CLCAPS_CLASS_NAME, writer1.toString(), startTime);
|
||||
}
|
||||
|
||||
private void generateCLPDCapabilitiesSource(Set<TypeElement> templates, final Class<? extends Annotation> capsType, final String capsName, final Class<? extends PointerWrapper> objectType, final String objectName) throws IOException {
|
||||
final PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opencl." + capsName, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opencl")).openWriter());
|
||||
private void generateCLPDCapabilitiesSource(Path genJavaPath, Set<TypeElement> templates, final Class<? extends Annotation> capsType, final String capsName, final Class<? extends PointerWrapper> objectType, final String objectName) throws IOException {
|
||||
long startTime = System.currentTimeMillis();
|
||||
StringWriter writer1 = new StringWriter();
|
||||
PrintWriter writer = new PrintWriter(writer1);
|
||||
printHeader(writer);
|
||||
writer.println("import java.util.*;");
|
||||
writer.println();
|
||||
|
@ -147,6 +161,6 @@ public class CLGeneratorProcessor extends AbstractProcessor {
|
|||
CLPDCapabilitiesGenerator.generateToString(writer, templates, capsType);
|
||||
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
saveGeneratedJavaSource(processingEnv, genJavaPath, "org.lwjgl.opencl." + capsName, writer1.toString(), startTime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.util.Arrays;
|
|||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
@ -326,4 +326,4 @@ public class GLCapabilitiesGenerator {
|
|||
public static void generateField(PrintWriter writer, TypeElement d) {
|
||||
writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName().toString()) + ";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ import org.lwjgl.util.generator.Utils;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.*;
|
||||
|
@ -42,8 +44,11 @@ import javax.lang.model.SourceVersion;
|
|||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
|
||||
import static org.lwjgl.util.generator.GeneratorVisitor.saveGeneratedJavaSource;
|
||||
import static org.lwjgl.util.generator.Utils.getRequiredOption;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the ContexCapabilities class
|
||||
* Generator tool for creating the ContextCapabilities class
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision: 3316 $ $Id: ContextGeneratorProcessorFactory.java 3316
|
||||
|
@ -51,22 +56,25 @@ import javax.lang.model.util.ElementFilter;
|
|||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||
@SupportedOptions({ "generatechecks", "contextspecific" })
|
||||
@SupportedOptions({ "genJavaPath", "generatechecks", "contextspecific" })
|
||||
public class GLGeneratorProcessor extends AbstractProcessor {
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
if ( roundEnv.processingOver() || !first_round ) {
|
||||
if (roundEnv.processingOver() || !first_round) {
|
||||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
Map<String, String> options = processingEnv.getOptions();
|
||||
Path genJavaPath = Path.of(getRequiredOption(options, "genJavaPath", "a path."));
|
||||
|
||||
boolean generate_error_checks = options.containsKey("generatechecks");
|
||||
boolean context_specific = options.containsKey("contextspecific");
|
||||
try {
|
||||
generateContextCapabilitiesSource(ElementFilter.typesIn(roundEnv.getRootElements()), context_specific, generate_error_checks);
|
||||
generateContextCapabilitiesSource(genJavaPath, ElementFilter.typesIn(roundEnv.getRootElements()), context_specific, generate_error_checks);
|
||||
first_round = false;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
|
@ -74,8 +82,13 @@ public class GLGeneratorProcessor extends AbstractProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
private void generateContextCapabilitiesSource(Set<TypeElement> templates, boolean context_specific, boolean generate_error_checks) throws IOException {
|
||||
PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengl." + Utils.CONTEXT_CAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengl")).openWriter());
|
||||
private void generateContextCapabilitiesSource(Path genJavaPath, Set<TypeElement> templates, boolean context_specific, boolean generate_error_checks) throws IOException {
|
||||
long startTime = System.currentTimeMillis();
|
||||
ProcessingEnvironment env = this.processingEnv;
|
||||
|
||||
StringWriter writer1 = new StringWriter();
|
||||
PrintWriter writer = new PrintWriter(writer1);
|
||||
|
||||
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
writer.println();
|
||||
writer.println("package org.lwjgl.opengl;");
|
||||
|
@ -155,6 +168,7 @@ public class GLGeneratorProcessor extends AbstractProcessor {
|
|||
writer.println("\t\ttracker.init();");
|
||||
writer.println("\t}");
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
|
||||
saveGeneratedJavaSource(env, genJavaPath, "org.lwjgl.opengl." + Utils.CONTEXT_CAPS_CLASS_NAME, writer1.toString(), startTime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,9 @@ import org.lwjgl.util.generator.Utils;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
@ -45,6 +48,9 @@ import javax.lang.model.element.TypeElement;
|
|||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
|
||||
import static org.lwjgl.util.generator.GeneratorVisitor.saveGeneratedJavaSource;
|
||||
import static org.lwjgl.util.generator.Utils.getRequiredOption;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the References class
|
||||
*
|
||||
|
@ -54,7 +60,7 @@ import javax.lang.model.util.ElementFilter;
|
|||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||
@SupportedOptions({ "generatechecks", "contextspecific" })
|
||||
@SupportedOptions({ "genJavaPath", "generatechecks", "contextspecific" })
|
||||
public class GLReferencesGeneratorProcessor extends AbstractProcessor {
|
||||
|
||||
private static final String REFERENCES_CLASS_NAME = "References";
|
||||
|
@ -68,8 +74,12 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
|
|||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
Map<String, String> options = processingEnv.getOptions();
|
||||
Path genJavaPath = Path.of(getRequiredOption(options, "genJavaPath", "a path."));
|
||||
|
||||
try {
|
||||
generateReferencesSource(processingEnv, ElementFilter.typesIn(roundEnv.getRootElements()));
|
||||
generateReferencesSource(processingEnv, genJavaPath, ElementFilter.typesIn(roundEnv.getRootElements()));
|
||||
first_round = false;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
|
@ -145,8 +155,10 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
private void generateReferencesSource(ProcessingEnvironment env, Set<TypeElement> templates) throws IOException {
|
||||
PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengl." + REFERENCES_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengl")).openWriter());
|
||||
private void generateReferencesSource(ProcessingEnvironment env, Path genJavaPath, Set<TypeElement> templates) throws IOException {
|
||||
long startTime = System.currentTimeMillis();
|
||||
StringWriter writer1 = new StringWriter();
|
||||
PrintWriter writer = new PrintWriter(writer1);
|
||||
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
writer.println();
|
||||
writer.println("package org.lwjgl.opengl;");
|
||||
|
@ -155,32 +167,36 @@ public class GLReferencesGeneratorProcessor extends AbstractProcessor {
|
|||
writer.println("\t" + REFERENCES_CLASS_NAME + "(ContextCapabilities caps) {");
|
||||
writer.println("\t\tsuper(caps);");
|
||||
writer.println("\t}");
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
generateReferencesFromMethods(env, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
templates.stream().parallel().filter(tmpl -> tmpl.getKind().isInterface()).map(interface_decl -> {
|
||||
StringWriter writer2 = new StringWriter();
|
||||
PrintWriter writer3 = new PrintWriter(writer2);
|
||||
generateReferencesFromMethods(env, writer3, interface_decl);
|
||||
return writer2.toString();
|
||||
}).sequential().forEach(writer::append);
|
||||
writer.println();
|
||||
writer.println("\tvoid copy(" + REFERENCES_CLASS_NAME + " " + REFERENCES_PARAMETER_NAME + ", int mask) {");
|
||||
writer.println("\t\tsuper.copy(" + REFERENCES_PARAMETER_NAME + ", mask);");
|
||||
writer.println("\t\tif ( (mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {");
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
generateCopiesFromMethods(processingEnv, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
templates.stream().parallel().filter(tmpl -> tmpl.getKind().isInterface()).map(interface_decl -> {
|
||||
StringWriter writer2 = new StringWriter();
|
||||
PrintWriter writer3 = new PrintWriter(writer2);
|
||||
generateCopiesFromMethods(processingEnv, writer, interface_decl);
|
||||
return writer2.toString();
|
||||
}).sequential().forEach(writer::append);
|
||||
writer.println("\t\t}");
|
||||
writer.println("\t}");
|
||||
writer.println("\tvoid clear() {");
|
||||
writer.println("\t\tsuper.clear();");
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
generateClearsFromMethods(processingEnv, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
templates.stream().parallel().filter(tmpl -> tmpl.getKind().isInterface()).map(interface_decl -> {
|
||||
StringWriter writer2 = new StringWriter();
|
||||
PrintWriter writer3 = new PrintWriter(writer2);
|
||||
generateClearsFromMethods(processingEnv, writer, interface_decl);
|
||||
return writer2.toString();
|
||||
}).sequential().forEach(writer::append);
|
||||
writer.println("\t}");
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
|
||||
saveGeneratedJavaSource(env, genJavaPath, "org.lwjgl.opengl." + REFERENCES_CLASS_NAME, writer1.toString(), startTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue