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

Commit dfac814c authored by Alex Sakhartchouk's avatar Alex Sakhartchouk
Browse files

Populate java objects with native data from a3d file.

Remove legacy constructor from programraster
Make a3d object creation synchronous

Change-Id: Ic7d7547cf6eee6f9a7c6e3ee12cd104e80056a7b
parent 506821b4
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -45,6 +45,16 @@ public class Allocation extends BaseObj {
        mID = id;
    }

    @Override
    void updateFromNative() {
        mRS.validate();
        int typeID = mRS.nAllocationGetType(mID);
        if(typeID != 0) {
            mType = new Type(typeID, mRS);
            mType.updateFromNative();
        }
    }

    public Type getType() {
        return mType;
    }
+40 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.renderscript;

import java.lang.reflect.Field;
import android.util.Log;

/**
 * @hide
@@ -308,6 +309,45 @@ public class Element extends BaseObj {
        mID = rs.nElementCreate(dt.mID, dk.mID, norm, size);
    }

    Element(RenderScript rs, int id) {
        super(rs);
        mID = id;
    }

    @Override
    void updateFromNative() {

        // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
        int[] dataBuffer = new int[5];
        mRS.nElementGetNativeData(mID, dataBuffer);
        for (DataType dt: DataType.values()) {
            if(dt.mID == dataBuffer[0]){
                mType = dt;
            }
        }
        for (DataKind dk: DataKind.values()) {
            if(dk.mID == dataBuffer[1]){
                mKind = dk;
            }
        }

        mNormalized = dataBuffer[2] == 1 ? true : false;
        mVectorSize = dataBuffer[3];
        int numSubElements = dataBuffer[4];
        if(numSubElements > 0) {
            mElements = new Element[numSubElements];
            mElementNames = new String[numSubElements];

            int[] subElementIds = new int[numSubElements];
            mRS.nElementGetSubElements(mID, subElementIds, mElementNames);
            for(int i = 0; i < numSubElements; i ++) {
                mElements[i] = new Element(mRS, subElementIds[i]);
                mElements[i].updateFromNative();
            }
        }

    }

    public void destroy() throws IllegalStateException {
        super.destroy();
    }
+20 −12
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ public class FileA3D extends BaseObj {
    }

    // Read only class with index entries
    public class IndexEntry {
    public static class IndexEntry {
        RenderScript mRS;
        int mIndex;
        int mID;
@@ -73,34 +73,40 @@ public class FileA3D extends BaseObj {
        }

        public BaseObj getObject() {
            if(mLoadedObj != null) {
                return mLoadedObj;
            mRS.validate();
            BaseObj obj = internalCreate(mRS, this);
            return obj;
        }

            if(mClassID == ClassID.UNKNOWN) {
        static synchronized BaseObj internalCreate(RenderScript rs, IndexEntry entry) {
            if(entry.mLoadedObj != null) {
                return entry.mLoadedObj;
            }

            if(entry.mClassID == ClassID.UNKNOWN) {
                return null;
            }

            int objectID = mRS.nFileA3DGetEntryByIndex(mID, mIndex);
            int objectID = rs.nFileA3DGetEntryByIndex(entry.mID, entry.mIndex);
            if(objectID == 0) {
                return null;
            }

            switch (mClassID) {
            switch (entry.mClassID) {
            case MESH:
                mLoadedObj = new Mesh(objectID, mRS);
                entry.mLoadedObj = new Mesh(objectID, rs);
                break;
            case TYPE:
                mLoadedObj = new Type(objectID, mRS);
                entry.mLoadedObj = new Type(objectID, rs);
                break;
            case ELEMENT:
                mLoadedObj = null;
                entry.mLoadedObj = null;
                break;
            case ALLOCATION:
                mLoadedObj = null;
                entry.mLoadedObj = null;
                break;
            case PROGRAM_VERTEX:
                mLoadedObj = new ProgramVertex(objectID, mRS);
                entry.mLoadedObj = new ProgramVertex(objectID, rs);
                break;
            case PROGRAM_RASTER:
                break;
@@ -122,7 +128,9 @@ public class FileA3D extends BaseObj {
                break;
            }

            return mLoadedObj;
            entry.mLoadedObj.updateFromNative();

            return entry.mLoadedObj;
        }

        IndexEntry(RenderScript rs, int index, int id, String name, ClassID classID) {
+0 −8
Original line number Diff line number Diff line
@@ -74,14 +74,6 @@ public class ProgramRaster extends BaseObj {
        boolean mPointSmooth;
        boolean mLineSmooth;

        // Legacy to not break app in other projects, will be removed in cleanup pass
        public Builder(RenderScript rs, Element in, Element out) {
            mRS = rs;
            mPointSmooth = false;
            mLineSmooth = false;
            mPointSprite = false;
        }

        public Builder(RenderScript rs) {
            mRS = rs;
            mPointSmooth = false;
+4 −0
Original line number Diff line number Diff line
@@ -90,12 +90,15 @@ public class RenderScript {

    native int  nElementCreate(int type, int kind, boolean norm, int vecSize);
    native int  nElementCreate2(int[] elements, String[] names);
    native void nElementGetNativeData(int id, int[] elementData);
    native void nElementGetSubElements(int id, int[] IDs, String[] names);

    native void nTypeBegin(int elementID);
    native void nTypeAdd(int dim, int val);
    native int  nTypeCreate();
    native void nTypeFinalDestroy(Type t);
    native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
    native void nTypeGetNativeData(int id, int[] typeData);

    native int  nAllocationCreateTyped(int type);
    native int  nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
@@ -117,6 +120,7 @@ public class RenderScript {
    native void nAllocationRead(int id, float[] d);
    native void nAllocationSubDataFromObject(int id, Type t, int offset, Object o);
    native void nAllocationSubReadFromObject(int id, Type t, int offset, Object o);
    native int  nAllocationGetType(int id);

    native int  nFileA3DCreateFromAssetStream(int assetStream);
    native int  nFileA3DGetNumIndexEntries(int fileA3D);
Loading