Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7d179eeb authored by Alex Sakhartchouk's avatar Alex Sakhartchouk Committed by Android (Google) Code Review
Browse files

Merge "API reaview cleanup"

parents fbc4939d e27cdeee
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -248,24 +248,45 @@ public class FieldPacker {
        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));
    }
+55 −50
Original line number Diff line number Diff line
@@ -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 @@ import android.util.TypedValue;
 **/
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 @@ public class FileA3D extends BaseObj {
        int mID;
        String mName;
        ClassID mClassID;
        EntryType mEntryType;
        BaseObj mLoadedObj;

        public String getName() {
@@ -71,18 +78,27 @@ public class FileA3D extends BaseObj {
            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 @@ public class FileA3D extends BaseObj {
                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 @@ public class FileA3D extends BaseObj {
        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 class FileA3D extends BaseObj {
    }

    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 {

+27 −6
Original line number Diff line number Diff line
@@ -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.os.Environment;

import android.content.res.Resources;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.util.Log;
import android.util.TypedValue;

@@ -126,13 +129,13 @@ public class Font extends BaseObj {
    /**
     * 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 @@ public class Font extends BaseObj {
        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 @@ public class Font extends BaseObj {
     * "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);
    }

}
+9 −0
Original line number Diff line number Diff line
@@ -31,6 +31,15 @@ public class Matrix2f {
        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];
    }
+9 −0
Original line number Diff line number Diff line
@@ -31,6 +31,15 @@ public class Matrix3f {
        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];
    }
Loading