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

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

Fix copyFrom() to use proper dimensions for copying.

This change actually fixes several bugs related to stride:

* copyFrom() needs to call the 2D or 1D version, depending on the dimensions
  of the corresponding Allocation.
* Add an internal-only copy2DRangeFromUnchecked(), since we don't really
  want to expose it as another public API (only via copyFromUnchecked()).
* Call the proper 1D/2D version in copyFromUnchecked() based on the
  Allocation dimensions.
* Add Element checks to the "checked" copy2DRangeFrom() routines.

Change-Id: I690706d36884ee749bf90937c715855f6c07368c
parent 7bd280ac
Loading
Loading
Loading
Loading
+91 −22
Original line number Diff line number Diff line
@@ -488,8 +488,12 @@ public class Allocation extends BaseObj {
     */
    public void copyFromUnchecked(int[] d) {
        mRS.validate();
        if (mCurrentDimY > 0) {
            copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d);
        } else {
            copy1DRangeFromUnchecked(0, mCurrentCount, d);
        }
    }
    /**
     * Copy an allocation from an array.  This variant is not type
     * checked which allows an application to fill in structured
@@ -499,8 +503,12 @@ public class Allocation extends BaseObj {
     */
    public void copyFromUnchecked(short[] d) {
        mRS.validate();
        if (mCurrentDimY > 0) {
            copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d);
        } else {
            copy1DRangeFromUnchecked(0, mCurrentCount, d);
        }
    }
    /**
     * Copy an allocation from an array.  This variant is not type
     * checked which allows an application to fill in structured
@@ -510,8 +518,12 @@ public class Allocation extends BaseObj {
     */
    public void copyFromUnchecked(byte[] d) {
        mRS.validate();
        if (mCurrentDimY > 0) {
            copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d);
        } else {
            copy1DRangeFromUnchecked(0, mCurrentCount, d);
        }
    }
    /**
     * Copy an allocation from an array.  This variant is not type
     * checked which allows an application to fill in structured
@@ -521,8 +533,12 @@ public class Allocation extends BaseObj {
     */
    public void copyFromUnchecked(float[] d) {
        mRS.validate();
        if (mCurrentDimY > 0) {
            copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d);
        } else {
            copy1DRangeFromUnchecked(0, mCurrentCount, d);
        }
    }

    /**
     * Copy an allocation from an array.  This variant is type
@@ -533,8 +549,12 @@ public class Allocation extends BaseObj {
     */
    public void copyFrom(int[] d) {
        mRS.validate();
        if (mCurrentDimY > 0) {
            copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d);
        } else {
            copy1DRangeFrom(0, mCurrentCount, d);
        }
    }

    /**
     * Copy an allocation from an array.  This variant is type
@@ -545,8 +565,12 @@ public class Allocation extends BaseObj {
     */
    public void copyFrom(short[] d) {
        mRS.validate();
        if (mCurrentDimY > 0) {
            copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d);
        } else {
            copy1DRangeFrom(0, mCurrentCount, d);
        }
    }

    /**
     * Copy an allocation from an array.  This variant is type
@@ -557,8 +581,12 @@ public class Allocation extends BaseObj {
     */
    public void copyFrom(byte[] d) {
        mRS.validate();
        if (mCurrentDimY > 0) {
            copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d);
        } else {
            copy1DRangeFrom(0, mCurrentCount, d);
        }
    }

    /**
     * Copy an allocation from an array.  This variant is type
@@ -569,8 +597,12 @@ public class Allocation extends BaseObj {
     */
    public void copyFrom(float[] d) {
        mRS.validate();
        if (mCurrentDimY > 0) {
            copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d);
        } else {
            copy1DRangeFrom(0, mCurrentCount, d);
        }
    }

    /**
     * Copy an allocation from a bitmap.  The height, width, and
@@ -827,44 +859,81 @@ public class Allocation extends BaseObj {
        }
    }

    /**
     * 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
     * @param w Width of the incoming region to update
     * @param h Height of the incoming region to update
     * @param data to be placed into the allocation
     */
    public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) {
    void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, byte[] data) {
        mRS.validate();
        validate2DRange(xoff, yoff, w, h);
        mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
                              w, h, data, data.length);
    }

    public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) {
    void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, short[] data) {
        mRS.validate();
        validate2DRange(xoff, yoff, w, h);
        mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
                              w, h, data, data.length * 2);
    }

    public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) {
    void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, int[] data) {
        mRS.validate();
        validate2DRange(xoff, yoff, w, h);
        mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
                              w, h, data, data.length * 4);
    }

    public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) {
    void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, float[] data) {
        mRS.validate();
        validate2DRange(xoff, yoff, w, h);
        mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID,
                              w, h, data, data.length * 4);
    }


    /**
     * 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
     * @param w Width of the incoming region to update
     * @param h Height of the incoming region to update
     * @param data to be placed into the allocation
     */
    public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) {
        // We can only validate the type on API 18+, since this check was not present in
        // earlier releases.
        if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) {
            validateIsInt8();
        }
        copy2DRangeFromUnchecked(xoff, yoff, w, h, data);
    }

    public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) {
        // We can only validate the type on API 18+, since this check was not present in
        // earlier releases.
        if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) {
            validateIsInt16();
        }
        copy2DRangeFromUnchecked(xoff, yoff, w, h, data);
    }

    public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) {
        // We can only validate the type on API 18+, since this check was not present in
        // earlier releases.
        if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) {
            validateIsInt32();
        }
        copy2DRangeFromUnchecked(xoff, yoff, w, h, data);
    }

    public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) {
        // We can only validate the type on API 18+, since this check was not present in
        // earlier releases.
        if (mRS.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) {
            validateIsFloat32();
        }
        copy2DRangeFromUnchecked(xoff, yoff, w, h, data);
    }

    /**
     * Copy a rectangular region into the allocation from another
     * allocation.