blob: 2ef3970299dc3c36e7f9de767bded8d996297fdc [file] [log] [blame]
Thomas Tafertshofer66a42db2012-06-15 16:22:43 -07001/*
2 * Copyright 2012 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
17import java.io.BufferedReader;
18import java.io.File;
19import java.io.FileOutputStream;
20import java.io.FileReader;
21import java.io.IOException;
22import java.io.PrintStream;
23
24public class GenerateEGL {
25
26 private 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
34 private static void emit(EGLCodeEmitter emitter,
35 BufferedReader specReader,
36 PrintStream glStream,
37 PrintStream cStream) throws Exception {
38 String s = null;
39 while ((s = specReader.readLine()) != null) {
40 if (s.trim().startsWith("//")) {
41 continue;
42 }
43
44 CFunc cfunc = CFunc.parseCFunc(s);
45
46 String fname = cfunc.getName();
47 String stubRoot = "stubs/egl/" + fname;
48 String javaPath = stubRoot + ".java";
49 File f = new File(javaPath);
50 if (f.exists()) {
51 System.out.println("Special-casing function " + fname);
52 copy(javaPath, glStream);
53 copy(stubRoot + ".cpp", cStream);
54
55 // Register native function names
56 // This should be improved to require fewer discrete files
57 String filename = stubRoot + ".nativeReg";
58 BufferedReader br =
59 new BufferedReader(new FileReader(filename));
60 String nfunc;
61 while ((nfunc = br.readLine()) != null) {
62 emitter.addNativeRegistration(nfunc);
63 }
64 } else {
65 emitter.emitCode(cfunc, s);
66 }
67 }
68 }
69
70 public static void main(String[] args) throws Exception {
71 int aidx = 0;
72 while ((aidx < args.length) && (args[aidx].charAt(0) == '-')) {
73 switch (args[aidx].charAt(1)) {
74 default:
75 System.err.println("Unknown flag: " + args[aidx]);
76 System.exit(1);
77 }
78
79 aidx++;
80 }
81
82 BufferedReader checksReader =
83 new BufferedReader(new FileReader("specs/egl/checks.spec"));
84 ParameterChecker checker = new ParameterChecker(checksReader);
85
86
Jesse Hallc8639352013-04-30 13:45:14 -070087 for(String suffix: new String[] {"EGL14", "EGLExt"}) {
88 BufferedReader specReader = new BufferedReader(new FileReader(
89 "specs/egl/" + suffix + ".spec"));
90 String egljFilename = "android/opengl/" + suffix + ".java";
91 String eglcFilename = "android_opengl_" + suffix + ".cpp";
92 PrintStream egljStream =
93 new PrintStream(new FileOutputStream("out/" + egljFilename));
94 PrintStream eglcStream =
95 new PrintStream(new FileOutputStream("out/" + eglcFilename));
96 copy("stubs/egl/" + suffix + "Header.java-if", egljStream);
97 copy("stubs/egl/" + suffix + "cHeader.cpp", eglcStream);
98 EGLCodeEmitter emitter = new EGLCodeEmitter(
99 "android/opengl/" + suffix,
100 checker, egljStream, eglcStream);
101 emit(emitter, specReader, egljStream, eglcStream);
102 emitter.emitNativeRegistration(
103 "register_android_opengl_jni_" + suffix);
104 egljStream.println("}");
105 egljStream.close();
106 eglcStream.close();
107 }
Thomas Tafertshofer66a42db2012-06-15 16:22:43 -0700108 }
109}