• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 import java.io.PrintStream;
2 
3 /**
4  * Emits a Java interface and Java & C implementation for a C function.
5  *
6  * <p> The Java interface will have Buffer and array variants for functions that
7  * have a typed pointer argument.  The array variant will convert a single "<type> *data"
8  * argument to a pair of arguments "<type>[] data, int offset".
9  */
10 public class Jsr239CodeEmitter extends JniCodeEmitter implements CodeEmitter {
11 
12     PrintStream mJava10InterfaceStream;
13     PrintStream mJava10ExtInterfaceStream;
14     PrintStream mJava11InterfaceStream;
15     PrintStream mJava11ExtInterfaceStream;
16     PrintStream mJava11ExtPackInterfaceStream;
17     PrintStream mJavaImplStream;
18     PrintStream mCStream;
19 
20     PrintStream mJavaInterfaceStream;
21 
22     /**
23      * @param java10InterfaceStream the PrintStream to which to emit the Java interface for GL 1.0 functions
24      * @param java10ExtInterfaceStream the PrintStream to which to emit the Java interface for GL 1.0 extension functions
25      * @param java11InterfaceStream the PrintStream to which to emit the Java interface for GL 1.1 functions
26      * @param java11ExtInterfaceStream the PrintStream to which to emit the Java interface for GL 1.1 Extension functions
27      * @param java11ExtPackInterfaceStream the PrintStream to which to emit the Java interface for GL 1.1 Extension Pack functions
28      * @param javaImplStream the PrintStream to which to emit the Java implementation
29      * @param cStream the PrintStream to which to emit the C implementation
30      */
Jsr239CodeEmitter(String classPathName, ParameterChecker checker, PrintStream java10InterfaceStream, PrintStream java10ExtInterfaceStream, PrintStream java11InterfaceStream, PrintStream java11ExtInterfaceStream, PrintStream java11ExtPackInterfaceStream, PrintStream javaImplStream, PrintStream cStream, boolean useContextPointer)31     public Jsr239CodeEmitter(String classPathName,
32                           ParameterChecker checker,
33                           PrintStream java10InterfaceStream,
34                           PrintStream java10ExtInterfaceStream,
35                           PrintStream java11InterfaceStream,
36                           PrintStream java11ExtInterfaceStream,
37                           PrintStream java11ExtPackInterfaceStream,
38                           PrintStream javaImplStream,
39                           PrintStream cStream,
40                           boolean useContextPointer) {
41         mClassPathName = classPathName;
42         mChecker = checker;
43         mJava10InterfaceStream = java10InterfaceStream;
44         mJava10ExtInterfaceStream = java10ExtInterfaceStream;
45         mJava11InterfaceStream = java11InterfaceStream;
46         mJava11ExtInterfaceStream = java11ExtInterfaceStream;
47         mJava11ExtPackInterfaceStream = java11ExtPackInterfaceStream;
48         mJavaImplStream = javaImplStream;
49         mCStream = cStream;
50         mUseContextPointer = useContextPointer;
51     }
52 
setVersion(int version, boolean ext, boolean pack)53     public void setVersion(int version, boolean ext, boolean pack) {
54         if (version == 0) {
55             mJavaInterfaceStream = ext ? mJava10ExtInterfaceStream :
56                 mJava10InterfaceStream;
57         } else if (version == 1) {
58             mJavaInterfaceStream = ext ?
59                 (pack ? mJava11ExtPackInterfaceStream :
60                  mJava11ExtInterfaceStream) :
61                 mJava11InterfaceStream;
62         } else {
63             throw new RuntimeException("Bad version: " + version);
64         }
65     }
66 
emitCode(CFunc cfunc, String original)67     public void emitCode(CFunc cfunc, String original) {
68         emitCode(cfunc, original, mJavaInterfaceStream, mJavaImplStream, mCStream);
69     }
70 
emitNativeRegistration()71     public void emitNativeRegistration() {
72         emitNativeRegistration("register_com_google_android_gles_jni_GLImpl", mCStream);
73     }
74 }
75