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

Commit fa1275a6 authored by Stephen Hines's avatar Stephen Hines
Browse files

Create FieldPacker.getPos() to get the actual amount of data used for FP.

We need larger buffers to handle 64-bit RS object types, but 32-bit code
will never fill all of the getData().length bytes. This allows us to retain
our verification code.

We have to modify an existing use of FieldPacker that was doing partial
updates of the underlying buffer. This was really relying on the old data
to be implicitly selected and written back, but that is not guaranteed by
the original API. This also required a fix to the FieldPacker.reset() API,
which was not allowing the FieldPacker to ever point to the final entry in
its buffer.

Change-Id: Idcd52790ac2b0ab1eff3f043e7eec2832953f04b
parent 88b37eda
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -776,10 +776,11 @@ public class Allocation extends BaseObj {
        mRS.validate();
        int eSize = mType.mElement.getBytesSize();
        final byte[] data = fp.getData();
        int data_length = fp.getPos();

        int count = data.length / eSize;
        if ((eSize * count) != data.length) {
            throw new RSIllegalArgumentException("Field packer length " + data.length +
        int count = data_length / eSize;
        if ((eSize * count) != data_length) {
            throw new RSIllegalArgumentException("Field packer length " + data_length +
                                               " not divisible by element size " + eSize + ".");
        }
        copy1DRangeFromUnchecked(xoff, count, data);
@@ -803,16 +804,17 @@ public class Allocation extends BaseObj {
        }

        final byte[] data = fp.getData();
        int data_length = fp.getPos();
        int eSize = mType.mElement.mElements[component_number].getBytesSize();
        eSize *= mType.mElement.mArraySizes[component_number];

        if (data.length != eSize) {
            throw new RSIllegalArgumentException("Field packer sizelength " + data.length +
        if (data_length != eSize) {
            throw new RSIllegalArgumentException("Field packer sizelength " + data_length +
                                               " does not match component size " + eSize + ".");
        }

        mRS.nAllocationElementData1D(getIDSafe(), xoff, mSelectedLOD,
                                     component_number, data, data.length);
                                     component_number, data, data_length);
    }

    private void data1DChecks(int off, int count, int len, int dataSize) {
+10 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public class FieldPacker {
        mPos = 0;
    }
    public void reset(int i) {
        if ((i < 0) || (i >= mLen)) {
        if ((i < 0) || (i > mLen)) {
            throw new RSIllegalArgumentException("out of range argument: " + i);
        }
        mPos = i;
@@ -606,6 +606,15 @@ public class FieldPacker {
        return mData;
    }

    /**
     * Get the actual length used for the FieldPacker.
     *
     * @hide
     */
    public int getPos() {
        return mPos;
    }

    private final byte mData[];
    private int mPos;
    private int mLen;
+3 −0
Original line number Diff line number Diff line
@@ -249,6 +249,9 @@ public class ProgramVertexFixedFunction extends ProgramVertex {
            for(int i = 0; i < 16; i ++) {
                mIOBuffer.addF32(m.mMat[i]);
            }
            // Reset the buffer back to the end, since we want to flush all of
            // the contents back (and not just what we wrote now).
            mIOBuffer.reset(mIOBuffer.getData().length);
            mAlloc.setFromFieldPacker(0, mIOBuffer);
        }