diff options
author | Tim Murray <timmurray@google.com> | 2013-02-28 11:45:22 -0800 |
---|---|---|
committer | Tim Murray <timmurray@google.com> | 2013-02-28 14:33:01 -0800 |
commit | abd5db9d37839bb47c77e03b28d00042582fbfe2 (patch) | |
tree | cdcfbf36e1194e35f6eb06a1569412e25e921dca /graphics/java | |
parent | 23b046c4af6672d96a4ef7bb27fb444e40f0bd5d (diff) | |
download | frameworks_base-abd5db9d37839bb47c77e03b28d00042582fbfe2.zip frameworks_base-abd5db9d37839bb47c77e03b28d00042582fbfe2.tar.gz frameworks_base-abd5db9d37839bb47c77e03b28d00042582fbfe2.tar.bz2 |
Add support and better exceptions for Bitmaps with a null config.
Bug: 8263427
Change-Id: I4181402e4739c6a40591f1e1416fca98643ecc57
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index a99cdad..b8564b6 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -26,6 +26,7 @@ import android.view.Surface; import android.graphics.SurfaceTexture; import android.util.Log; import android.util.TypedValue; +import android.graphics.Canvas; /** * <p> @@ -429,6 +430,9 @@ public class Allocation extends BaseObj { private void validateBitmapFormat(Bitmap b) { Bitmap.Config bc = b.getConfig(); + if (bc == null) { + throw new RSIllegalArgumentException("Bitmap has an unsupported format for this operation"); + } switch (bc) { case ALPHA_8: if (mType.getElement().mKind != Element.DataKind.PIXEL_A) { @@ -612,6 +616,13 @@ public class Allocation extends BaseObj { */ public void copyFrom(Bitmap b) { mRS.validate(); + if (b.getConfig() == null) { + Bitmap newBitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(newBitmap); + c.drawBitmap(b, 0, 0, null); + copyFrom(newBitmap); + return; + } validateBitmapSize(b); validateBitmapFormat(b); mRS.nAllocationCopyFromBitmap(getID(mRS), b); @@ -951,6 +962,12 @@ public class Allocation extends BaseObj { */ public void copy2DRangeFrom(int xoff, int yoff, Bitmap data) { mRS.validate(); + if (data.getConfig() == null) { + Bitmap newBitmap = Bitmap.createBitmap(data.getWidth(), data.getHeight(), Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(newBitmap); + c.drawBitmap(data, 0, 0, null); + copy2DRangeFrom(xoff, yoff, newBitmap); + } validateBitmapFormat(data); validate2DRange(xoff, yoff, data.getWidth(), data.getHeight()); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data); @@ -1220,6 +1237,18 @@ public class Allocation extends BaseObj { MipmapControl mips, int usage) { rs.validate(); + + // WAR undocumented color formats + if (b.getConfig() == null) { + if ((usage & USAGE_SHARED) != 0) { + throw new RSIllegalArgumentException("USAGE_SHARED cannot be used with a Bitmap that has a null config."); + } + Bitmap newBitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(newBitmap); + c.drawBitmap(b, 0, 0, null); + return createFromBitmap(rs, newBitmap, mips, usage); + } + Type t = typeFromBitmap(rs, b, mips); // enable optimized bitmap path only with no mipmap and script-only usage |