diff options
author | Stephen Hines <srhines@google.com> | 2013-02-08 17:11:31 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2013-02-08 20:56:00 -0800 |
commit | a9a7b3740598c79792cbcebca6a00d1595324ae9 (patch) | |
tree | 85abcb4eed70a1334fcdd8d576c2ad5454dbe0eb /graphics/java/android/renderscript/Allocation.java | |
parent | 7bd280ac8d56a9eb73240ccd5a403855286e6cb9 (diff) |
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
Diffstat (limited to 'graphics/java/android/renderscript/Allocation.java')
-rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 113 |
1 files changed, 91 insertions, 22 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 5f0844af2f52..7e43a9acee28 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -488,7 +488,11 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(int[] d) { mRS.validate(); - copy1DRangeFromUnchecked(0, mCurrentCount, d); + 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 @@ -499,7 +503,11 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(short[] d) { mRS.validate(); - copy1DRangeFromUnchecked(0, mCurrentCount, d); + 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 @@ -510,7 +518,11 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(byte[] d) { mRS.validate(); - copy1DRangeFromUnchecked(0, mCurrentCount, d); + 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 @@ -521,7 +533,11 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(float[] d) { mRS.validate(); - copy1DRangeFromUnchecked(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFromUnchecked(0, mCurrentCount, d); + } } /** @@ -533,7 +549,11 @@ public class Allocation extends BaseObj { */ public void copyFrom(int[] d) { mRS.validate(); - copy1DRangeFrom(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFrom(0, mCurrentCount, d); + } } /** @@ -545,7 +565,11 @@ public class Allocation extends BaseObj { */ public void copyFrom(short[] d) { mRS.validate(); - copy1DRangeFrom(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFrom(0, mCurrentCount, d); + } } /** @@ -557,7 +581,11 @@ public class Allocation extends BaseObj { */ public void copyFrom(byte[] d) { mRS.validate(); - copy1DRangeFrom(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFrom(0, mCurrentCount, d); + } } /** @@ -569,7 +597,11 @@ public class Allocation extends BaseObj { */ public void copyFrom(float[] d) { mRS.validate(); - copy1DRangeFrom(0, mCurrentCount, d); + if (mCurrentDimY > 0) { + copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); + } else { + copy1DRangeFrom(0, mCurrentCount, d); + } } /** @@ -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. |