diff options
author | Jack Palevich <jackpal@google.com> | 2009-04-13 16:22:25 -0700 |
---|---|---|
committer | Jack Palevich <jackpal@google.com> | 2009-04-13 16:40:25 -0700 |
commit | 3cae8fede973a66c10ee07446e8dd8d7c2ead2c1 (patch) | |
tree | 830c9cc7c86fcfb9edf7eef3264730c552d40102 /opengl/tools | |
parent | d5a9af45fff88be8bde35852f247e212f82e5e26 (diff) | |
download | frameworks_base-3cae8fede973a66c10ee07446e8dd8d7c2ead2c1.zip frameworks_base-3cae8fede973a66c10ee07446e8dd8d7c2ead2c1.tar.gz frameworks_base-3cae8fede973a66c10ee07446e8dd8d7c2ead2c1.tar.bz2 |
Clean up trivial Eclipse warnings and fix whitespace.
Added @Override to overridden methods.
Removed unused imports.
Converted tabs to spaces.
Removed \r characters from end-of-lines.
Add .gitignore file to ignore the .class files that are
generated when the "gen" script is run.
Diffstat (limited to 'opengl/tools')
-rw-r--r-- | opengl/tools/glgen/src/.gitignore | 1 | ||||
-rw-r--r-- | opengl/tools/glgen/src/CFunc.java | 311 | ||||
-rw-r--r-- | opengl/tools/glgen/src/CType.java | 173 | ||||
-rw-r--r-- | opengl/tools/glgen/src/CodeEmitter.java | 16 | ||||
-rw-r--r-- | opengl/tools/glgen/src/GenerateGL.java | 332 | ||||
-rw-r--r-- | opengl/tools/glgen/src/JFunc.java | 297 | ||||
-rw-r--r-- | opengl/tools/glgen/src/JType.java | 279 | ||||
-rw-r--r-- | opengl/tools/glgen/src/JniCodeEmitter.java | 88 |
8 files changed, 753 insertions, 744 deletions
diff --git a/opengl/tools/glgen/src/.gitignore b/opengl/tools/glgen/src/.gitignore new file mode 100644 index 0000000..6b468b6 --- /dev/null +++ b/opengl/tools/glgen/src/.gitignore @@ -0,0 +1 @@ +*.class diff --git a/opengl/tools/glgen/src/CFunc.java b/opengl/tools/glgen/src/CFunc.java index 0794f41..a89e1c5 100644 --- a/opengl/tools/glgen/src/CFunc.java +++ b/opengl/tools/glgen/src/CFunc.java @@ -1,155 +1,156 @@ -
-import java.util.*;
-
-public class CFunc {
-
- String original;
-
- CType ftype;
- String fname;
-
- List<String> argNames = new ArrayList<String>();
- List<CType> argTypes = new ArrayList<CType>();
-
- boolean hasPointerArg = false;
- boolean hasTypedPointerArg = false;
-
- public CFunc(String original) {
- this.original = original;
- }
-
- public String getOriginal() {
- return original;
- }
-
- public void setName(String fname) {
- this.fname = fname;
- }
-
- public String getName() {
- return fname;
- }
-
- public void setType(CType ftype) {
- this.ftype = ftype;
- }
-
- public CType getType() {
- return ftype;
- }
-
- public void addArgument(String argName, CType argType) {
- argNames.add(argName);
- argTypes.add(argType);
-
- if (argType.isPointer()) {
- hasPointerArg = true;
- }
- if (argType.isTypedPointer()) {
- hasTypedPointerArg = true;
- }
- }
-
- public int getNumArgs() {
- return argNames.size();
- }
-
- public int getArgIndex(String name) {
- int len = argNames.size();
- for (int i = 0; i < len; i++) {
- if (name.equals(argNames.get(i))) {
- return i;
- }
- }
- return -1;
- }
-
- public String getArgName(int index) {
- return argNames.get(index);
- }
-
- public CType getArgType(int index) {
- return argTypes.get(index);
- }
-
- public boolean hasPointerArg() {
- return hasPointerArg;
- }
-
- public boolean hasTypedPointerArg() {
- return hasTypedPointerArg;
- }
-
- public String toString() {
- String s = "Function " + fname + " returns " + ftype + ": ";
- for (int i = 0; i < argNames.size(); i++) {
- if (i > 0) {
- s += ", ";
- }
- s += argTypes.get(i) + " " + argNames.get(i);
- }
- return s;
- }
-
- public static CFunc parseCFunc(String s) {
- CFunc cfunc = new CFunc(s);
- String[] tokens = s.split("\\s");
-
- int i = 0;
- CType ftype = new CType();
- String ftypeName = tokens[i++];
- if (ftypeName.equals("const")) {
- ftype.setIsConst(true);
- ftypeName = tokens[i++];
- }
- ftype.setBaseType(ftypeName);
-
- String fname = tokens[i++];
- if (fname.equals("*")) {
- ftype.setIsPointer(true);
- fname = tokens[i++];
- }
-
- cfunc.setName(fname);
- cfunc.setType(ftype);
-
- while (i < tokens.length) {
- String tok = tokens[i++];
-
- if (tok.equals("(")) {
- continue;
- }
- if (tok.equals(")")) {
- break;
- }
-
- CType argType = new CType();
-
- String argTypeName = tok;
- String argName = "";
-
- if (argTypeName.equals("const")) {
- argType.setIsConst(true);
- argTypeName = tokens[i++];
- }
- argType.setBaseType(argTypeName);
-
- if (argTypeName.equals("void")) {
- break;
- }
-
- argName = tokens[i++];
- if (argName.startsWith("*")) {
- argType.setIsPointer(true);
- argName = argName.substring(1, argName.length());
- }
- if (argName.endsWith(",")) {
- argName = argName.substring(0, argName.length() - 1);
- }
-
- cfunc.addArgument(argName, argType);
- }
-
- return cfunc;
- }
-}
+ +import java.util.*; + +public class CFunc { + + String original; + + CType ftype; + String fname; + + List<String> argNames = new ArrayList<String>(); + List<CType> argTypes = new ArrayList<CType>(); + + boolean hasPointerArg = false; + boolean hasTypedPointerArg = false; + + public CFunc(String original) { + this.original = original; + } + + public String getOriginal() { + return original; + } + + public void setName(String fname) { + this.fname = fname; + } + + public String getName() { + return fname; + } + + public void setType(CType ftype) { + this.ftype = ftype; + } + + public CType getType() { + return ftype; + } + + public void addArgument(String argName, CType argType) { + argNames.add(argName); + argTypes.add(argType); + + if (argType.isPointer()) { + hasPointerArg = true; + } + if (argType.isTypedPointer()) { + hasTypedPointerArg = true; + } + } + + public int getNumArgs() { + return argNames.size(); + } + + public int getArgIndex(String name) { + int len = argNames.size(); + for (int i = 0; i < len; i++) { + if (name.equals(argNames.get(i))) { + return i; + } + } + return -1; + } + + public String getArgName(int index) { + return argNames.get(index); + } + + public CType getArgType(int index) { + return argTypes.get(index); + } + + public boolean hasPointerArg() { + return hasPointerArg; + } + + public boolean hasTypedPointerArg() { + return hasTypedPointerArg; + } + + @Override + public String toString() { + String s = "Function " + fname + " returns " + ftype + ": "; + for (int i = 0; i < argNames.size(); i++) { + if (i > 0) { + s += ", "; + } + s += argTypes.get(i) + " " + argNames.get(i); + } + return s; + } + + public static CFunc parseCFunc(String s) { + CFunc cfunc = new CFunc(s); + String[] tokens = s.split("\\s"); + + int i = 0; + CType ftype = new CType(); + String ftypeName = tokens[i++]; + if (ftypeName.equals("const")) { + ftype.setIsConst(true); + ftypeName = tokens[i++]; + } + ftype.setBaseType(ftypeName); + + String fname = tokens[i++]; + if (fname.equals("*")) { + ftype.setIsPointer(true); + fname = tokens[i++]; + } + + cfunc.setName(fname); + cfunc.setType(ftype); + + while (i < tokens.length) { + String tok = tokens[i++]; + + if (tok.equals("(")) { + continue; + } + if (tok.equals(")")) { + break; + } + + CType argType = new CType(); + + String argTypeName = tok; + String argName = ""; + + if (argTypeName.equals("const")) { + argType.setIsConst(true); + argTypeName = tokens[i++]; + } + argType.setBaseType(argTypeName); + + if (argTypeName.equals("void")) { + break; + } + + argName = tokens[i++]; + if (argName.startsWith("*")) { + argType.setIsPointer(true); + argName = argName.substring(1, argName.length()); + } + if (argName.endsWith(",")) { + argName = argName.substring(0, argName.length() - 1); + } + + cfunc.addArgument(argName, argType); + } + + return cfunc; + } +} diff --git a/opengl/tools/glgen/src/CType.java b/opengl/tools/glgen/src/CType.java index 331ec62..826c90d 100644 --- a/opengl/tools/glgen/src/CType.java +++ b/opengl/tools/glgen/src/CType.java @@ -1,85 +1,88 @@ -
-public class CType {
-
- String baseType;
- boolean isConst;
- boolean isPointer;
-
- public CType() {
- }
-
- public CType(String baseType) {
- setBaseType(baseType);
- }
-
- public CType(String baseType, boolean isConst, boolean isPointer) {
- setBaseType(baseType);
- setIsConst(isConst);
- setIsPointer(isPointer);
- }
-
- public String getDeclaration() {
- return baseType + (isPointer ? " *" : "");
- }
-
- public void setIsConst(boolean isConst) {
- this.isConst = isConst;
- }
-
- public boolean isConst() {
- return isConst;
- }
-
- public void setIsPointer(boolean isPointer) {
- this.isPointer = isPointer;
- }
-
- public boolean isPointer() {
- return isPointer;
- }
-
- boolean isVoid() {
- String baseType = getBaseType();
- return baseType.equals("GLvoid") ||
- baseType.equals("void");
- }
-
- public boolean isTypedPointer() {
- return isPointer() && !isVoid();
- }
-
- public void setBaseType(String baseType) {
- this.baseType = baseType;
- }
-
- public String getBaseType() {
- return baseType;
- }
-
- public String toString() {
- String s = "";
- if (isConst()) {
- s += "const ";
- }
- s += baseType;
- if (isPointer()) {
- s += "*";
- }
-
- return s;
- }
-
- public int hashCode() {
- return baseType.hashCode() ^ (isPointer ? 2 : 0) ^ (isConst ? 1 : 0);
- }
-
- public boolean equals(Object o) {
- if (o != null && o instanceof CType) {
- CType c = (CType)o;
- return baseType.equals(c.baseType) &&
- isPointer() == c.isPointer() &&
- isConst() == c.isConst();
- }
- return false;
- }
-}
+ +public class CType { + + String baseType; + boolean isConst; + boolean isPointer; + + public CType() { + } + + public CType(String baseType) { + setBaseType(baseType); + } + + public CType(String baseType, boolean isConst, boolean isPointer) { + setBaseType(baseType); + setIsConst(isConst); + setIsPointer(isPointer); + } + + public String getDeclaration() { + return baseType + (isPointer ? " *" : ""); + } + + public void setIsConst(boolean isConst) { + this.isConst = isConst; + } + + public boolean isConst() { + return isConst; + } + + public void setIsPointer(boolean isPointer) { + this.isPointer = isPointer; + } + + public boolean isPointer() { + return isPointer; + } + + boolean isVoid() { + String baseType = getBaseType(); + return baseType.equals("GLvoid") || + baseType.equals("void"); + } + + public boolean isTypedPointer() { + return isPointer() && !isVoid(); + } + + public void setBaseType(String baseType) { + this.baseType = baseType; + } + + public String getBaseType() { + return baseType; + } + + @Override + public String toString() { + String s = ""; + if (isConst()) { + s += "const "; + } + s += baseType; + if (isPointer()) { + s += "*"; + } + + return s; + } + + @Override + public int hashCode() { + return baseType.hashCode() ^ (isPointer ? 2 : 0) ^ (isConst ? 1 : 0); + } + + @Override + public boolean equals(Object o) { + if (o != null && o instanceof CType) { + CType c = (CType)o; + return baseType.equals(c.baseType) && + isPointer() == c.isPointer() && + isConst() == c.isConst(); + } + return false; + } +} diff --git a/opengl/tools/glgen/src/CodeEmitter.java b/opengl/tools/glgen/src/CodeEmitter.java index 3e9b90a..ebb9727 100644 --- a/opengl/tools/glgen/src/CodeEmitter.java +++ b/opengl/tools/glgen/src/CodeEmitter.java @@ -1,8 +1,8 @@ -
-public interface CodeEmitter {
-
- void setVersion(int version, boolean ext, boolean pack);
- void emitCode(CFunc cfunc, String original);
- void addNativeRegistration(String fname);
- void emitNativeRegistration();
-}
+ +public interface CodeEmitter { + + void setVersion(int version, boolean ext, boolean pack); + void emitCode(CFunc cfunc, String original); + void addNativeRegistration(String fname); + void emitNativeRegistration(); +} diff --git a/opengl/tools/glgen/src/GenerateGL.java b/opengl/tools/glgen/src/GenerateGL.java index 657ee6e..afe1bb6 100644 --- a/opengl/tools/glgen/src/GenerateGL.java +++ b/opengl/tools/glgen/src/GenerateGL.java @@ -1,164 +1,168 @@ -
-import java.io.*;
-import java.util.*;
-
-public class GenerateGL {
-
- 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(int version, boolean ext, boolean pack,
- CodeEmitter emitter,
- BufferedReader specReader,
- PrintStream glStream,
- PrintStream glImplStream,
- PrintStream cStream) throws Exception {
- String s = null;
- int counter = 0;
- while ((s = specReader.readLine()) != null) {
- if (s.trim().startsWith("//")) {
- continue;
- }
-
- CFunc cfunc = CFunc.parseCFunc(s);
-
- String fname = cfunc.getName();
- File f = new File("stubs/" + fname +
- ".java-1" + version + "-if");
- if (f.exists()) {
- System.out.println("Special-casing function " + fname);
- copy("stubs/" + fname +
- ".java-1" + version + "-if", glStream);
- copy("stubs/" + fname + ".java-impl", glImplStream);
- copy("stubs/" + fname + ".cpp", cStream);
-
- // Register native function names
- // This should be improved to require fewer discrete files
- String filename = "stubs/" + fname + ".nativeReg";
- BufferedReader br =
- new BufferedReader(new FileReader(filename));
- String nfunc;
- while ((nfunc = br.readLine()) != null) {
- emitter.addNativeRegistration(nfunc);
- }
- } else {
- emitter.setVersion(version, ext, pack);
- emitter.emitCode(cfunc, s);
- }
- }
- }
-
- public static void main(String[] args) throws Exception {
- String classPathName = "com/google/android/gles_jni/GLImpl";
- boolean useContextPointer = true;
-
- int aidx = 0;
- while (args[aidx].charAt(0) == '-') {
- switch (args[aidx].charAt(1)) {
- case 'c':
- useContextPointer = false;
- break;
-
- default:
- System.err.println("Unknown flag: " + args[aidx]);
- System.exit(1);
- }
-
- aidx++;
- }
-
- System.out.println("useContextPointer = " + useContextPointer);
-
- BufferedReader spec10Reader =
- new BufferedReader(new FileReader(args[aidx++]));
- BufferedReader spec10ExtReader =
- new BufferedReader(new FileReader(args[aidx++]));
- BufferedReader spec11Reader =
- new BufferedReader(new FileReader(args[aidx++]));
- BufferedReader spec11ExtReader =
- new BufferedReader(new FileReader(args[aidx++]));
- BufferedReader spec11ExtPackReader =
- new BufferedReader(new FileReader(args[aidx++]));
- BufferedReader checksReader =
- new BufferedReader(new FileReader(args[aidx++]));
-
- String gl10Filename = "javax/microedition/khronos/opengles/GL10.java";
- String gl10ExtFilename =
- "javax/microedition/khronos/opengles/GL10Ext.java";
- String gl11Filename = "javax/microedition/khronos/opengles/GL11.java";
- String gl11ExtFilename =
- "javax/microedition/khronos/opengles/GL11Ext.java";
- String gl11ExtPackFilename =
- "javax/microedition/khronos/opengles/GL11ExtensionPack.java";
- String glImplFilename = "com/google/android/gles_jni/GLImpl.java";
- String cFilename = "com_google_android_gles_jni_GLImpl.cpp";
-
- PrintStream gl10Stream =
- new PrintStream(new FileOutputStream("out/" + gl10Filename));
- PrintStream gl10ExtStream =
- new PrintStream(new FileOutputStream("out/" + gl10ExtFilename));
- PrintStream gl11Stream =
- new PrintStream(new FileOutputStream("out/" + gl11Filename));
- PrintStream gl11ExtStream =
- new PrintStream(new FileOutputStream("out/" + gl11ExtFilename));
- PrintStream gl11ExtPackStream =
- new PrintStream(new FileOutputStream("out/" + gl11ExtPackFilename));
- PrintStream glImplStream =
- new PrintStream(new FileOutputStream("out/" + glImplFilename));
- PrintStream cStream =
- new PrintStream(new FileOutputStream("out/" + cFilename));
-
- ParameterChecker checker = new ParameterChecker(checksReader);
-
- CodeEmitter emitter =
- new JniCodeEmitter(classPathName,
- checker,
- gl10Stream, gl10ExtStream,
- gl11Stream, gl11ExtStream, gl11ExtPackStream,
- glImplStream, cStream,
- useContextPointer);
-
- gl10Stream.println("/* //device/java/android/" + gl10Filename);
- gl10ExtStream.println("/* //device/java/android/" + gl10ExtFilename);
- gl11Stream.println("/* //device/java/android/" + gl11Filename);
- gl11ExtStream.println("/* //device/java/android/" + gl11ExtFilename);
- gl11ExtPackStream.println("/* //device/java/android/" +
- gl11ExtPackFilename);
- 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);
-
- emit(0, false, false,
- emitter, spec10Reader, gl10Stream, glImplStream, cStream);
- emit(0, true, false,
- emitter, spec10ExtReader, gl10ExtStream, glImplStream, cStream);
- emit(1, false, false,
- emitter, spec11Reader, gl11Stream, glImplStream, cStream);
- emit(1, true, false,
- emitter, spec11ExtReader, gl11ExtStream, glImplStream, cStream);
- emit(1, true, true,
- emitter, spec11ExtPackReader, gl11ExtPackStream, glImplStream,
- cStream);
-
- emitter.emitNativeRegistration();
-
- gl10Stream.println("}");
- gl10ExtStream.println("}");
- gl11Stream.println("}");
- gl11ExtStream.println("}");
- gl11ExtPackStream.println("}");
- glImplStream.println("}");
- }
-}
+ +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 GenerateGL { + + 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(int version, boolean ext, boolean pack, + CodeEmitter emitter, + BufferedReader specReader, + PrintStream glStream, + PrintStream glImplStream, + PrintStream cStream) throws Exception { + String s = null; + int counter = 0; + while ((s = specReader.readLine()) != null) { + if (s.trim().startsWith("//")) { + continue; + } + + CFunc cfunc = CFunc.parseCFunc(s); + + String fname = cfunc.getName(); + File f = new File("stubs/" + fname + + ".java-1" + version + "-if"); + if (f.exists()) { + System.out.println("Special-casing function " + fname); + copy("stubs/" + fname + + ".java-1" + version + "-if", glStream); + copy("stubs/" + fname + ".java-impl", glImplStream); + copy("stubs/" + fname + ".cpp", cStream); + + // Register native function names + // This should be improved to require fewer discrete files + String filename = "stubs/" + fname + ".nativeReg"; + BufferedReader br = + new BufferedReader(new FileReader(filename)); + String nfunc; + while ((nfunc = br.readLine()) != null) { + emitter.addNativeRegistration(nfunc); + } + } else { + emitter.setVersion(version, ext, pack); + emitter.emitCode(cfunc, s); + } + } + } + + public static void main(String[] args) throws Exception { + String classPathName = "com/google/android/gles_jni/GLImpl"; + boolean useContextPointer = true; + + int aidx = 0; + while (args[aidx].charAt(0) == '-') { + switch (args[aidx].charAt(1)) { + case 'c': + useContextPointer = false; + break; + + default: + System.err.println("Unknown flag: " + args[aidx]); + System.exit(1); + } + + aidx++; + } + + System.out.println("useContextPointer = " + useContextPointer); + + BufferedReader spec10Reader = + new BufferedReader(new FileReader(args[aidx++])); + BufferedReader spec10ExtReader = + new BufferedReader(new FileReader(args[aidx++])); + BufferedReader spec11Reader = + new BufferedReader(new FileReader(args[aidx++])); + BufferedReader spec11ExtReader = + new BufferedReader(new FileReader(args[aidx++])); + BufferedReader spec11ExtPackReader = + new BufferedReader(new FileReader(args[aidx++])); + BufferedReader checksReader = + new BufferedReader(new FileReader(args[aidx++])); + + String gl10Filename = "javax/microedition/khronos/opengles/GL10.java"; + String gl10ExtFilename = + "javax/microedition/khronos/opengles/GL10Ext.java"; + String gl11Filename = "javax/microedition/khronos/opengles/GL11.java"; + String gl11ExtFilename = + "javax/microedition/khronos/opengles/GL11Ext.java"; + String gl11ExtPackFilename = + "javax/microedition/khronos/opengles/GL11ExtensionPack.java"; + String glImplFilename = "com/google/android/gles_jni/GLImpl.java"; + String cFilename = "com_google_android_gles_jni_GLImpl.cpp"; + + PrintStream gl10Stream = + new PrintStream(new FileOutputStream("out/" + gl10Filename)); + PrintStream gl10ExtStream = + new PrintStream(new FileOutputStream("out/" + gl10ExtFilename)); + PrintStream gl11Stream = + new PrintStream(new FileOutputStream("out/" + gl11Filename)); + PrintStream gl11ExtStream = + new PrintStream(new FileOutputStream("out/" + gl11ExtFilename)); + PrintStream gl11ExtPackStream = + new PrintStream(new FileOutputStream("out/" + gl11ExtPackFilename)); + PrintStream glImplStream = + new PrintStream(new FileOutputStream("out/" + glImplFilename)); + PrintStream cStream = + new PrintStream(new FileOutputStream("out/" + cFilename)); + + ParameterChecker checker = new ParameterChecker(checksReader); + + CodeEmitter emitter = + new JniCodeEmitter(classPathName, + checker, + gl10Stream, gl10ExtStream, + gl11Stream, gl11ExtStream, gl11ExtPackStream, + glImplStream, cStream, + useContextPointer); + + gl10Stream.println("/* //device/java/android/" + gl10Filename); + gl10ExtStream.println("/* //device/java/android/" + gl10ExtFilename); + gl11Stream.println("/* //device/java/android/" + gl11Filename); + gl11ExtStream.println("/* //device/java/android/" + gl11ExtFilename); + gl11ExtPackStream.println("/* //device/java/android/" + + gl11ExtPackFilename); + 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); + + emit(0, false, false, + emitter, spec10Reader, gl10Stream, glImplStream, cStream); + emit(0, true, false, + emitter, spec10ExtReader, gl10ExtStream, glImplStream, cStream); + emit(1, false, false, + emitter, spec11Reader, gl11Stream, glImplStream, cStream); + emit(1, true, false, + emitter, spec11ExtReader, gl11ExtStream, glImplStream, cStream); + emit(1, true, true, + emitter, spec11ExtPackReader, gl11ExtPackStream, glImplStream, + cStream); + + emitter.emitNativeRegistration(); + + gl10Stream.println("}"); + gl10ExtStream.println("}"); + gl11Stream.println("}"); + gl11ExtStream.println("}"); + gl11ExtPackStream.println("}"); + glImplStream.println("}"); + } +} diff --git a/opengl/tools/glgen/src/JFunc.java b/opengl/tools/glgen/src/JFunc.java index 42d466c..68f717c 100644 --- a/opengl/tools/glgen/src/JFunc.java +++ b/opengl/tools/glgen/src/JFunc.java @@ -1,148 +1,149 @@ -
-import java.util.ArrayList;
-import java.util.List;
-
-public class JFunc {
-
- String className = "com.google.android.gles_jni.GL11Impl";
-
- CFunc cfunc;
- JType ftype;
- String fname;
-
- List<String> argNames = new ArrayList<String>();
- List<JType> argTypes = new ArrayList<JType>();
- List<Integer> argCIndices = new ArrayList<Integer>();
-
- boolean hasBufferArg = false;
- boolean hasTypedBufferArg = false;
- ArrayList<String> bufferArgNames = new ArrayList<String>();
-
- public JFunc(CFunc cfunc) {
- this.cfunc = cfunc;
- }
-
- public CFunc getCFunc() {
- return cfunc;
- }
-
- public void setName(String fname) {
- this.fname = fname;
- }
-
- public String getName() {
- return fname;
- }
-
- public void setType(JType ftype) {
- this.ftype = ftype;
- }
-
- public JType getType() {
- return ftype;
- }
-
- public void setClassName(String className) {
- this.className = className;
- }
-
- public String getClassName() {
- return className;
- }
-
- public boolean hasBufferArg() {
- return hasBufferArg;
- }
-
- public boolean hasTypedBufferArg() {
- return hasTypedBufferArg;
- }
-
- public String getBufferArgName(int index) {
- return bufferArgNames.get(index);
- }
-
- public void addArgument(String argName, JType argType, int cindex) {
- argNames.add(argName);
- argTypes.add(argType);
- argCIndices.add(new Integer(cindex));
-
- if (argType.isBuffer()) {
- hasBufferArg = true;
- bufferArgNames.add(argName);
- }
- if (argType.isTypedBuffer()) {
- hasTypedBufferArg = true;
- bufferArgNames.add(argName);
- }
- }
-
- public int getNumArgs() {
- return argNames.size();
- }
-
- public int getArgIndex(String name) {
- int len = argNames.size();
- for (int i = 0; i < len; i++) {
- if (name.equals(argNames.get(i))) {
- return i;
- }
- }
- return -1;
- }
-
- public String getArgName(int index) {
- return argNames.get(index);
- }
-
- public JType getArgType(int index) {
- return argTypes.get(index);
- }
-
- public int getArgCIndex(int index) {
- return argCIndices.get(index).intValue();
- }
-
- 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;
- }
- }
-
- 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;
- }
-
- public String toString() {
- String s = "Function " + fname + " returns " + ftype + ": ";
- for (int i = 0; i < argNames.size(); i++) {
- if (i > 0) {
- s += ", ";
- }
- s += argTypes.get(i) + " " + argNames.get(i);
- }
- return s;
- }
-
-}
+ +import java.util.ArrayList; +import java.util.List; + +public class JFunc { + + String className = "com.google.android.gles_jni.GL11Impl"; + + CFunc cfunc; + JType ftype; + String fname; + + List<String> argNames = new ArrayList<String>(); + List<JType> argTypes = new ArrayList<JType>(); + List<Integer> argCIndices = new ArrayList<Integer>(); + + boolean hasBufferArg = false; + boolean hasTypedBufferArg = false; + ArrayList<String> bufferArgNames = new ArrayList<String>(); + + public JFunc(CFunc cfunc) { + this.cfunc = cfunc; + } + + public CFunc getCFunc() { + return cfunc; + } + + public void setName(String fname) { + this.fname = fname; + } + + public String getName() { + return fname; + } + + public void setType(JType ftype) { + this.ftype = ftype; + } + + public JType getType() { + return ftype; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getClassName() { + return className; + } + + public boolean hasBufferArg() { + return hasBufferArg; + } + + public boolean hasTypedBufferArg() { + return hasTypedBufferArg; + } + + public String getBufferArgName(int index) { + return bufferArgNames.get(index); + } + + public void addArgument(String argName, JType argType, int cindex) { + argNames.add(argName); + argTypes.add(argType); + argCIndices.add(new Integer(cindex)); + + if (argType.isBuffer()) { + hasBufferArg = true; + bufferArgNames.add(argName); + } + if (argType.isTypedBuffer()) { + hasTypedBufferArg = true; + bufferArgNames.add(argName); + } + } + + public int getNumArgs() { + return argNames.size(); + } + + public int getArgIndex(String name) { + int len = argNames.size(); + for (int i = 0; i < len; i++) { + if (name.equals(argNames.get(i))) { + return i; + } + } + return -1; + } + + public String getArgName(int index) { + return argNames.get(index); + } + + public JType getArgType(int index) { + return argTypes.get(index); + } + + public int getArgCIndex(int index) { + return argCIndices.get(index).intValue(); + } + + 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; + } + } + + 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; + } + + @Override + public String toString() { + String s = "Function " + fname + " returns " + ftype + ": "; + for (int i = 0; i < argNames.size(); i++) { + if (i > 0) { + s += ", "; + } + s += argTypes.get(i) + " " + argNames.get(i); + } + return s; + } + +} diff --git a/opengl/tools/glgen/src/JType.java b/opengl/tools/glgen/src/JType.java index a16d440..5ad0e54 100644 --- a/opengl/tools/glgen/src/JType.java +++ b/opengl/tools/glgen/src/JType.java @@ -1,139 +1,140 @@ -
-import java.util.HashMap;
-
-public class JType {
-
- String baseType;
- boolean isArray;
- boolean isClass;
-
- static HashMap<CType,JType> typeMapping = new HashMap<CType,JType>();
- static HashMap<CType,JType> arrayTypeMapping = new HashMap<CType,JType>();
-
- static {
- // Primitive types
- typeMapping.put(new CType("GLbitfield"), new JType("int"));
- typeMapping.put(new CType("GLboolean"), new JType("boolean"));
- typeMapping.put(new CType("GLclampf"), new JType("float"));
- typeMapping.put(new CType("GLclampx"), new JType("int"));
- typeMapping.put(new CType("GLenum"), new JType("int"));
- typeMapping.put(new CType("GLfloat"), new JType("float"));
- typeMapping.put(new CType("GLfixed"), new JType("int"));
- typeMapping.put(new CType("GLint"), new JType("int"));
- typeMapping.put(new CType("GLintptr"), new JType("int"));
- typeMapping.put(new CType("GLshort"), new JType("short"));
- typeMapping.put(new CType("GLsizei"), new JType("int"));
- typeMapping.put(new CType("GLsizeiptr"), new JType("int"));
- typeMapping.put(new CType("GLubyte"), new JType("byte"));
- typeMapping.put(new CType("GLuint"), new JType("int"));
- typeMapping.put(new CType("void"), new JType("void"));
- typeMapping.put(new CType("GLubyte", true, true), new JType("String"));
-
- // Untyped pointers map to untyped Buffers
- typeMapping.put(new CType("GLvoid", true, true),
- new JType("java.nio.Buffer", true, false));
- typeMapping.put(new CType("GLvoid", false, true),
- new JType("java.nio.Buffer", true, false));
- typeMapping.put(new CType("void", false, true),
- new JType("java.nio.Buffer", true, false));
-
- // Typed pointers map to typed Buffers
- typeMapping.put(new CType("GLboolean", false, true),
- new JType("java.nio.IntBuffer", true, false));
- typeMapping.put(new CType("GLfixed", false, true),
- new JType("java.nio.IntBuffer", true, false));
- typeMapping.put(new CType("GLfixed", true, true),
- new JType("java.nio.IntBuffer", true, false));
- typeMapping.put(new CType("GLfloat", false, true),
- new JType("java.nio.FloatBuffer", true, false));
- typeMapping.put(new CType("GLfloat", true, true),
- new JType("java.nio.FloatBuffer", true, false));
- typeMapping.put(new CType("GLint", false, true),
- new JType("java.nio.IntBuffer", true, false));
- typeMapping.put(new CType("GLint", true, true),
- new JType("java.nio.IntBuffer", true, false));
- typeMapping.put(new CType("GLuint", false, true),
- new JType("java.nio.IntBuffer", true, false));
- typeMapping.put(new CType("GLuint", true, true),
- new JType("java.nio.IntBuffer", true, false));
- typeMapping.put(new CType("GLshort", true, true),
- new JType("java.nio.ShortBuffer", true, false));
-
- // Typed pointers map to arrays + offsets
- arrayTypeMapping.put(new CType("GLboolean", false, true),
- new JType("boolean", false, true));
- arrayTypeMapping.put(new CType("GLfixed", true, true), new JType("int", false, true));
- arrayTypeMapping.put(new CType("GLfixed", false, true), new JType("int", false, true));
- arrayTypeMapping.put(new CType("GLfloat", false, true), new JType("float", false, true));
- arrayTypeMapping.put(new CType("GLfloat", true, true), new JType("float", false, true));
- arrayTypeMapping.put(new CType("GLint", false, true), new JType("int", false, true));
- arrayTypeMapping.put(new CType("GLint", true, true), new JType("int", false, true));
- arrayTypeMapping.put(new CType("GLshort", true, true), new JType("short", false, true));
- arrayTypeMapping.put(new CType("GLuint", false, true), new JType("int", false, true));
- arrayTypeMapping.put(new CType("GLuint", true, true), new JType("int", false, true));
- arrayTypeMapping.put(new CType("GLintptr"), new JType("int", false, true));
- arrayTypeMapping.put(new CType("GLsizeiptr"), new JType("int", false, true));
- }
-
- public JType() {
- }
-
- public JType(String primitiveTypeName) {
- this.baseType = primitiveTypeName;
- this.isClass = false;
- this.isArray = false;
- }
-
- public JType(String primitiveTypeName, boolean isClass, boolean isArray) {
- this.baseType = primitiveTypeName;
- this.isClass = isClass;
- this.isArray = isArray;
- }
-
- public String getBaseType() {
- return baseType;
- }
-
- public String toString() {
- return baseType + (isArray ? "[]" : "");
- }
-
- public boolean isArray() {
- return isArray;
- }
-
- public boolean isClass() {
- return isClass;
- }
-
- public boolean isPrimitive() {
- return !isClass() && !isArray();
- }
-
- public boolean isVoid() {
- return baseType.equals("void");
- }
-
- public boolean isBuffer() {
- return baseType.indexOf("Buffer") != -1;
- }
-
- public boolean isTypedBuffer() {
- return !baseType.equals("java.nio.Buffer") &&
- (baseType.indexOf("Buffer") != -1);
- }
-
- public static JType convert(CType ctype, boolean useArray) {
- JType javaType = null;
- if (useArray) {
- javaType = arrayTypeMapping.get(ctype);
- }
- if (javaType == null) {
- javaType = typeMapping.get(ctype);
- }
- if (javaType == null) {
- throw new RuntimeException("Unsupported C type: " + ctype);
- }
- return javaType;
- }
-}
+ +import java.util.HashMap; + +public class JType { + + String baseType; + boolean isArray; + boolean isClass; + + static HashMap<CType,JType> typeMapping = new HashMap<CType,JType>(); + static HashMap<CType,JType> arrayTypeMapping = new HashMap<CType,JType>(); + + static { + // Primitive types + typeMapping.put(new CType("GLbitfield"), new JType("int")); + typeMapping.put(new CType("GLboolean"), new JType("boolean")); + typeMapping.put(new CType("GLclampf"), new JType("float")); + typeMapping.put(new CType("GLclampx"), new JType("int")); + typeMapping.put(new CType("GLenum"), new JType("int")); + typeMapping.put(new CType("GLfloat"), new JType("float")); + typeMapping.put(new CType("GLfixed"), new JType("int")); + typeMapping.put(new CType("GLint"), new JType("int")); + typeMapping.put(new CType("GLintptr"), new JType("int")); + typeMapping.put(new CType("GLshort"), new JType("short")); + typeMapping.put(new CType("GLsizei"), new JType("int")); + typeMapping.put(new CType("GLsizeiptr"), new JType("int")); + typeMapping.put(new CType("GLubyte"), new JType("byte")); + typeMapping.put(new CType("GLuint"), new JType("int")); + typeMapping.put(new CType("void"), new JType("void")); + typeMapping.put(new CType("GLubyte", true, true), new JType("String")); + + // Untyped pointers map to untyped Buffers + typeMapping.put(new CType("GLvoid", true, true), + new JType("java.nio.Buffer", true, false)); + typeMapping.put(new CType("GLvoid", false, true), + new JType("java.nio.Buffer", true, false)); + typeMapping.put(new CType("void", false, true), + new JType("java.nio.Buffer", true, false)); + + // Typed pointers map to typed Buffers + typeMapping.put(new CType("GLboolean", false, true), + new JType("java.nio.IntBuffer", true, false)); + typeMapping.put(new CType("GLfixed", false, true), + new JType("java.nio.IntBuffer", true, false)); + typeMapping.put(new CType("GLfixed", true, true), + new JType("java.nio.IntBuffer", true, false)); + typeMapping.put(new CType("GLfloat", false, true), + new JType("java.nio.FloatBuffer", true, false)); + typeMapping.put(new CType("GLfloat", true, true), + new JType("java.nio.FloatBuffer", true, false)); + typeMapping.put(new CType("GLint", false, true), + new JType("java.nio.IntBuffer", true, false)); + typeMapping.put(new CType("GLint", true, true), + new JType("java.nio.IntBuffer", true, false)); + typeMapping.put(new CType("GLuint", false, true), + new JType("java.nio.IntBuffer", true, false)); + typeMapping.put(new CType("GLuint", true, true), + new JType("java.nio.IntBuffer", true, false)); + typeMapping.put(new CType("GLshort", true, true), + new JType("java.nio.ShortBuffer", true, false)); + + // Typed pointers map to arrays + offsets + arrayTypeMapping.put(new CType("GLboolean", false, true), + new JType("boolean", false, true)); + arrayTypeMapping.put(new CType("GLfixed", true, true), new JType("int", false, true)); + arrayTypeMapping.put(new CType("GLfixed", false, true), new JType("int", false, true)); + arrayTypeMapping.put(new CType("GLfloat", false, true), new JType("float", false, true)); + arrayTypeMapping.put(new CType("GLfloat", true, true), new JType("float", false, true)); + arrayTypeMapping.put(new CType("GLint", false, true), new JType("int", false, true)); + arrayTypeMapping.put(new CType("GLint", true, true), new JType("int", false, true)); + arrayTypeMapping.put(new CType("GLshort", true, true), new JType("short", false, true)); + arrayTypeMapping.put(new CType("GLuint", false, true), new JType("int", false, true)); + arrayTypeMapping.put(new CType("GLuint", true, true), new JType("int", false, true)); + arrayTypeMapping.put(new CType("GLintptr"), new JType("int", false, true)); + arrayTypeMapping.put(new CType("GLsizeiptr"), new JType("int", false, true)); + } + + public JType() { + } + + public JType(String primitiveTypeName) { + this.baseType = primitiveTypeName; + this.isClass = false; + this.isArray = false; + } + + public JType(String primitiveTypeName, boolean isClass, boolean isArray) { + this.baseType = primitiveTypeName; + this.isClass = isClass; + this.isArray = isArray; + } + + public String getBaseType() { + return baseType; + } + + @Override + public String toString() { + return baseType + (isArray ? "[]" : ""); + } + + public boolean isArray() { + return isArray; + } + + public boolean isClass() { + return isClass; + } + + public boolean isPrimitive() { + return !isClass() && !isArray(); + } + + public boolean isVoid() { + return baseType.equals("void"); + } + + public boolean isBuffer() { + return baseType.indexOf("Buffer") != -1; + } + + public boolean isTypedBuffer() { + return !baseType.equals("java.nio.Buffer") && + (baseType.indexOf("Buffer") != -1); + } + + public static JType convert(CType ctype, boolean useArray) { + JType javaType = null; + if (useArray) { + javaType = arrayTypeMapping.get(ctype); + } + if (javaType == null) { + javaType = typeMapping.get(ctype); + } + if (javaType == null) { + throw new RuntimeException("Unsupported C type: " + ctype); + } + return javaType; + } +} diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java index 33b9a3e..2a8bcbb 100644 --- a/opengl/tools/glgen/src/JniCodeEmitter.java +++ b/opengl/tools/glgen/src/JniCodeEmitter.java @@ -1,6 +1,4 @@ import java.io.PrintStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -24,7 +22,7 @@ public class JniCodeEmitter implements CodeEmitter { boolean mUseContextPointer = true; String mClassPathName; - + ParameterChecker mChecker; PrintStream mJava10InterfaceStream; PrintStream mJava10ExtInterfaceStream; @@ -47,7 +45,7 @@ public class JniCodeEmitter implements CodeEmitter { /** * @param java10InterfaceStream the PrintStream to which to emit the Java interface for GL 1.0 functions * @param java10ExtInterfaceStream the PrintStream to which to emit the Java interface for GL 1.0 extension functions - * @param java11InterfaceStream the PrintStream to which to emit the Java interface for GL 1.1 functions + * @param java11InterfaceStream the PrintStream to which to emit the Java interface for GL 1.1 functions * @param java11ExtInterfaceStream the PrintStream to which to emit the Java interface for GL 1.1 Extension functions * @param java11ExtPackInterfaceStream the PrintStream to which to emit the Java interface for GL 1.1 Extension Pack functions * @param javaImplStream the PrintStream to which to emit the Java implementation @@ -93,7 +91,7 @@ public class JniCodeEmitter implements CodeEmitter { JFunc jfunc; String signature; boolean duplicate; - + if (cfunc.hasTypedPointerArg()) { jfunc = JFunc.convert(cfunc, true); @@ -152,7 +150,7 @@ public class JniCodeEmitter implements CodeEmitter { public void emitJavaCode(JFunc jfunc, PrintStream out) { emitFunction(jfunc, out, false, false); } - + void emitFunctionCall(JFunc jfunc, PrintStream out, String iii, boolean grabArray ) { boolean isVoid = jfunc.getType().isVoid(); boolean isPointerFunc = jfunc.getName().endsWith("Pointer") && @@ -167,7 +165,7 @@ public class JniCodeEmitter implements CodeEmitter { jfunc.getName() + (isPointerFunc ? "Bounds" : "" ) + "("); - + int numArgs = jfunc.getNumArgs(); for (int i = 0; i < numArgs; i++) { String argName = jfunc.getArgName(i); @@ -177,7 +175,7 @@ public class JniCodeEmitter implements CodeEmitter { String typeName = argType.getBaseType(); typeName = typeName.substring(9, typeName.length() - 6); out.println(iii + indent + "get" + typeName + "Array(" + argName + "),"); - out.print(iii + indent + "getOffset(" + argName + ")"); + out.print(iii + indent + "getOffset(" + argName + ")"); } else { out.print(iii + indent + argName); } @@ -192,7 +190,7 @@ public class JniCodeEmitter implements CodeEmitter { out.println(","); } } - + out.println(iii + ");"); } @@ -220,7 +218,7 @@ public class JniCodeEmitter implements CodeEmitter { (mUseCPlusPlus ? "" : "_env, ") + "IAEClass, " + "\"" + - (isBuffer ? + (isBuffer ? "remaining()" : "length - " + offset) + " < needed\");"); out.println(iii + indent + "goto exit;"); @@ -345,21 +343,21 @@ public class JniCodeEmitter implements CodeEmitter { if (emitExceptionCheck) { out.println(iii + indent + "_exception = 1;"); } - String exceptionClassName = "IAEClass"; - // If the "check" keyword was of the form - // "check_<class name>", use the class name in the - // exception to be thrown - int underscore = checks[index].indexOf('_'); - if (underscore >= 0) { - exceptionClassName = checks[index].substring(underscore + 1) + "Class"; - } + String exceptionClassName = "IAEClass"; + // If the "check" keyword was of the form + // "check_<class name>", use the class name in the + // exception to be thrown + int underscore = checks[index].indexOf('_'); + if (underscore >= 0) { + exceptionClassName = checks[index].substring(underscore + 1) + "Class"; + } out.println(iii + indent + (mUseCPlusPlus ? "_env" : "(*_env)") + "->ThrowNew(" + (mUseCPlusPlus ? "" : "_env, ") + - exceptionClassName + ", " + + exceptionClassName + ", " + "\"" + - (isBuffer ? + (isBuffer ? "remaining()" : "length - " + offset) + " < " + checks[index + 2] + "\");"); @@ -367,7 +365,7 @@ public class JniCodeEmitter implements CodeEmitter { out.println(iii + indent + "goto exit;"); needsExit = true; out.println(iii + "}"); - + index += 3; } else if (checks[index].equals("ifcheck")) { String[] matches = checks[index + 4].split(","); @@ -379,7 +377,7 @@ public class JniCodeEmitter implements CodeEmitter { checks[index + 3] + ") {"); } - + for (int i = 0; i < matches.length; i++) { out.println("#if defined(" + matches[i] + ")"); out.println(iii + @@ -394,7 +392,7 @@ public class JniCodeEmitter implements CodeEmitter { ";"); out.println(iii + " break;"); - + lastWasIfcheck = true; index += 5; } else if (checks[index].equals("return")) { @@ -439,7 +437,7 @@ public class JniCodeEmitter implements CodeEmitter { return false; } - + /** * Emit a function in several variants: * @@ -478,12 +476,12 @@ public class JniCodeEmitter implements CodeEmitter { jfunc.getName() + "("); } - + int numArgs = jfunc.getNumArgs(); for (int i = 0; i < numArgs; i++) { String argName = jfunc.getArgName(i); JType argType = jfunc.getArgType(i); - + out.print(indent + indent + argType + " " + argName); if (i == numArgs - 1) { if (isPointerFunc && nativeDecl) { @@ -568,7 +566,7 @@ public class JniCodeEmitter implements CodeEmitter { } else if (jType.isArray()) { jniName = "["; } - + String baseType = jType.getBaseType(); if (baseType.equals("int")) { jniName += "I"; @@ -604,7 +602,7 @@ public class JniCodeEmitter implements CodeEmitter { return "jobject"; } } - + String getJniMangledName(String name) { name = name.replaceAll("_", "_1"); name = name.replaceAll(";", "_2"); @@ -614,7 +612,7 @@ public class JniCodeEmitter implements CodeEmitter { public void emitJniCode(JFunc jfunc, PrintStream out) { CFunc cfunc = jfunc.getCFunc(); - + // Emit comment identifying original C function // // Example: @@ -658,13 +656,13 @@ public class JniCodeEmitter implements CodeEmitter { } // Append signature to function name - String sig = getJniMangledName(signature).replace('.', '_'); + String sig = getJniMangledName(signature).replace('.', '_'); out.print("__" + sig); outName += "__" + sig; - + signature = signature.replace('.', '/'); rsignature = rsignature.replace('.', '/'); - + out.println(); if (rsignature.length() == 0) { rsignature = "V"; @@ -718,7 +716,7 @@ public class JniCodeEmitter implements CodeEmitter { out.print(", jint remaining"); } out.println(") {"); - + int numArrays = 0; int numBuffers = 0; for (int i = 0; i < nonPrimitiveArgs.size(); i++) { @@ -740,7 +738,7 @@ public class JniCodeEmitter implements CodeEmitter { // Example: // // android::gl::ogles_context_t *ctx; - // + // // jint _exception; // GLenum _returnValue; // @@ -827,7 +825,7 @@ public class JniCodeEmitter implements CodeEmitter { out.println(indent + decl + (decl.endsWith("*") ? "" : " ") + - jfunc.getArgName(idx) + + jfunc.getArgName(idx) + " = (" + decl + ") 0;"); } @@ -843,7 +841,7 @@ public class JniCodeEmitter implements CodeEmitter { for (int i = 0; i < nonPrimitiveArgs.size(); i++) { int idx = nonPrimitiveArgs.get(i).intValue(); int cIndex = jfunc.getArgCIndex(idx); - + String cname = cfunc.getArgName(cIndex); offset = numArrays <= 1 ? "offset" : cname + "Offset"; @@ -852,7 +850,7 @@ public class JniCodeEmitter implements CodeEmitter { if (jfunc.getArgType(idx).isArray()) { out.println(indent + - "if (!" + + "if (!" + cname + "_ref) {"); if (emitExceptionCheck) { @@ -884,7 +882,7 @@ public class JniCodeEmitter implements CodeEmitter { out.println(indent + "}"); out.println(indent + remaining + " = " + - (mUseCPlusPlus ? "_env" : "(*_env)") + + (mUseCPlusPlus ? "_env" : "(*_env)") + "->GetArrayLength(" + (mUseCPlusPlus ? "" : "_env, ") + cname + "_ref) - " + offset + ";"); @@ -901,7 +899,7 @@ public class JniCodeEmitter implements CodeEmitter { out.println(indent + " " + (mUseCPlusPlus ? "_env" : "(*_env)") + "->GetPrimitiveArrayCritical(" + - (mUseCPlusPlus ? "" : "_env, ") + + (mUseCPlusPlus ? "" : "_env, ") + jfunc.getArgName(idx) + "_ref, (jboolean *)0);"); out.println(indent + @@ -917,7 +915,7 @@ public class JniCodeEmitter implements CodeEmitter { out.println(indent + "if (" + cname + "_buf) {"); out.print(indent); } - + out.println(indent + cname + " = (" + @@ -950,10 +948,10 @@ public class JniCodeEmitter implements CodeEmitter { name.substring(1, name.length()); out.print("ctx->procs."); } - + out.print(name + (isPointerFunc ? "Bounds" : "") + "("); - numArgs = cfunc.getNumArgs(); + numArgs = cfunc.getNumArgs(); if (numArgs == 0) { if (mUseContextPointer) { out.println("ctx);"); @@ -1006,7 +1004,7 @@ public class JniCodeEmitter implements CodeEmitter { int cIndex = jfunc.getArgCIndex(idx); if (jfunc.getArgType(idx).isArray()) { - + // If the argument is 'const', GL will not write to it. // In this case, we can use the 'JNI_ABORT' flag to avoid // the need to write back to the Java array @@ -1015,7 +1013,7 @@ public class JniCodeEmitter implements CodeEmitter { out.println(indent + indent + (mUseCPlusPlus ? "_env" : "(*_env)") + "->ReleasePrimitiveArrayCritical(" + - (mUseCPlusPlus ? "" : "_env, ") + + (mUseCPlusPlus ? "" : "_env, ") + jfunc.getArgName(idx) + "_ref, " + cfunc.getArgName(cIndex) + "_base,"); @@ -1070,7 +1068,7 @@ public class JniCodeEmitter implements CodeEmitter { mCStream.println("};"); mCStream.println(); - + mCStream.println("int register_com_google_android_gles_jni_GLImpl(JNIEnv *_env)"); mCStream.println("{"); |