API reaview cleanup

Change-Id: Ib1aaf81130ffa6b5e6c60096c27c969e8891db3f
diff --git a/graphics/java/android/renderscript/FieldPacker.java b/graphics/java/android/renderscript/FieldPacker.java
index ff3e22b..ed16451 100644
--- a/graphics/java/android/renderscript/FieldPacker.java
+++ b/graphics/java/android/renderscript/FieldPacker.java
@@ -248,24 +248,45 @@
         addU32(v.w);
     }
 
+    // to be removed on cleanup
     public void addObj(Matrix4f v) {
         for (int i=0; i < v.mMat.length; i++) {
             addF32(v.mMat[i]);
         }
     }
 
+    // to be removed on cleanup
     public void addObj(Matrix3f v) {
         for (int i=0; i < v.mMat.length; i++) {
             addF32(v.mMat[i]);
         }
     }
 
+    // to be removed on cleanup
     public void addObj(Matrix2f v) {
         for (int i=0; i < v.mMat.length; i++) {
             addF32(v.mMat[i]);
         }
     }
 
+    public void addMatrix(Matrix4f v) {
+        for (int i=0; i < v.mMat.length; i++) {
+            addF32(v.mMat[i]);
+        }
+    }
+
+    public void addMatrix(Matrix3f v) {
+        for (int i=0; i < v.mMat.length; i++) {
+            addF32(v.mMat[i]);
+        }
+    }
+
+    public void addMatrix(Matrix2f v) {
+        for (int i=0; i < v.mMat.length; i++) {
+            addF32(v.mMat[i]);
+        }
+    }
+
     public void addBoolean(boolean v) {
         addI8((byte)(v ? 1 : 0));
     }
diff --git a/graphics/java/android/renderscript/FileA3D.java b/graphics/java/android/renderscript/FileA3D.java
index af85d8e..c3e5faf 100644
--- a/graphics/java/android/renderscript/FileA3D.java
+++ b/graphics/java/android/renderscript/FileA3D.java
@@ -16,11 +16,12 @@
 
 package android.renderscript;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 
-import android.content.res.Resources;
 import android.content.res.AssetManager;
