summaryrefslogtreecommitdiffstats
path: root/opengl/tools/glgen/src
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2009-04-15 19:13:17 -0700
committerJack Palevich <jackpal@google.com>2009-04-16 15:20:55 -0700
commit27f8002e591b5c579f75b2580183b5d1c4219cd4 (patch)
tree23fafecbd64e66b7a866510c8163d34c3e506df8 /opengl/tools/glgen/src
parentf5bfda1fcecc5d8553eab16182e2f6579214ede2 (diff)
downloadframeworks_base-27f8002e591b5c579f75b2580183b5d1c4219cd4.zip
frameworks_base-27f8002e591b5c579f75b2580183b5d1c4219cd4.tar.gz
frameworks_base-27f8002e591b5c579f75b2580183b5d1c4219cd4.tar.bz2
Add an Android-specific static OpenGL ES 1.1 Java API.
This change adds four new public classes that expose a static OpenGL ES 1.1 API: android.opengl.GLES10 android.opengl.GLES10Ext android.opengl.GLES11 android.opengl.GLES11Ext Benefits: + The static API is slightly faster (1% to 4%) than the existing Interface based JSR239 API. + The static API is similar to the C API, which should make it easier to import C-based example code. + The static API provides a clear path for adding new OpenGL ES 1.1 extensions and OpenGL ES 2.0 APIs, neither of which currently have a JSR standard. Example: import static android.opengl.GLES10.*; ... glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Note that it is possible to mix-and-match calls to both the static and JSR239 APIs. This works because neither API maintains state. They both call through to the same underlying C OpenGL ES APIs. Implementation details: This change enhances the "glgen" "gen" script to generate both the original JSR239 and new static OpenGL ES APIs. The contents of the generated JSR239 classes remained the same as before, so there is no need to check in new versions of the generated JSR239 classes. As part of this work the gen script was updated to be somewhat more robust, and to work with git instead of perforce. The script prints out commands to git add the generated files, but leaves it up to the script runner to actually execute those commands.
Diffstat (limited to 'opengl/tools/glgen/src')
-rw-r--r--opengl/tools/glgen/src/GLESCodeEmitter.java40
-rw-r--r--opengl/tools/glgen/src/GenerateGL.java24
-rw-r--r--opengl/tools/glgen/src/GenerateGLES.java99
-rw-r--r--opengl/tools/glgen/src/JFunc.java51
-rw-r--r--opengl/tools/glgen/src/JType.java2
-rw-r--r--opengl/tools/glgen/src/JniCodeEmitter.java24
-rw-r--r--opengl/tools/glgen/src/Jsr239CodeEmitter.java2
7 files changed, 198 insertions, 44 deletions
diff --git a/opengl/tools/glgen/src/GLESCodeEmitter.java b/opengl/tools/glgen/src/GLESCodeEmitter.java
new file mode 100644
index 0000000..b303503
--- /dev/null
+++ b/opengl/tools/glgen/src/GLESCodeEmitter.java
@@ -0,0 +1,40 @@
+import java.io.PrintStream;
+
+/**
+ * Emits a Java interface and Java & C implementation for a C function.
+ *
+ * <p> The Java interface will have Buffer and array variants for functions that
+ * have a typed pointer argument. The array variant will convert a single "<type> *data"
+ * argument to a pair of arguments "<type>[] data, int offset".
+ */
+public class GLESCodeEmitter extends JniCodeEmitter {
+
+ PrintStream mJavaImplStream;
+ PrintStream mCStream;
+
+ PrintStream mJavaInterfaceStream;
+
+ /**
+ */
+ public GLESCodeEmitter(String classPathName,
+ ParameterChecker checker,
+ PrintStream javaImplStream,
+ PrintStream cStream) {
+ mClassPathName = classPathName;
+ mChecker = checker;
+
+ mJavaImplStream = javaImplStream;
+ mCStream = cStream;
+ mUseContextPointer = false;
+ mUseStaticMethods = true;
+ }
+
+ public void emitCode(CFunc cfunc, String original) {
+ emitCode(cfunc, original, null, mJavaImplStream,
+ mCStream);
+ }
+
+ public void emitNativeRegistration(String nativeRegistrationName) {
+ emitNativeRegistration(nativeRegistrationName, mCStream);
+ }
+}
diff --git a/opengl/tools/glgen/src/GenerateGL.java b/opengl/tools/glgen/src/GenerateGL.java
index accb16e..3715a96 100644
--- a/opengl/tools/glgen/src/GenerateGL.java
+++ b/opengl/tools/glgen/src/GenerateGL.java
@@ -31,18 +31,18 @@ public class GenerateGL {
CFunc cfunc = CFunc.parseCFunc(s);
String fname = cfunc.getName();
- File f = new File("stubs/" + fname +
+ File f = new File("stubs/jsr239/" + fname +
".java-1" + version + "-if");
if (f.exists()) {
System.out.println("Special-casing function " + fname);
- copy("stubs/" + fname +
+ copy("stubs/jsr239/" + fname +
".java-1" + version + "-if", glStream);
- copy("stubs/" + fname + ".java-impl", glImplStream);
- copy("stubs/" + fname + ".cpp", cStream);
+ copy("stubs/jsr239/" + fname + ".java-impl", glImplStream);
+ copy("stubs/jsr239/" + fname + ".cpp", cStream);
// Register native function names
// This should be improved to require fewer discrete files
- String filename = "stubs/" + fname + ".nativeReg";
+ String filename = "stubs/jsr239/" + fname + ".nativeReg";
BufferedReader br =
new BufferedReader(new FileReader(filename));
String nfunc;
@@ -135,13 +135,13 @@ public class GenerateGL {
glImplStream.println("/* //device/java/android/" + glImplFilename);
cStream.println("/* //device/libs/android_runtime/" + cFilename);
- copy("stubs/GL10Header.java-if", gl10Stream);
- copy("stubs/GL10ExtHeader.java-if", gl10ExtStream);
- copy("stubs/GL11Header.java-if", gl11Stream);
- copy("stubs/GL11ExtHeader.java-if", gl11ExtStream);
- copy("stubs/GL11ExtensionPackHeader.java-if", gl11ExtPackStream);
- copy("stubs/GLImplHeader.java-impl", glImplStream);
- copy("stubs/GLCHeader.cpp", cStream);
+ copy("stubs/jsr239/GL10Header.java-if", gl10Stream);
+ copy("stubs/jsr239/GL10ExtHeader.java-if", gl10ExtStream);
+ copy("stubs/jsr239/GL11Header.java-if", gl11Stream);
+ copy("stubs/jsr239/GL11ExtHeader.java-if", gl11ExtStream);
+ copy("stubs/jsr239/GL11ExtensionPackHeader.java-if", gl11ExtPackStream);
+ copy("stubs/jsr239/GLImplHeader.java-impl", glImplStream);
+ copy("stubs/jsr239/GLCHeader.cpp", cStream);
emit(0, false, false,
emitter, spec10Reader, gl10Stream, glImplStream, cStream);
diff --git a/opengl/tools/glgen/src/GenerateGLES.java b/opengl/tools/glgen/src/GenerateGLES.java
new file mode 100644
index 0000000..60775b7
--- /dev/null
+++ b/opengl/tools/glgen/src/GenerateGLES.java
@@ -0,0 +1,99 @@
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintStream;
+
+public class GenerateGLES {
+
+ static void copy(String filename, PrintStream out) throws IOException {
+ BufferedReader br = new BufferedReader(new FileReader(filename));
+ String s;
+ while ((s = br.readLine()) != null) {
+ out.println(s);
+ }
+ }
+
+ private static void emit(GLESCodeEmitter emitter,
+ BufferedReader specReader,
+ PrintStream glStream,
+ PrintStream cStream) throws Exception {
+ String s = null;
+ while ((s = specReader.readLine()) != null) {
+ if (s.trim().startsWith("//")) {
+ continue;
+ }
+
+ CFunc cfunc = CFunc.parseCFunc(s);
+
+ String fname = cfunc.getName();
+ String stubRoot = "stubs/gles11/" + fname;
+ String javaPath = stubRoot + ".java";
+ File f = new File(javaPath);
+ if (f.exists()) {
+ System.out.println("Special-casing function " + fname);
+ copy(javaPath, glStream);
+ copy(stubRoot + ".cpp", cStream);
+
+ // Register native function names
+ // This should be improved to require fewer discrete files
+ String filename = stubRoot + ".nativeReg";
+ BufferedReader br =
+ new BufferedReader(new FileReader(filename));
+ String nfunc;
+ while ((nfunc = br.readLine()) != null) {
+ emitter.addNativeRegistration(nfunc);
+ }
+ } else {
+ emitter.emitCode(cfunc, s);
+ }
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ int aidx = 0;
+ while ((aidx < args.length) && (args[aidx].charAt(0) == '-')) {
+ switch (args[aidx].charAt(1)) {
+ default:
+ System.err.println("Unknown flag: " + args[aidx]);
+ System.exit(1);
+ }
+
+ aidx++;
+ }
+
+ BufferedReader checksReader =
+ new BufferedReader(new FileReader("specs/gles11/checks.spec"));
+ ParameterChecker checker = new ParameterChecker(checksReader);
+
+ // Generate files
+ for(String suffix: new String[] {"GLES10", "GLES10Ext",
+ "GLES11", "GLES11Ext"})
+ {
+ BufferedReader spec11Reader =
+ new BufferedReader(new FileReader("specs/gles11/"
+ + suffix + ".spec"));
+ String gl11Filename = "android/opengl/" + suffix + ".java";
+ String gl11cFilename = "android_opengl_" + suffix + ".cpp";
+ PrintStream gl11Stream =
+ new PrintStream(new FileOutputStream("out/" + gl11Filename));
+ PrintStream gl11cStream =
+ new PrintStream(new FileOutputStream("out/" + gl11cFilename));
+ gl11Stream.println("/*");
+ gl11cStream.println("/*");
+ copy("stubs/gles11/" + suffix + "Header.java-if", gl11Stream);
+ copy("stubs/gles11/" + suffix + "cHeader.cpp", gl11cStream);
+ GLESCodeEmitter emitter = new GLESCodeEmitter(
+ "android/opengl/" + suffix,
+ checker, gl11Stream, gl11cStream);
+ emit(emitter, spec11Reader, gl11Stream, gl11cStream);
+ emitter.emitNativeRegistration("register_android_opengl_jni_"
+ + suffix);
+ gl11Stream.println("}");
+ gl11Stream.close();
+ gl11cStream.close();
+ }
+ }
+}
diff --git a/opengl/tools/glgen/src/JFunc.java b/opengl/tools/glgen/src/JFunc.java
index 68f717c..63c045b 100644
--- a/opengl/tools/glgen/src/JFunc.java
+++ b/opengl/tools/glgen/src/JFunc.java
@@ -104,34 +104,39 @@ public class JFunc {
}
public static JFunc convert(CFunc cfunc, boolean useArray) {
- JFunc jfunc = new JFunc(cfunc);
- jfunc.setName(cfunc.getName());
- jfunc.setType(JType.convert(cfunc.getType(), false));
-
- int numArgs = cfunc.getNumArgs();
- int numOffsets = 0;
- for (int i = 0; i < numArgs; i++) {
- CType cArgType = cfunc.getArgType(i);
- if (cArgType.isTypedPointer() && useArray) {
- ++numOffsets;
+ try {
+ JFunc jfunc = new JFunc(cfunc);
+ jfunc.setName(cfunc.getName());
+ jfunc.setType(JType.convert(cfunc.getType(), false));
+
+ int numArgs = cfunc.getNumArgs();
+ int numOffsets = 0;
+ for (int i = 0; i < numArgs; i++) {
+ CType cArgType = cfunc.getArgType(i);
+ if (cArgType.isTypedPointer() && useArray) {
+ ++numOffsets;
+ }
}
- }
-
- for (int i = 0; i < numArgs; i++) {
- String cArgName = cfunc.getArgName(i);
- CType cArgType = cfunc.getArgType(i);
- jfunc.addArgument(cArgName, JType.convert(cArgType, useArray), i);
- if (cArgType.isTypedPointer() && useArray) {
- if (numOffsets > 1) {
- jfunc.addArgument(cArgName + "Offset", new JType("int"), i);
- } else {
- jfunc.addArgument("offset", new JType("int"), i);
+ for (int i = 0; i < numArgs; i++) {
+ String cArgName = cfunc.getArgName(i);
+ CType cArgType = cfunc.getArgType(i);
+
+ jfunc.addArgument(cArgName, JType.convert(cArgType, useArray), i);
+ if (cArgType.isTypedPointer() && useArray) {
+ if (numOffsets > 1) {
+ jfunc.addArgument(cArgName + "Offset", new JType("int"), i);
+ } else {
+ jfunc.addArgument("offset", new JType("int"), i);
+ }
}
}
- }
- return jfunc;
+ return jfunc;
+ } catch (RuntimeException e) {
+ System.err.println("Failed to convert function " + cfunc);
+ throw e;
+ }
}
@Override
diff --git a/opengl/tools/glgen/src/JType.java b/opengl/tools/glgen/src/JType.java
index 5ad0e54..df1177b 100644
--- a/opengl/tools/glgen/src/JType.java
+++ b/opengl/tools/glgen/src/JType.java
@@ -36,6 +36,8 @@ public class JType {
new JType("java.nio.Buffer", true, false));
typeMapping.put(new CType("void", false, true),
new JType("java.nio.Buffer", true, false));
+ typeMapping.put(new CType("GLeglImageOES", false, false),
+ new JType("java.nio.Buffer", true, false));
// Typed pointers map to typed Buffers
typeMapping.put(new CType("GLboolean", false, true),
diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java
index 9d37607..ef0dbd0 100644
--- a/opengl/tools/glgen/src/JniCodeEmitter.java
+++ b/opengl/tools/glgen/src/JniCodeEmitter.java
@@ -8,6 +8,7 @@ public class JniCodeEmitter {
static final boolean mUseCPlusPlus = true;
protected boolean mUseContextPointer = true;
+ protected boolean mUseStaticMethods = false;
protected String mClassPathName;
protected ParameterChecker mChecker;
protected List<String> nativeRegistrations = new ArrayList<String>();
@@ -67,7 +68,9 @@ public class JniCodeEmitter {
emitNativeDeclaration(jfunc, javaImplStream);
emitJavaCode(jfunc, javaImplStream);
}
- emitJavaInterfaceCode(jfunc, javaInterfaceStream);
+ if (javaInterfaceStream != null) {
+ emitJavaInterfaceCode(jfunc, javaInterfaceStream);
+ }
if (!duplicate) {
emitJniCode(jfunc, cStream);
}
@@ -86,7 +89,9 @@ public class JniCodeEmitter {
if (!duplicate) {
emitNativeDeclaration(jfunc, javaImplStream);
}
- emitJavaInterfaceCode(jfunc, javaInterfaceStream);
+ if (javaInterfaceStream != null) {
+ emitJavaInterfaceCode(jfunc, javaInterfaceStream);
+ }
if (!duplicate) {
emitJavaCode(jfunc, javaImplStream);
emitJniCode(jfunc, cStream);
@@ -405,18 +410,20 @@ public class JniCodeEmitter {
return;
}
+ String maybeStatic = mUseStaticMethods ? "static " : "";
+
if (isPointerFunc) {
out.println(indent +
- (nativeDecl ? "private native " :
- (interfaceDecl ? "" : "public ")) +
+ (nativeDecl ? "private " + maybeStatic +"native " :
+ (interfaceDecl ? "" : "public ") + maybeStatic) +
jfunc.getType() + " " +
jfunc.getName() +
(nativeDecl ? "Bounds" : "") +
"(");
} else {
out.println(indent +
- (nativeDecl ? "public native " :
- (interfaceDecl ? "" : "public ")) +
+ (nativeDecl ? "public " + maybeStatic +"native " :
+ (interfaceDecl ? "" : "public ") + maybeStatic) +
jfunc.getType() + " " +
jfunc.getName() +
"(");
@@ -508,7 +515,8 @@ public class JniCodeEmitter {
nativeRegistrations.add(s);
}
- public void emitNativeRegistration(PrintStream cStream) {
+ public void emitNativeRegistration(String registrationFunctionName,
+ PrintStream cStream) {
cStream.println("static const char *classPathName = \"" +
mClassPathName +
"\";");
@@ -527,7 +535,7 @@ public class JniCodeEmitter {
cStream.println();
- cStream.println("int register_com_google_android_gles_jni_GLImpl(JNIEnv *_env)");
+ cStream.println("int " + registrationFunctionName + "(JNIEnv *_env)");
cStream.println("{");
cStream.println(indent +
"int err;");
diff --git a/opengl/tools/glgen/src/Jsr239CodeEmitter.java b/opengl/tools/glgen/src/Jsr239CodeEmitter.java
index eff0447..335d226 100644
--- a/opengl/tools/glgen/src/Jsr239CodeEmitter.java
+++ b/opengl/tools/glgen/src/Jsr239CodeEmitter.java
@@ -69,6 +69,6 @@ public class Jsr239CodeEmitter extends JniCodeEmitter implements CodeEmitter {
}
public void emitNativeRegistration() {
- emitNativeRegistration(mCStream);
+ emitNativeRegistration("register_com_google_android_gles_jni_GLImpl", mCStream);
}
}