1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import java.io.BufferedReader; 18 import java.io.File; 19 import java.io.FileOutputStream; 20 import java.io.FileReader; 21 import java.io.IOException; 22 import java.io.PrintStream; 23 24 public class GenerateGL { 25 copy(String filename, PrintStream out)26 static void copy(String filename, PrintStream out) throws IOException { 27 BufferedReader br = new BufferedReader(new FileReader(filename)); 28 String s; 29 while ((s = br.readLine()) != null) { 30 out.println(s); 31 } 32 } 33 emit(int version, boolean ext, boolean pack, CodeEmitter emitter, BufferedReader specReader, PrintStream glStream, PrintStream glImplStream, PrintStream cStream)34 private static void emit(int version, boolean ext, boolean pack, 35 CodeEmitter emitter, 36 BufferedReader specReader, 37 PrintStream glStream, 38 PrintStream glImplStream, 39 PrintStream cStream) throws Exception { 40 String s = null; 41 while ((s = specReader.readLine()) != null) { 42 if (s.trim().startsWith("//")) { 43 continue; 44 } 45 46 CFunc cfunc = CFunc.parseCFunc(s); 47 48 String fname = cfunc.getName(); 49 File f = new File("stubs/jsr239/" + fname + 50 ".java-1" + version + "-if"); 51 if (f.exists()) { 52 System.out.println("Special-casing function " + fname); 53 copy("stubs/jsr239/" + fname + 54 ".java-1" + version + "-if", glStream); 55 copy("stubs/jsr239/" + fname + ".java-impl", glImplStream); 56 copy("stubs/jsr239/" + fname + ".cpp", cStream); 57 58 // Register native function names 59 // This should be improved to require fewer discrete files 60 String filename = "stubs/jsr239/" + fname + ".nativeReg"; 61 BufferedReader br = 62 new BufferedReader(new FileReader(filename)); 63 String nfunc; 64 while ((nfunc = br.readLine()) != null) { 65 emitter.addNativeRegistration(nfunc); 66 } 67 } else { 68 emitter.setVersion(version, ext, pack); 69 emitter.emitCode(cfunc, s); 70 } 71 } 72 } 73 main(String[] args)74 public static void main(String[] args) throws Exception { 75 String classPathName = "com/google/android/gles_jni/GLImpl"; 76 boolean useContextPointer = true; 77 78 int aidx = 0; 79 while (args[aidx].charAt(0) == '-') { 80 switch (args[aidx].charAt(1)) { 81 case 'c': 82 useContextPointer = false; 83 break; 84 85 default: 86 System.err.println("Unknown flag: " + args[aidx]); 87 System.exit(1); 88 } 89 90 aidx++; 91 } 92 93 System.out.println("useContextPointer = " + useContextPointer); 94 95 BufferedReader spec10Reader = 96 new BufferedReader(new FileReader(args[aidx++])); 97 BufferedReader spec10ExtReader = 98 new BufferedReader(new FileReader(args[aidx++])); 99 BufferedReader spec11Reader = 100 new BufferedReader(new FileReader(args[aidx++])); 101 BufferedReader spec11ExtReader = 102 new BufferedReader(new FileReader(args[aidx++])); 103 BufferedReader spec11ExtPackReader = 104 new BufferedReader(new FileReader(args[aidx++])); 105 BufferedReader checksReader = 106 new BufferedReader(new FileReader(args[aidx++])); 107 108 String gl10Filename = "javax/microedition/khronos/opengles/GL10.java"; 109 String gl10ExtFilename = 110 "javax/microedition/khronos/opengles/GL10Ext.java"; 111 String gl11Filename = "javax/microedition/khronos/opengles/GL11.java"; 112 String gl11ExtFilename = 113 "javax/microedition/khronos/opengles/GL11Ext.java"; 114 String gl11ExtPackFilename = 115 "javax/microedition/khronos/opengles/GL11ExtensionPack.java"; 116 String glImplFilename = "com/google/android/gles_jni/GLImpl.java"; 117 String cFilename = "com_google_android_gles_jni_GLImpl.cpp"; 118 119 PrintStream gl10Stream = 120 new PrintStream(new FileOutputStream("out/" + gl10Filename)); 121 PrintStream gl10ExtStream = 122 new PrintStream(new FileOutputStream("out/" + gl10ExtFilename)); 123 PrintStream gl11Stream = 124 new PrintStream(new FileOutputStream("out/" + gl11Filename)); 125 PrintStream gl11ExtStream = 126 new PrintStream(new FileOutputStream("out/" + gl11ExtFilename)); 127 PrintStream gl11ExtPackStream = 128 new PrintStream(new FileOutputStream("out/" + gl11ExtPackFilename)); 129 PrintStream glImplStream = 130 new PrintStream(new FileOutputStream("out/" + glImplFilename)); 131 PrintStream cStream = 132 new PrintStream(new FileOutputStream("out/" + cFilename)); 133 134 ParameterChecker checker = new ParameterChecker(checksReader); 135 136 CodeEmitter emitter = 137 new Jsr239CodeEmitter(classPathName, 138 checker, 139 gl10Stream, gl10ExtStream, 140 gl11Stream, gl11ExtStream, gl11ExtPackStream, 141 glImplStream, cStream, 142 useContextPointer); 143 144 gl10Stream.println("/* //device/java/android/" + gl10Filename); 145 gl10ExtStream.println("/* //device/java/android/" + gl10ExtFilename); 146 gl11Stream.println("/* //device/java/android/" + gl11Filename); 147 gl11ExtStream.println("/* //device/java/android/" + gl11ExtFilename); 148 gl11ExtPackStream.println("/* //device/java/android/" + 149 gl11ExtPackFilename); 150 glImplStream.println("/* //device/java/android/" + glImplFilename); 151 cStream.println("/* //device/libs/android_runtime/" + cFilename); 152 153 copy("stubs/jsr239/GL10Header.java-if", gl10Stream); 154 copy("stubs/jsr239/GL10ExtHeader.java-if", gl10ExtStream); 155 copy("stubs/jsr239/GL11Header.java-if", gl11Stream); 156 copy("stubs/jsr239/GL11ExtHeader.java-if", gl11ExtStream); 157 copy("stubs/jsr239/GL11ExtensionPackHeader.java-if", gl11ExtPackStream); 158 copy("stubs/jsr239/GLImplHeader.java-impl", glImplStream); 159 copy("stubs/jsr239/GLCHeader.cpp", cStream); 160 161 emit(0, false, false, 162 emitter, spec10Reader, gl10Stream, glImplStream, cStream); 163 emit(0, true, false, 164 emitter, spec10ExtReader, gl10ExtStream, glImplStream, cStream); 165 emit(1, false, false, 166 emitter, spec11Reader, gl11Stream, glImplStream, cStream); 167 emit(1, true, false, 168 emitter, spec11ExtReader, gl11ExtStream, glImplStream, cStream); 169 emit(1, true, true, 170 emitter, spec11ExtPackReader, gl11ExtPackStream, glImplStream, 171 cStream); 172 173 emitter.emitNativeRegistration(); 174 175 gl10Stream.println("}"); 176 gl10ExtStream.println("}"); 177 gl11Stream.println("}"); 178 gl11ExtStream.println("}"); 179 gl11ExtPackStream.println("}"); 180 glImplStream.println("}"); 181 } 182 } 183