+import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.util.Log;
@@ -32,28 +33,33 @@
  **/
 public class FileA3D extends BaseObj {
 
+    // This will go away in the clean up pass,
+    // trying to avoid multiproject submits
     public enum ClassID {
 
         UNKNOWN,
-        MESH,
-        TYPE,
-        ELEMENT,
-        ALLOCATION,
-        PROGRAM_VERTEX,
-        PROGRAM_RASTER,
-        PROGRAM_FRAGMENT,
-        PROGRAM_STORE,
-        SAMPLER,
-        ANIMATION,
-        ADAPTER_1D,
-        ADAPTER_2D,
-        SCRIPT_C;
+        MESH;
 
         public static ClassID toClassID(int intID) {
             return ClassID.values()[intID];
         }
     }
 
+    public enum EntryType {
+
+        UNKNOWN (0),
+        MESH (1);
+
+        int mID;
+        EntryType(int id) {
+            mID = id;
+        }
+
+        static EntryType toEntryType(int intID) {
+            return EntryType.values()[intID];
+        }
+    }
+
     // Read only class with index entries
     public static class IndexEntry {
         RenderScript mRS;
@@ -61,6 +67,7 @@
         int mID;
         String mName;
         ClassID mClassID;
+        EntryType mEntryType;
         BaseObj mLoadedObj;
 
         public String getName() {
@@ -71,18 +78,27 @@
             return mClassID;
         }
 
+        public EntryType getEntryType() {
+            return mEntryType;
+        }
+
         public BaseObj getObject() {
             mRS.validate();
             BaseObj obj = internalCreate(mRS, this);
             return obj;
         }
 
+        public Mesh getMesh() {
+            return (Mesh)getObject();
+        }
+
         static synchronized BaseObj internalCreate(RenderScript rs, IndexEntry entry) {
             if(entry.mLoadedObj != null) {
                 return entry.mLoadedObj;
             }
 
-            if(entry.mClassID == ClassID.UNKNOWN) {
+            // to be purged on cleanup
+            if(entry.mEntryType == EntryType.UNKNOWN) {
                 return null;
             }
 
@@ -91,51 +107,23 @@
                 return null;
             }
 
-            switch (entry.mClassID) {
+            switch (entry.mEntryType) {
             case MESH:
                 entry.mLoadedObj = new Mesh(objectID, rs);
                 break;
-            case TYPE:
-                entry.mLoadedObj = new Type(objectID, rs);
-                break;
-            case ELEMENT:
-                entry.mLoadedObj = null;
-                break;
-            case ALLOCATION:
-                entry.mLoadedObj = null;
-                break;
-            case PROGRAM_VERTEX:
-                entry.mLoadedObj = new ProgramVertex(objectID, rs);
-                break;
-            case PROGRAM_RASTER:
-                break;
-            case PROGRAM_FRAGMENT:
-                break;
-            case PROGRAM_STORE:
-                break;
-            case SAMPLER:
-                break;
-            case ANIMATION:
-                break;
-            case ADAPTER_1D:
-                break;
-            case ADAPTER_2D:
-                break;
-            case SCRIPT_C:
-                break;
             }
 
             entry.mLoadedObj.updateFromNative();
-
             return entry.mLoadedObj;
         }
 
-        IndexEntry(RenderScript rs, int index, int id, String name, ClassID classID) {
+        IndexEntry(RenderScript rs, int index, int id, String name, EntryType type) {
             mRS = rs;
             mIndex = index;
             mID = id;
             mName = name;
-            mClassID = classID;
+            mEntryType = type;
+            mClassID = mEntryType == EntryType.MESH ? ClassID.MESH : ClassID.UNKNOWN;
             mLoadedObj = null;
         }
     }
@@ -161,11 +149,11 @@
         mRS.nFileA3DGetIndexEntries(getID(), numFileEntries, ids, names);
 
         for(int i = 0; i < numFileEntries; i ++) {
-            mFileEntries[i] = new IndexEntry(mRS, i, getID(), names[i], ClassID.toClassID(ids[i]));
+            mFileEntries[i] = new IndexEntry(mRS, i, getID(), names[i], EntryType.toEntryType(ids[i]));
         }
     }
 
-    public int getNumIndexEntries() {
+    public int getIndexEntryCount() {
         if(mFileEntries == null) {
             return 0;
         }
@@ -173,12 +161,29 @@
     }
 
     public IndexEntry getIndexEntry(int index) {
-        if(getNumIndexEntries() == 0 || index < 0 || index >= mFileEntries.length) {
+        if(getIndexEntryCount() == 0 || index < 0 || index >= mFileEntries.length) {
             return null;
         }
         return mFileEntries[index];
     }
 
+    // API cleanup stand-ins
+    // TODO: implement ermaining loading mechanisms
+    static public FileA3D createFromAsset(RenderScript rs, AssetManager mgr, String path)
+        throws IllegalArgumentException {
+        return null;
+    }
+
+    static public FileA3D createFromFile(RenderScript rs, String path)
+        throws IllegalArgumentException {
+        return null;
+    }
+
+    static public FileA3D createFromFile(RenderScript rs, File path)
+        throws IllegalArgumentException {
+        return createFromFile(rs, path.getAbsolutePath());
+    }
+
     static public FileA3D createFromResource(RenderScript rs, Resources res, int id)
         throws IllegalArgumentException {
 
diff --git a/graphics/java/android/renderscript/Font.java b/graphics/java/android/renderscript/Font.java
index de25014..0f7c24d 100644
--- a/graphics/java/android/renderscript/Font.java
+++ b/graphics/java/android/renderscript/Font.java
@@ -16,13 +16,16 @@
 
 package android.renderscript;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
 
-import android.content.res.Resources;
+import android.os.Environment;
+
 import android.content.res.AssetManager;
+import android.content.res.Resources;
 import android.util.Log;
 import android.util.TypedValue;
 
@@ -126,13 +129,13 @@
     /**
      * Takes a specific file name as an argument
      */
-    static public Font create(RenderScript rs, Resources res, String fileName, int size)
+    static public Font createFromFile(RenderScript rs, Resources res, String path, float pointSize)
         throws IllegalArgumentException {
 
         rs.validate();
         try {
             int dpi = res.getDisplayMetrics().densityDpi;
-            int fontId = rs.nFontCreateFromFile(fileName, size, dpi);
+            int fontId = rs.nFontCreateFromFile(path, pointSize, dpi);
 
             if(fontId == 0) {
                 throw new IllegalStateException("Failed loading a font");
@@ -148,6 +151,21 @@
         return null;
     }
 
+    static public Font createFromFile(RenderScript rs, Resources res, File path, float pointSize)
+        throws IllegalArgumentException {
+        return createFromFile(rs, res, path.getAbsolutePath(), pointSize);
+    }
+
+    static public Font createFromAsset(RenderScript rs, Resources res, AssetManager mgr, String path, float pointSize)
+        throws IllegalArgumentException {
+        return null;
+    }
+
+    static public Font createFromResource(RenderScript rs, Resources res, int id, float pointSize)
+        throws IllegalArgumentException {
+        return null;
+    }
+
     /**
      * Accepts one of the following family names as an argument
      * and will attemp to produce the best match with a system font
@@ -157,9 +175,12 @@
      * "monospace" "courier" "courier new" "monaco"
      * Returns default font if no match could be found
      */
-    static public Font createFromFamily(RenderScript rs, Resources res, String familyName, Style fontStyle, int size)
+    static public Font create(RenderScript rs, Resources res, String familyName, Style fontStyle, float pointSize)
     throws IllegalArgumentException {
         String fileName = getFontFileName(familyName, fontStyle);
-        return create(rs, res, fileName, size);
+        String fontPath = Environment.getRootDirectory().getAbsolutePath();
+        fontPath += "/fonts/" + fileName;
+        return createFromFile(rs, res, fontPath, pointSize);
     }
+
 }
diff --git a/graphics/java/android/renderscript/Matrix2f.java b/graphics/java/android/renderscript/Matrix2f.java
index 99d23db..4654c48 100644
--- a/graphics/java/android/renderscript/Matrix2f.java
+++ b/graphics/java/android/renderscript/Matrix2f.java
@@ -31,6 +31,15 @@
         loadIdentity();
     }
 
+    public Matrix2f(float[] dataArray) {
+        mMat = new float[2];
+        System.arraycopy(dataArray, 0, mMat, 0, mMat.length);
+    }
+
+    public float[] getArray() {
+        return mMat;
+    }
+
     public float get(int i, int j) {
         return mMat[i*2 + j];
     }
diff --git a/graphics/java/android/renderscript/Matrix3f.java b/graphics/java/android/renderscript/Matrix3f.java
index 961bc5d..15e5ce6 100644
--- a/graphics/java/android/renderscript/Matrix3f.java
+++ b/graphics/java/android/renderscript/Matrix3f.java
@@ -31,6 +31,15 @@
         loadIdentity();
     }
 
+    public Matrix3f(float[] dataArray) {
+        mMat = new float[9];
+        System.arraycopy(dataArray, 0, mMat, 0, mMat.length);
+    }
+
+    public float[] getArray() {
+        return mMat;
+    }
+
     public float get(int i, int j) {
         return mMat[i*3 + j];
     }
diff --git a/graphics/java/android/renderscript/Matrix4f.java b/graphics/java/android/renderscript/Matrix4f.java
index 5ffc21a..ea97509 100644
--- a/graphics/java/android/renderscript/Matrix4f.java
+++ b/graphics/java/android/renderscript/Matrix4f.java
@@ -31,6 +31,15 @@
         loadIdentity();
     }
 
+    public Matrix4f(float[] dataArray) {
+        mMat = new float[16];
+        System.arraycopy(dataArray, 0, mMat, 0, mMat.length);
+    }
+
+    public float[] getArray() {
+        return mMat;
+    }
+
     public float get(int i, int j) {
         return mMat[i*4 + j];
     }
@@ -147,6 +156,10 @@
         mMat[14]= -(f + n) / (f - n);
     }
 
+    public void loadOrthoWindow(int w, int h) {
+        loadOrtho(0,w, h,0, -1,1);
+    }
+
     public void loadFrustum(float l, float r, float b, float t, float n, float f) {
         loadIdentity();
         mMat[0] = 2 * n / (r - l);
@@ -159,6 +172,14 @@
         mMat[15]= 0;
     }
 
+    public void loadPerspective(float fovy, float aspect, float near, float far) {
+        float top = near * (float)Math.tan((float) (fovy * Math.PI / 360.0f));
+        float bottom = -top;
+        float left = bottom * aspect;
+        float right = top * aspect;
+        loadFrustum(left, right, bottom, top, near, far);
+    }
+
     public void multiply(Matrix4f rhs) {
         Matrix4f tmp = new Matrix4f();
         tmp.loadMultiply(this, rhs);
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 5f93f5b..0b7262b 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -305,8 +305,8 @@
         return rsnFileA3DGetEntryByIndex(mContext, fileA3D, index);
     }
 
-    native int  rsnFontCreateFromFile(int con, String fileName, int size, int dpi);
-    synchronized int nFontCreateFromFile(String fileName, int size, int dpi) {
+    native int  rsnFontCreateFromFile(int con, String fileName, float size, int dpi);
+    synchronized int nFontCreateFromFile(String fileName, float size, int dpi) {
         return rsnFontCreateFromFile(mContext, fileName, size, dpi);
     }