diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2013-12-05 13:10:46 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2013-12-05 13:10:46 -0800 |
commit | ebcb32f58a6220802ca129ea33f47b4b69931a10 (patch) | |
tree | 32b57c1d6ba9180ae63979e06d7421e107a9aa6c /graphics/java | |
parent | 6e2d0c1d91f644ab50e0c0b7cae4306262a4ca41 (diff) | |
parent | bac61807d3bcfff957b358cb9ad77850bd373689 (diff) | |
download | frameworks_base-ebcb32f58a6220802ca129ea33f47b4b69931a10.zip frameworks_base-ebcb32f58a6220802ca129ea33f47b4b69931a10.tar.gz frameworks_base-ebcb32f58a6220802ca129ea33f47b4b69931a10.tar.bz2 |
Merge commit 'bac61807d3bcfff957b358cb9ad77850bd373689' into HEAD
Change-Id: I29374270c8e0c2f2859efaf1d55af9f73da0f8d7
Diffstat (limited to 'graphics/java')
6 files changed, 90 insertions, 21 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 4c7395c..3c24683 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -995,7 +995,7 @@ public final class Bitmap implements Parcelable { } /** - * Returns true if the bitmap is marked as mutable (i.e. can be drawn into) + * Returns true if the bitmap is marked as mutable (i.e. can be drawn into) */ public final boolean isMutable() { return mIsMutable; @@ -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 a7c5b20..429be49 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; @@ -457,7 +469,7 @@ public class BitmapFactory { * * @param res The resources object containing the image data * @param id The resource id of the image data - * @return The decoded bitmap, or null if the image could not be decode. + * @return The decoded bitmap, or null if the image could not be decoded. */ public static Bitmap decodeResource(Resources res, int id) { return decodeResource(res, id, null); @@ -505,7 +517,7 @@ public class BitmapFactory { * @param offset offset into imageData for where the decoder should begin * parsing. * @param length the number of bytes, beginning at offset, to parse - * @return The decoded bitmap, or null if the image could not be decode. + * @return The decoded bitmap, or null if the image could not be decoded. */ public static Bitmap decodeByteArray(byte[] data, int offset, int length) { return decodeByteArray(data, offset, length, null); diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 8a3d940..93738b0 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -693,8 +693,8 @@ public abstract class Drawable { */ protected boolean onLevelChange(int level) { return false; } /** - * Override this in your subclass to change appearance if you recognize the - * specified state. + * Override this in your subclass to change appearance if you vary based on + * the bounds. */ protected void onBoundsChange(Rect bounds) {} diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java index e350e8d..aac7876 100644 --- a/graphics/java/android/graphics/drawable/DrawableContainer.java +++ b/graphics/java/android/graphics/drawable/DrawableContainer.java @@ -23,6 +23,7 @@ import android.graphics.Insets; import android.graphics.PixelFormat; import android.graphics.Rect; import android.os.SystemClock; +import android.util.LayoutDirection; import android.util.SparseArray; /** @@ -59,6 +60,8 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { private long mExitAnimationEnd; private Drawable mLastDrawable; + private Insets mInsets = Insets.NONE; + // overrides from Drawable @Override @@ -78,18 +81,31 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { | mDrawableContainerState.mChildrenChangingConfigurations; } + private boolean needsMirroring() { + return isAutoMirrored() && getLayoutDirection() == LayoutDirection.RTL; + } + @Override public boolean getPadding(Rect padding) { final Rect r = mDrawableContainerState.getConstantPadding(); + boolean result; if (r != null) { padding.set(r); - return true; - } - if (mCurrDrawable != null) { - return mCurrDrawable.getPadding(padding); + result = (r.left | r.top | r.bottom | r.right) != 0; } else { - return super.getPadding(padding); + if (mCurrDrawable != null) { + result = mCurrDrawable.getPadding(padding); + } else { + result = super.getPadding(padding); + } } + if (needsMirroring()) { + final int left = padding.left; + final int right = padding.right; + padding.left = right; + padding.right = left; + } + return result; } /** @@ -97,7 +113,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { */ @Override public Insets getOpticalInsets() { - return (mCurrDrawable == null) ? Insets.NONE : mCurrDrawable.getOpticalInsets(); + return mInsets; } @Override @@ -334,6 +350,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { mCurrDrawable = d; mCurIndex = idx; if (d != null) { + mInsets = d.getOpticalInsets(); d.mutate(); if (mDrawableContainerState.mEnterFadeDuration > 0) { mEnterAnimationEnd = now + mDrawableContainerState.mEnterFadeDuration; @@ -348,9 +365,12 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { d.setBounds(getBounds()); d.setLayoutDirection(getLayoutDirection()); d.setAutoMirrored(mDrawableContainerState.mAutoMirrored); + } else { + mInsets = Insets.NONE; } } else { mCurrDrawable = null; + mInsets = Insets.NONE; mCurIndex = -1; } 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/graphics/pdf/PdfDocument.java b/graphics/java/android/graphics/pdf/PdfDocument.java index 066ae2b..29d14a2 100644 --- a/graphics/java/android/graphics/pdf/PdfDocument.java +++ b/graphics/java/android/graphics/pdf/PdfDocument.java @@ -18,6 +18,7 @@ package android.graphics.pdf; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Paint; import android.graphics.Rect; import dalvik.system.CloseGuard; @@ -69,6 +70,12 @@ import java.util.List; */ public class PdfDocument { + // TODO: We need a constructor that will take an OutputStream to + // support online data serialization as opposed to the current + // on demand one. The current approach is fine until Skia starts + // to support online PDF generation at which point we need to + // handle this. + private final byte[] mChunk = new byte[4096]; private final CloseGuard mCloseGuard = CloseGuard.get(); @@ -111,7 +118,7 @@ public class PdfDocument { if (pageInfo == null) { throw new IllegalArgumentException("page cannot be null"); } - Canvas canvas = new PdfCanvas(nativeCreatePage(pageInfo.mPageWidth, + Canvas canvas = new PdfCanvas(nativeStartPage(mNativeDocument, pageInfo.mPageWidth, pageInfo.mPageHeight, pageInfo.mContentRect.left, pageInfo.mContentRect.top, pageInfo.mContentRect.right, pageInfo.mContentRect.bottom)); mCurrentPage = new Page(canvas, pageInfo); @@ -142,7 +149,7 @@ public class PdfDocument { } mPages.add(page.getInfo()); mCurrentPage = null; - nativeAppendPage(mNativeDocument, page.mCanvas.mNativeCanvas); + nativeFinishPage(mNativeDocument); page.finish(); } @@ -204,7 +211,7 @@ public class PdfDocument { private void dispose() { if (mNativeDocument != 0) { - nativeFinalize(mNativeDocument); + nativeClose(mNativeDocument); mCloseGuard.close(); mNativeDocument = 0; } @@ -230,14 +237,14 @@ public class PdfDocument { private native int nativeCreateDocument(); - private native void nativeFinalize(int document); + private native void nativeClose(int document); - private native void nativeAppendPage(int document, int page); + private native void nativeFinishPage(int document); private native void nativeWriteTo(int document, OutputStream out, byte[] chunk); - private static native int nativeCreatePage(int pageWidth, int pageHeight, int contentLeft, - int contentTop, int contentRight, int contentBottom); + private static native int nativeStartPage(int documentPtr, int pageWidth, int pageHeight, + int contentLeft, int contentTop, int contentRight, int contentBottom); private final class PdfCanvas extends Canvas { @@ -391,6 +398,31 @@ public class PdfDocument { /** * Gets the {@link Canvas} of the page. * + * <p> + * <strong>Note: </strong> There are some draw operations that are not yet + * supported by the canvas returned by this method. More specifically: + * <ul> + * <li>Inverse path clipping performed via {@link Canvas#clipPath(android.graphics.Path, + * android.graphics.Region.Op) Canvas.clipPath(android.graphics.Path, + * android.graphics.Region.Op)} for {@link + * android.graphics.Region.Op#REVERSE_DIFFERENCE + * Region.Op#REVERSE_DIFFERENCE} operations.</li> + * <li>{@link Canvas#drawVertices(android.graphics.Canvas.VertexMode, int, + * float[], int, float[], int, int[], int, short[], int, int, + * android.graphics.Paint) Canvas.drawVertices( + * android.graphics.Canvas.VertexMode, int, float[], int, float[], + * int, int[], int, short[], int, int, android.graphics.Paint)}</li> + * <li>Color filters set via {@link Paint#setColorFilter( + * android.graphics.ColorFilter)}</li> + * <li>Mask filters set via {@link Paint#setMaskFilter( + * android.graphics.MaskFilter)}</li> + * <li>Some XFER modes such as + * {@link android.graphics.PorterDuff.Mode#SRC_ATOP PorterDuff.Mode SRC}, + * {@link android.graphics.PorterDuff.Mode#DST_ATOP PorterDuff.DST_ATOP}, + * {@link android.graphics.PorterDuff.Mode#XOR PorterDuff.XOR}, + * {@link android.graphics.PorterDuff.Mode#ADD PorterDuff.ADD}</li> + * </ul> + * * @return The canvas if the page is not finished, null otherwise. * * @see PdfDocument#finishPage(Page) |