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

Commit 460a0497 authored by Tim Murray's avatar Tim Murray
Browse files

Convert Java/JNI to 64-bit, part 2.

This changes BaseObj to support 64-bit IDs. There are a few caveats:

1. Since it is deprecated, RSG will not support 64-bit.
2. Currently, methods that pass arrays of IDs to the driver are not supported in 64-bit. This will be fixed in a later CL.

bug 11332320

Change-Id: If0dbecc8b285e260f767e441e05088b6a1b749a2
parent eff663f3
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -77,8 +77,8 @@ public class Allocation extends BaseObj {
    int mCurrentDimY;
    int mCurrentDimZ;
    int mCurrentCount;
    static HashMap<Integer, Allocation> mAllocationMap =
            new HashMap<Integer, Allocation>();
    static HashMap<Long, Allocation> mAllocationMap =
            new HashMap<Long, Allocation>();
    OnBufferAvailableListener mBufferNotifier;

    /**
@@ -187,7 +187,7 @@ public class Allocation extends BaseObj {
    }


    private int getIDSafe() {
    private long getIDSafe() {
        if (mAdaptedAllocation != null) {
            return mAdaptedAllocation.getID(mRS);
        }
@@ -243,7 +243,7 @@ public class Allocation extends BaseObj {
        mBitmap = b;
    }

    Allocation(int id, RenderScript rs, Type t, int usage) {
    Allocation(long id, RenderScript rs, Type t, int usage) {
        super(id, rs);
        if ((usage & ~(USAGE_SCRIPT |
                       USAGE_GRAPHICS_TEXTURE |
@@ -344,7 +344,7 @@ public class Allocation extends BaseObj {
    @Override
    void updateFromNative() {
        super.updateFromNative();
        int typeID = mRS.nAllocationGetType(getID(mRS));
        long typeID = mRS.nAllocationGetType(getID(mRS));
        if(typeID != 0) {
            mType = new Type(typeID, mRS);
            mType.updateFromNative();
@@ -439,9 +439,11 @@ public class Allocation extends BaseObj {
            throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " +
                                                 mCurrentCount + ", array length = " + d.length);
        }
        // FIXME: requires 64-bit path

        int i[] = new int[d.length];
        for (int ct=0; ct < d.length; ct++) {
            i[ct] = d[ct].getID(mRS);
            i[ct] = (int)d[ct].getID(mRS);
        }
        copy1DRangeFromUnchecked(0, mCurrentCount, i);
        Trace.traceEnd(RenderScript.TRACE_TAG);
@@ -1333,7 +1335,7 @@ public class Allocation extends BaseObj {
        mRS.nAllocationResize1D(getID(mRS), dimX);
        mRS.finish();  // Necessary because resize is fifoed and update is async.

        int typeID = mRS.nAllocationGetType(getID(mRS));
        long typeID = mRS.nAllocationGetType(getID(mRS));
        mType = new Type(typeID, mRS);
        mType.updateFromNative();
        updateCacheInfo(mType);
@@ -1363,7 +1365,7 @@ public class Allocation extends BaseObj {
        if (type.getID(rs) == 0) {
            throw new RSInvalidStateException("Bad Type");
        }
        int id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0);
        long id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0);
        if (id == 0) {
            throw new RSRuntimeException("Allocation creation failed.");
        }
@@ -1418,7 +1420,7 @@ public class Allocation extends BaseObj {
        b.setX(count);
        Type t = b.create();

        int id = rs.nAllocationCreateTyped(t.getID(rs), MipmapControl.MIPMAP_NONE.mID, usage, 0);
        long id = rs.nAllocationCreateTyped(t.getID(rs), MipmapControl.MIPMAP_NONE.mID, usage, 0);
        if (id == 0) {
            throw new RSRuntimeException("Allocation creation failed.");
        }
@@ -1502,7 +1504,7 @@ public class Allocation extends BaseObj {
        if (mips == MipmapControl.MIPMAP_NONE &&
            t.getElement().isCompatible(Element.RGBA_8888(rs)) &&
            usage == (USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE)) {
            int id = rs.nAllocationCreateBitmapBackedAllocation(t.getID(rs), mips.mID, b, usage);
            long id = rs.nAllocationCreateBitmapBackedAllocation(t.getID(rs), mips.mID, b, usage);
            if (id == 0) {
                throw new RSRuntimeException("Load failed.");
            }
@@ -1514,7 +1516,7 @@ public class Allocation extends BaseObj {
        }


        int id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage);
        long id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage);
        if (id == 0) {
            throw new RSRuntimeException("Load failed.");
        }
@@ -1617,7 +1619,7 @@ public class Allocation extends BaseObj {
        tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL);
        Type t = tb.create();

        int id = rs.nAllocationCubeCreateFromBitmap(t.getID(rs), mips.mID, b, usage);
        long id = rs.nAllocationCubeCreateFromBitmap(t.getID(rs), mips.mID, b, usage);
        if(id == 0) {
            throw new RSRuntimeException("Load failed for bitmap " + b + " element " + e);
        }
@@ -1842,14 +1844,14 @@ public class Allocation extends BaseObj {
     */
    public void setOnBufferAvailableListener(OnBufferAvailableListener callback) {
        synchronized(mAllocationMap) {
            mAllocationMap.put(new Integer(getID(mRS)), this);
            mAllocationMap.put(new Long(getID(mRS)), this);
            mBufferNotifier = callback;
        }
    }

    static void sendBufferNotification(int id) {
        synchronized(mAllocationMap) {
            Allocation a = mAllocationMap.get(new Integer(id));
            Allocation a = mAllocationMap.get(new Long(id));

            if ((a != null) && (a.mBufferNotifier != null)) {
                a.mBufferNotifier.onBufferAvailable(a);
+2 −2
Original line number Diff line number Diff line
@@ -26,12 +26,12 @@ import android.util.TypedValue;
 *
 **/
public class AllocationAdapter extends Allocation {
    AllocationAdapter(int id, RenderScript rs, Allocation alloc) {
    AllocationAdapter(long id, RenderScript rs, Allocation alloc) {
        super(id, rs, alloc.mType, alloc.mUsage);
        mAdaptedAllocation = alloc;
    }

    int getID(RenderScript rs) {
    long getID(RenderScript rs) {
        throw new RSInvalidStateException(
            "This operation is not supported with adapters at this time.");
    }
+5 −5
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.util.Log;
 *
 **/
public class BaseObj {
    BaseObj(int id, RenderScript rs) {
    BaseObj(long id, RenderScript rs) {
        rs.validate();
        mRS = rs;
        mID = id;
@@ -46,9 +46,9 @@ public class BaseObj {
     * @param rs Context to verify against internal context for
     *           match.
     *
     * @return int
     * @return long
     */
    int getID(RenderScript rs) {
    long getID(RenderScript rs) {
        mRS.validate();
        if (mDestroyed) {
            throw new RSInvalidStateException("using a destroyed object.");
@@ -68,7 +68,7 @@ public class BaseObj {
        }
    }

    private int mID;
    private long mID;
    private boolean mDestroyed;
    private String mName;
    RenderScript mRS;
@@ -152,7 +152,7 @@ public class BaseObj {
     */
    @Override
    public int hashCode() {
        return mID;
        return (int)((mID & 0xfffffff) ^ (mID >> 32));
    }

    /**
+11 −8
Original line number Diff line number Diff line
@@ -759,7 +759,7 @@ public class Element extends BaseObj {
        return rs.mElement_MATRIX_2X2;
    }

    Element(int id, RenderScript rs, Element[] e, String[] n, int[] as) {
    Element(long id, RenderScript rs, Element[] e, String[] n, int[] as) {
        super(id, rs);
        mSize = 0;
        mVectorSize = 1;
@@ -776,7 +776,7 @@ public class Element extends BaseObj {
        updateVisibleSubElements();
    }

    Element(int id, RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) {
    Element(long id, RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) {
        super(id, rs);
        if ((dt != DataType.UNSIGNED_5_6_5) &&
            (dt != DataType.UNSIGNED_4_4_4_4) &&
@@ -795,7 +795,7 @@ public class Element extends BaseObj {
        mVectorSize = size;
    }

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

@@ -803,6 +803,8 @@ public class Element extends BaseObj {
    void updateFromNative() {
        super.updateFromNative();

        // FIXME: updateFromNative is broken in JNI for 64-bit

        // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
        int[] dataBuffer = new int[5];
        mRS.nElementGetNativeData(getID(mRS), dataBuffer);
@@ -853,7 +855,7 @@ public class Element extends BaseObj {
        DataKind dk = DataKind.USER;
        boolean norm = false;
        int vecSize = 1;
        int id = rs.nElementCreate(dt.mID, dk.mID, norm, vecSize);
        long id = rs.nElementCreate(dt.mID, dk.mID, norm, vecSize);
        return new Element(id, rs, dt, dk, norm, vecSize);
    }

@@ -890,7 +892,7 @@ public class Element extends BaseObj {
        case BOOLEAN: {
            DataKind dk = DataKind.USER;
            boolean norm = false;
            int id = rs.nElementCreate(dt.mID, dk.mID, norm, size);
            long id = rs.nElementCreate(dt.mID, dk.mID, norm, size);
            return new Element(id, rs, dt, dk, norm, size);
        }

@@ -961,7 +963,7 @@ public class Element extends BaseObj {
        }

        boolean norm = true;
        int id = rs.nElementCreate(dt.mID, dk.mID, norm, size);
        long id = rs.nElementCreate(dt.mID, dk.mID, norm, size);
        return new Element(id, rs, dt, dk, norm, size);
    }

@@ -1088,11 +1090,12 @@ public class Element extends BaseObj {
            java.lang.System.arraycopy(mElementNames, 0, sin, 0, mCount);
            java.lang.System.arraycopy(mArraySizes, 0, asin, 0, mCount);

            // FIXME: broken for 64-bit
            int[] ids = new int[ein.length];
            for (int ct = 0; ct < ein.length; ct++ ) {
                ids[ct] = ein[ct].getID(mRS);
                ids[ct] = (int)ein[ct].getID(mRS);
            }
            int id = mRS.nElementCreate2(ids, sin, asin);
            long id = mRS.nElementCreate2(ids, sin, asin);
            return new Element(id, mRS, ein, sin, asin);
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -232,7 +232,8 @@ public class FieldPacker {

    public void addObj(BaseObj obj) {
        if (obj != null) {
            addI32(obj.getID(null));
            // FIXME: this is fine for 32-bit but needs a path for 64-bit
            addI32((int)obj.getID(null));
        } else {
            addI32(0);
        }
Loading