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

Commit 304b1f54 authored by Alex Sakhartchouk's avatar Alex Sakhartchouk
Browse files

Allocation copy functions.

Change-Id: Idce6d44a4f4bb2e399284a40c0f90dc1bff912fd
parent bd3e5379
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -16495,6 +16495,7 @@ package android.renderscript {
    method public void copy1DRangeFrom(int, int, short[]);
    method public void copy1DRangeFrom(int, int, byte[]);
    method public void copy1DRangeFrom(int, int, float[]);
    method public void copy1DRangeFrom(int, int, android.renderscript.Allocation, int);
    method public void copy1DRangeFromUnchecked(int, int, int[]);
    method public void copy1DRangeFromUnchecked(int, int, short[]);
    method public void copy1DRangeFromUnchecked(int, int, byte[]);
@@ -16503,6 +16504,7 @@ package android.renderscript {
    method public void copy2DRangeFrom(int, int, int, int, short[]);
    method public void copy2DRangeFrom(int, int, int, int, int[]);
    method public void copy2DRangeFrom(int, int, int, int, float[]);
    method public void copy2DRangeFrom(int, int, int, int, android.renderscript.Allocation, int, int);
    method public void copy2DRangeFrom(int, int, android.graphics.Bitmap);
    method public void copyFrom(android.renderscript.BaseObj[]);
    method public void copyFrom(int[]);
@@ -16567,8 +16569,10 @@ package android.renderscript {
    method public void subData1D(int, int, short[]);
    method public void subData1D(int, int, byte[]);
    method public void subData1D(int, int, float[]);
    method public void subData1D(int, int, android.renderscript.AllocationAdapter, int);
    method public void subData2D(int, int, int, int, int[]);
    method public void subData2D(int, int, int, int, float[]);
    method public void subData2D(int, int, int, int, android.renderscript.AllocationAdapter, int, int);
    method public void subElementData(int, int, android.renderscript.FieldPacker);
  }
+41 −4
Original line number Diff line number Diff line
@@ -588,13 +588,29 @@ public class Allocation extends BaseObj {
     *
     * @param off The offset of the first element to be copied.
     * @param count The number of elements to be copied.
     * @param d the source data array
     * @param d the source data array.
     */
    public void copy1DRangeFrom(int off, int count, float[] d) {
        validateIsFloat32();
        copy1DRangeFromUnchecked(off, count, d);
    }

     /**
     * Copy part of an allocation from another allocation.
     *
     * @param off The offset of the first element to be copied.
     * @param count The number of elements to be copied.
     * @param data the source data allocation.
     * @param dataOff off The offset of the first element in data to
     *          be copied.
     */
    public void copy1DRangeFrom(int off, int count, Allocation data, int dataOff) {
        mRS.nAllocationData2D(getID(), off, 0,
                              0, Type.CubemapFace.POSITVE_X.mID,
                              count, 1, data.getID(), dataOff, 0,
                              0, Type.CubemapFace.POSITVE_X.mID);
    }

    private void validate2DRange(int xoff, int yoff, int w, int h) {
        if (xoff < 0 || yoff < 0) {
            throw new RSIllegalArgumentException("Offset cannot be negative.");
@@ -609,9 +625,8 @@ public class Allocation extends BaseObj {
    }

    /**
     * Copy a rectanglular region from the array into the
     * allocation.  The incoming array is assumed to be tightly
     * packed.
     * Copy a rectangular region from the array into the allocation.
     * The incoming array is assumed to be tightly packed.
     *
     * @param xoff X offset of the region to update
     * @param yoff Y offset of the region to update
@@ -643,6 +658,28 @@ public class Allocation extends BaseObj {
        mRS.nAllocationData2D(getID(), xoff, yoff, 0, 0, w, h, data, data.length * 4);
    }

    /**
     * Copy a rectangular region into the allocation from another
     * allocation.
     *
     * @param xoff X offset of the region to update.
     * @param yoff Y offset of the region to update.
     * @param w Width of the incoming region to update.
     * @param h Height of the incoming region to update.
     * @param data source allocation.
     * @param dataXoff X offset in data of the region to update.
     * @param dataYoff Y offset in data of the region to update.
     */
    public void copy2DRangeFrom(int xoff, int yoff, int w, int h,
                                Allocation data, int dataXoff, int dataYoff) {
        mRS.validate();
        validate2DRange(xoff, yoff, w, h);
        mRS.nAllocationData2D(getID(), xoff, yoff,
                              0, Type.CubemapFace.POSITVE_X.mID,
                              w, h, data.getID(), dataXoff, dataYoff,
                              0, Type.CubemapFace.POSITVE_X.mID);
    }

    /**
     * Copy a bitmap into an allocation.  The height and width of
     * the update will use the height and width of the incoming
+45 −3
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ public class AllocationAdapter extends Allocation {
    private Allocation mAlloc;

    private int mSelectedLOD = 0;
    private Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITVE_X;;
    private Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITVE_X;

    AllocationAdapter(int id, RenderScript rs, Allocation alloc) {
        super(id, rs, null, alloc.mUsage);
@@ -163,15 +163,54 @@ public class AllocationAdapter extends Allocation {
        mRS.nAllocationData1D(getID(), off, mSelectedLOD, count, d, dataSize);
    }

    /**
     * Copy part of an allocation from another allocation.
     *
     * @param off The offset of the first element to be copied.
     * @param count The number of elements to be copied.
     * @param data the source data allocation.
     * @param dataOff off The offset of the first element in data to
     *          be copied.
     */
    public void subData1D(int off, int count, AllocationAdapter data, int dataOff) {
        mRS.nAllocationData2D(getID(), off, 0,
                              mSelectedLOD, mSelectedFace.mID,
                              count, 1, data.getID(), dataOff, 0,
                              data.mSelectedLOD, data.mSelectedFace.mID);
    }


    public void subData2D(int xoff, int yoff, int w, int h, int[] d) {
        mRS.validate();
        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4);
        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
                              w, h, d, d.length * 4);
    }

    public void subData2D(int xoff, int yoff, int w, int h, float[] d) {
        mRS.validate();
        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, d, d.length * 4);
        mRS.nAllocationData2D(getID(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
                              w, h, d, d.length * 4);
    }

    /**
     * Copy a rectangular region into the allocation from another
     * allocation.
     *
     * @param xoff X offset of the region to update.
     * @param yoff Y offset of the region to update.
     * @param w Width of the incoming region to update.
     * @param h Height of the incoming region to update.
     * @param data source allocation.
     * @param dataXoff X offset in data of the region to update.
     * @param dataYoff Y offset in data of the region to update.
     */
    public void subData2D(int xoff, int yoff, int w, int h,
                          AllocationAdapter data, int dataXoff, int dataYoff) {
        mRS.validate();
        mRS.nAllocationData2D(getID(), xoff, yoff,
                              mSelectedLOD, mSelectedFace.mID,
                              w, h, data.getID(), dataXoff, dataYoff,
                              data.mSelectedLOD, data.mSelectedFace.mID);
    }

    public void readData(int[] d) {
@@ -185,12 +224,15 @@ public class AllocationAdapter extends Allocation {
    }

    public void setLOD(int lod) {
        mSelectedLOD = lod;
    }

    public void setFace(Type.CubemapFace cf) {
        mSelectedFace = cf;
    }

    public void setY(int y) {
        mSelectedDimY = y;
    }

    public void setZ(int z) {
+20 −0
Original line number Diff line number Diff line
@@ -295,6 +295,26 @@ public class RenderScript {
        rsnAllocationElementData1D(mContext, id, xoff, mip, compIdx, d, sizeBytes);
    }

    native void rsnAllocationData2D(int con,
                                    int dstAlloc, int dstXoff, int dstYoff,
                                    int dstMip, int dstFace,
                                    int width, int height,
                                    int srcAlloc, int srcXoff, int srcYoff,
                                    int srcMip, int srcFace);
    synchronized void nAllocationData2D(int dstAlloc, int dstXoff, int dstYoff,
                                        int dstMip, int dstFace,
                                        int width, int height,
                                        int srcAlloc, int srcXoff, int srcYoff,
                                        int srcMip, int srcFace) {
        validate();
        rsnAllocationData2D(mContext,
                            dstAlloc, dstXoff, dstYoff,
                            dstMip, dstFace,
                            width, height,
                            srcAlloc, srcXoff, srcYoff,
                            srcMip, srcFace);
    }

    native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes);
    synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, byte[] d, int sizeBytes) {
        validate();
+26 −1
Original line number Diff line number Diff line
@@ -468,7 +468,7 @@ nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc
    bitmap.lockPixels();
    const void* ptr = bitmap.getPixels();
    rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
                       0, RS_ALLOCATION_CUBMAP_FACE_POSITVE_X,
                       0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
                       w, h, ptr, bitmap.getSize());
    bitmap.unlockPixels();
}
@@ -588,6 +588,30 @@ nAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint
    _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
}

static void
nAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
                        jint dstAlloc, jint dstXoff, jint dstYoff,
                        jint dstMip, jint dstFace,
                        jint width, jint height,
                        jint srcAlloc, jint srcXoff, jint srcYoff,
                        jint srcMip, jint srcFace)
{
    LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff, dstYoff,"
            " dstMip(%i), dstFace(%i), width(%i), height(%i),"
            " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
            con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
            width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);

    rsAllocationCopy2DRange(con,
                            (RsAllocation)dstAlloc,
                            dstXoff, dstYoff,
                            dstMip, dstFace,
                            width, height,
                            (RsAllocation)srcAlloc,
                            srcXoff, srcYoff,
                            srcMip, srcFace);
}

static void
nAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
{
@@ -1217,6 +1241,7 @@ static JNINativeMethod methods[] = {
{"rsnAllocationData2D",              "(IIIIIIII[SI)V",                        (void*)nAllocationData2D_s },
{"rsnAllocationData2D",              "(IIIIIIII[BI)V",                        (void*)nAllocationData2D_b },
{"rsnAllocationData2D",              "(IIIIIIII[FI)V",                        (void*)nAllocationData2D_f },
{"rsnAllocationData2D",              "(IIIIIIIIIIIII)V",                      (void*)nAllocationData2D_alloc },
{"rsnAllocationRead",                "(II[I)V",                               (void*)nAllocationRead_i },
{"rsnAllocationRead",                "(II[S)V",                               (void*)nAllocationRead_s },
{"rsnAllocationRead",                "(II[B)V",                               (void*)nAllocationRead_b },
Loading