diff options
Diffstat (limited to 'graphics/java')
6 files changed, 48 insertions, 72 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 6d60dd2..3c24683 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -1167,6 +1167,11 @@ public final class Bitmap implements Parcelable { * @see #reconfigure(int, int, Config) */ public final int getAllocationByteCount() { + if (mBuffer == null) { + // native backed bitmaps don't support reconfiguration, + // so alloc size is always content size + return getByteCount(); + } return mBuffer.length; } diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java index b73db74..b714fab 100644 --- a/graphics/java/android/graphics/BitmapFactory.java +++ b/graphics/java/android/graphics/BitmapFactory.java @@ -259,14 +259,26 @@ public class BitmapFactory { * (e.g. the bitmap is drawn, getPixels() is called), they will be * automatically re-decoded. * - * For the re-decode to happen, the bitmap must have access to the + * <p>For the re-decode to happen, the bitmap must have access to the * encoded data, either by sharing a reference to the input * or by making a copy of it. This distinction is controlled by * inInputShareable. If this is true, then the bitmap may keep a shallow * reference to the input. If this is false, then the bitmap will * explicitly make a copy of the input data, and keep that. Even if * sharing is allowed, the implementation may still decide to make a - * deep copy of the input data. + * deep copy of the input data.</p> + * + * <p>While inPurgeable can help avoid big Dalvik heap allocations (from + * API level 11 onward), it sacrifices performance predictability since any + * image that the view system tries to draw may incur a decode delay which + * can lead to dropped frames. Therefore, most apps should avoid using + * inPurgeable to allow for a fast and fluid UI. To minimize Dalvik heap + * allocations use the {@link #inBitmap} flag instead.</p> + * + * <p class="note"><strong>Note:</strong> This flag is ignored when used + * with {@link #decodeResource(Resources, int, + * android.graphics.BitmapFactory.Options)} or {@link #decodeFile(String, + * android.graphics.BitmapFactory.Options)}.</p> */ public boolean inPurgeable; diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java index 60e2376..aac7876 100644 --- a/graphics/java/android/graphics/drawable/DrawableContainer.java +++ b/graphics/java/android/graphics/drawable/DrawableContainer.java @@ -60,7 +60,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { private long mExitAnimationEnd; private Drawable mLastDrawable; - private Insets mInsets; + private Insets mInsets = Insets.NONE; // overrides from Drawable @@ -88,9 +88,10 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { @Override public boolean getPadding(Rect padding) { final Rect r = mDrawableContainerState.getConstantPadding(); - boolean result = true; + boolean result; if (r != null) { padding.set(r); + result = (r.left | r.top | r.bottom | r.right) != 0; } else { if (mCurrDrawable != null) { result = mCurrDrawable.getPadding(padding); diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java index ab34c0f..9c57a2c 100644 --- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java +++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java @@ -244,7 +244,7 @@ public class NinePatchDrawable extends Drawable { } else { padding.set(mPadding); } - return true; + return (padding.left | padding.top | padding.right | padding.bottom) != 0; } /** diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index bb1e743..0cafdd7 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -801,7 +801,7 @@ public class Allocation extends BaseObj { Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked"); int dataSize = mType.mElement.getBytesSize() * count; data1DChecks(off, count, d.length * 4, dataSize); - mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); + mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize, Element.DataType.SIGNED_32); Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -817,7 +817,7 @@ public class Allocation extends BaseObj { Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked"); int dataSize = mType.mElement.getBytesSize() * count; data1DChecks(off, count, d.length * 2, dataSize); - mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); + mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize, Element.DataType.SIGNED_16); Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -833,7 +833,7 @@ public class Allocation extends BaseObj { Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked"); int dataSize = mType.mElement.getBytesSize() * count; data1DChecks(off, count, d.length, dataSize); - mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); + mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize, Element.DataType.SIGNED_8); Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -849,7 +849,7 @@ public class Allocation extends BaseObj { Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked"); int dataSize = mType.mElement.getBytesSize() * count; data1DChecks(off, count, d.length * 4, dataSize); - mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); + mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize, Element.DataType.FLOAT_32); Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -955,7 +955,7 @@ public class Allocation extends BaseObj { mRS.validate(); validate2DRange(xoff, yoff, w, h); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, - w, h, data, data.length); + w, h, data, data.length, Element.DataType.SIGNED_8); Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -964,7 +964,7 @@ public class Allocation extends BaseObj { mRS.validate(); validate2DRange(xoff, yoff, w, h); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, - w, h, data, data.length * 2); + w, h, data, data.length * 2, Element.DataType.SIGNED_16); Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -973,7 +973,7 @@ public class Allocation extends BaseObj { mRS.validate(); validate2DRange(xoff, yoff, w, h); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, - w, h, data, data.length * 4); + w, h, data, data.length * 4, Element.DataType.SIGNED_32); Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -982,7 +982,7 @@ public class Allocation extends BaseObj { mRS.validate(); validate2DRange(xoff, yoff, w, h); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, - w, h, data, data.length * 4); + w, h, data, data.length * 4, Element.DataType.FLOAT_32); Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -1128,7 +1128,7 @@ public class Allocation extends BaseObj { mRS.validate(); validate3DRange(xoff, yoff, zoff, w, h, d); mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, - w, h, d, data, data.length); + w, h, d, data, data.length, Element.DataType.SIGNED_8); } /** @@ -1139,7 +1139,7 @@ public class Allocation extends BaseObj { mRS.validate(); validate3DRange(xoff, yoff, zoff, w, h, d); mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, - w, h, d, data, data.length * 2); + w, h, d, data, data.length * 2, Element.DataType.SIGNED_16); } /** @@ -1150,7 +1150,7 @@ public class Allocation extends BaseObj { mRS.validate(); validate3DRange(xoff, yoff, zoff, w, h, d); mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, - w, h, d, data, data.length * 4); + w, h, d, data, data.length * 4, Element.DataType.SIGNED_32); } /** @@ -1161,7 +1161,7 @@ public class Allocation extends BaseObj { mRS.validate(); validate3DRange(xoff, yoff, zoff, w, h, d); mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, - w, h, d, data, data.length * 4); + w, h, d, data, data.length * 4, Element.DataType.FLOAT_32); } diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index 7d4a5c4..da0cfeb 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -386,25 +386,10 @@ public class RenderScript { } - native void rsnAllocationData1D(int con, int id, int off, int mip, int count, int[] d, int sizeBytes); - synchronized void nAllocationData1D(int id, int off, int mip, int count, int[] d, int sizeBytes) { + native void rsnAllocationData1D(int con, int id, int off, int mip, int count, Object d, int sizeBytes, int dt); + synchronized void nAllocationData1D(int id, int off, int mip, int count, Object d, int sizeBytes, Element.DataType dt) { validate(); - rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); - } - native void rsnAllocationData1D(int con, int id, int off, int mip, int count, short[] d, int sizeBytes); - synchronized void nAllocationData1D(int id, int off, int mip, int count, short[] d, int sizeBytes) { - validate(); - rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); - } - native void rsnAllocationData1D(int con, int id, int off, int mip, int count, byte[] d, int sizeBytes); - synchronized void nAllocationData1D(int id, int off, int mip, int count, byte[] d, int sizeBytes) { - validate(); - rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); - } - native void rsnAllocationData1D(int con, int id, int off, int mip, int count, float[] d, int sizeBytes); - synchronized void nAllocationData1D(int id, int off, int mip, int count, float[] d, int sizeBytes) { - validate(); - rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes); + rsnAllocationData1D(mContext, id, off, mip, count, d, sizeBytes, dt.mID); } native void rsnAllocationElementData1D(int con, int id, int xoff, int mip, int compIdx, byte[] d, int sizeBytes); @@ -433,25 +418,12 @@ public class RenderScript { 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(); - rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes); - } - native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, short[] d, int sizeBytes); - synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, short[] d, int sizeBytes) { - validate(); - rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes); - } - native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes); - synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, int[] d, int sizeBytes) { + native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, + int w, int h, Object d, int sizeBytes, int dt); + synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, + int w, int h, Object d, int sizeBytes, Element.DataType dt) { validate(); - rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes); - } - native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes); - synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, int w, int h, float[] d, int sizeBytes) { - validate(); - rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes); + rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, w, h, d, sizeBytes, dt.mID); } native void rsnAllocationData2D(int con, int id, int xoff, int yoff, int mip, int face, Bitmap b); synchronized void nAllocationData2D(int id, int xoff, int yoff, int mip, int face, Bitmap b) { @@ -477,27 +449,13 @@ public class RenderScript { srcAlloc, srcXoff, srcYoff, srcZoff, srcMip); } - native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, byte[] d, int sizeBytes); - synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, byte[] d, int sizeBytes) { + native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, + int w, int h, int depth, Object d, int sizeBytes, int dt); + synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, + int w, int h, int depth, Object d, int sizeBytes, Element.DataType dt) { validate(); - rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); + rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes, dt.mID); } - native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, short[] d, int sizeBytes); - synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, short[] d, int sizeBytes) { - validate(); - rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); - } - native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, int[] d, int sizeBytes); - synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, int[] d, int sizeBytes) { - validate(); - rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); - } - native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, float[] d, int sizeBytes); - synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, float[] d, int sizeBytes) { - validate(); - rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); - } - native void rsnAllocationRead(int con, int id, byte[] d); synchronized void nAllocationRead(int id, byte[] d) { |