Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2009 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.PrintStream;
     18 
     19 /**
     20  * Emits a Java interface and Java & C implementation for a C function.
     21  *
     22  * <p> The Java interface will have Buffer and array variants for functions that
     23  * have a typed pointer argument.  The array variant will convert a single "<type> *data"
     24  * argument to a pair of arguments "<type>[] data, int offset".
     25  */
     26 public class Jsr239CodeEmitter extends JniCodeEmitter implements CodeEmitter {
     27 
     28     PrintStream mJava10InterfaceStream;
     29     PrintStream mJava10ExtInterfaceStream;
     30     PrintStream mJava11InterfaceStream;
     31     PrintStream mJava11ExtInterfaceStream;
     32     PrintStream mJava11ExtPackInterfaceStream;
     33     PrintStream mJavaImplStream;
     34     PrintStream mCStream;
     35 
     36     PrintStream mJavaInterfaceStream;
     37 
     38     /**
     39      * @param java10InterfaceStream the PrintStream to which to emit the Java interface for GL 1.0 functions
     40      * @param java10ExtInterfaceStream the PrintStream to which to emit the Java interface for GL 1.0 extension functions
     41      * @param java11InterfaceStream the PrintStream to which to emit the Java interface for GL 1.1 functions
     42      * @param java11ExtInterfaceStream the PrintStream to which to emit the Java interface for GL 1.1 Extension functions
     43      * @param java11ExtPackInterfaceStream the PrintStream to which to emit the Java interface for GL 1.1 Extension Pack functions
     44      * @param javaImplStream the PrintStream to which to emit the Java implementation
     45      * @param cStream the PrintStream to which to emit the C implementation
     46      */
     47     public Jsr239CodeEmitter(String classPathName,
     48                           ParameterChecker checker,
     49                           PrintStream java10InterfaceStream,
     50                           PrintStream java10ExtInterfaceStream,
     51                           PrintStream java11InterfaceStream,
     52                           PrintStream java11ExtInterfaceStream,
     53                           PrintStream java11ExtPackInterfaceStream,
     54                           PrintStream javaImplStream,
     55                           PrintStream cStream,
     56                           boolean useContextPointer) {
     57         mClassPathName = classPathName;
     58         mChecker = checker;
     59         mJava10InterfaceStream = java10InterfaceStream;
     60         mJava10ExtInterfaceStream = java10ExtInterfaceStream;
     61         mJava11InterfaceStream = java11InterfaceStream;
     62         mJava11ExtInterfaceStream = java11ExtInterfaceStream;
     63         mJava11ExtPackInterfaceStream = java11ExtPackInterfaceStream;
     64         mJavaImplStream = javaImplStream;
     65         mCStream = cStream;
     66         mUseContextPointer = useContextPointer;
     67     }
     68 
     69     public void setVersion(int version, boolean ext, boolean pack) {
     70         if (version == 0) {
     71             mJavaInterfaceStream = ext ? mJava10ExtInterfaceStream :
     72                 mJava10InterfaceStream;
     73         } else if (version == 1) {
     74             mJavaInterfaceStream = ext ?
     75                 (pack ? mJava11ExtPackInterfaceStream :
     76                  mJava11ExtInterfaceStream) :
     77                 mJava11InterfaceStream;
     78         } else {
     79             throw new RuntimeException("Bad version: " + version);
     80         }
     81     }
     82 
     83     public void emitCode(CFunc cfunc, String original) {
     84         emitCode(cfunc, original, mJavaInterfaceStream, mJavaImplStream, mCStream);
     85     }
     86 
     87     public void emitNativeRegistration() {
     88         emitNativeRegistration("register_com_google_android_gles_jni_GLImpl", mCStream);
     89     }
     90 }
     91