diff options
author | Leon Scroggins III <scroggo@google.com> | 2014-03-06 19:49:58 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-03-06 19:49:58 +0000 |
commit | 8d3281f5f7a880b996e50d291ebb7154a486eb6c (patch) | |
tree | ce2df832edfe7b3d7c53e6049cb8a2f872b284ef /graphics/java | |
parent | eac19754ca0822e4c1c50c436affbf5cbf7e08d3 (diff) | |
parent | ee008d4264a95bba5f90b17856fc06fa29a6f12c (diff) | |
download | frameworks_base-8d3281f5f7a880b996e50d291ebb7154a486eb6c.zip frameworks_base-8d3281f5f7a880b996e50d291ebb7154a486eb6c.tar.gz frameworks_base-8d3281f5f7a880b996e50d291ebb7154a486eb6c.tar.bz2 |
am ee008d42: Merge "Update framework to use M33 Skia. DO NOT MERGE" into klp-dev
* commit 'ee008d4264a95bba5f90b17856fc06fa29a6f12c':
Update framework to use M33 Skia. DO NOT MERGE
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 50 | ||||
-rw-r--r-- | graphics/java/android/graphics/BitmapFactory.java | 7 |
2 files changed, 45 insertions, 12 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 3c24683..314b8c5 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -67,6 +67,16 @@ public final class Bitmap implements Parcelable { * setPremultiplied() aren't order dependent, despite being setters. */ private boolean mIsPremultiplied; + + /** + * Whether the Bitmap's content is expected to have alpha. Note that hasAlpha() + * does not directly return this value, because hasAlpha() may never return true + * for a 565 Bitmap. + * + * Any time this or mIsPremultiplied is changed, both are passed to native so they + * are not order dependent. + */ + private boolean mHasAlpha; private byte[] mNinePatchChunk; // may be null private int[] mLayoutBounds; // may be null private int mWidth; @@ -390,7 +400,7 @@ public final class Bitmap implements Parcelable { * No color information is stored. * With this configuration, each pixel requires 1 byte of memory. */ - ALPHA_8 (2), + ALPHA_8 (1), /** * Each pixel is stored on 2 bytes and only the RGB channels are @@ -406,7 +416,7 @@ public final class Bitmap implements Parcelable { * This configuration may be useful when using opaque bitmaps * that do not require high color fidelity. */ - RGB_565 (4), + RGB_565 (3), /** * Each pixel is stored on 2 bytes. The three RGB color channels @@ -428,7 +438,7 @@ public final class Bitmap implements Parcelable { * it is advised to use {@link #ARGB_8888} instead. */ @Deprecated - ARGB_4444 (5), + ARGB_4444 (4), /** * Each pixel is stored on 4 bytes. Each channel (RGB and alpha @@ -438,13 +448,13 @@ public final class Bitmap implements Parcelable { * This configuration is very flexible and offers the best * quality. It should be used whenever possible. */ - ARGB_8888 (6); + ARGB_8888 (5); final int nativeInt; @SuppressWarnings({"deprecation"}) private static Config sConfigs[] = { - null, null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888 + null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888 }; Config(int ni) { @@ -554,7 +564,7 @@ public final class Bitmap implements Parcelable { checkRecycled("Can't copy a recycled bitmap"); Bitmap b = nativeCopy(mNativeBitmap, config.nativeInt, isMutable); if (b != null) { - b.mIsPremultiplied = mIsPremultiplied; + b.setAlphaAndPremultiplied(mHasAlpha, mIsPremultiplied); b.mDensity = mDensity; } return b; @@ -727,12 +737,12 @@ public final class Bitmap implements Parcelable { paint.setAntiAlias(true); } } - + // The new bitmap was created from a known bitmap source so assume that // they use the same density bitmap.mDensity = source.mDensity; - bitmap.mIsPremultiplied = source.mIsPremultiplied; - + bitmap.setAlphaAndPremultiplied(source.mHasAlpha, source.mIsPremultiplied); + canvas.setBitmap(bitmap); canvas.drawBitmap(source, srcR, dstR, paint); canvas.setBitmap(null); @@ -810,9 +820,9 @@ public final class Bitmap implements Parcelable { if (display != null) { bm.mDensity = display.densityDpi; } + bm.setHasAlpha(hasAlpha); if (config == Config.ARGB_8888 && !hasAlpha) { nativeErase(bm.mNativeBitmap, 0xff000000); - nativeSetHasAlpha(bm.mNativeBitmap, hasAlpha); } // No need to initialize the bitmap to zeroes with other configs; // it is backed by a VM byte array which is by definition preinitialized @@ -884,6 +894,7 @@ public final class Bitmap implements Parcelable { if (display != null) { bm.mDensity = display.densityDpi; } + bm.mHasAlpha = true; return bm; } @@ -1041,11 +1052,24 @@ public final class Bitmap implements Parcelable { * <p>This method will not affect the behavior of a bitmap without an alpha * channel, or if {@link #hasAlpha()} returns false.</p> * + * <p>Calling {@link createBitmap()} or {@link createScaledBitmap()} with a source + * Bitmap whose colors are not pre-multiplied may result in a RuntimeException, + * since those functions require drawing the source, which is not supported for + * un-pre-multiplied Bitmaps.</p> + * * @see Bitmap#isPremultiplied() * @see BitmapFactory.Options#inPremultiplied */ public final void setPremultiplied(boolean premultiplied) { mIsPremultiplied = premultiplied; + nativeSetAlphaAndPremultiplied(mNativeBitmap, mHasAlpha, premultiplied); + } + + /** Helper function to set both alpha and premultiplied. **/ + private final void setAlphaAndPremultiplied(boolean hasAlpha, boolean premultiplied) { + mHasAlpha = hasAlpha; + mIsPremultiplied = premultiplied; + nativeSetAlphaAndPremultiplied(mNativeBitmap, hasAlpha, premultiplied); } /** Returns the bitmap's width */ @@ -1206,7 +1230,8 @@ public final class Bitmap implements Parcelable { * non-opaque per-pixel alpha values. */ public void setHasAlpha(boolean hasAlpha) { - nativeSetHasAlpha(mNativeBitmap, hasAlpha); + mHasAlpha = hasAlpha; + nativeSetAlphaAndPremultiplied(mNativeBitmap, hasAlpha, mIsPremultiplied); } /** @@ -1611,7 +1636,8 @@ public final class Bitmap implements Parcelable { private static native void nativePrepareToDraw(int nativeBitmap); private static native boolean nativeHasAlpha(int nativeBitmap); - private static native void nativeSetHasAlpha(int nBitmap, boolean hasAlpha); + private static native void nativeSetAlphaAndPremultiplied(int nBitmap, boolean hasAlpha, + boolean isPremul); private static native boolean nativeHasMipMap(int nativeBitmap); private static native void nativeSetHasMipMap(int nBitmap, boolean hasMipMap); private static native boolean nativeSameAs(int nb0, int nb1); diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java index 429be49..4575364 100644 --- a/graphics/java/android/graphics/BitmapFactory.java +++ b/graphics/java/android/graphics/BitmapFactory.java @@ -153,8 +153,12 @@ public class BitmapFactory { * * <p>This does not affect bitmaps without an alpha channel.</p> * + * <p>Setting this flag to false while setting {@link #inScaled} to true + * may result in incorrect colors.</p> + * * @see Bitmap#hasAlpha() * @see Bitmap#isPremultiplied() + * @see #inScaled */ public boolean inPremultiplied; @@ -249,6 +253,9 @@ public class BitmapFactory { * <p>This flag is turned on by default and should be turned off if you need * a non-scaled version of the bitmap. Nine-patch bitmaps ignore this * flag and are always scaled. + * + * <p>If {@link #inPremultiplied} is set to false, and the image has alpha, + * setting this flag to true may result in incorrect colors. */ public boolean inScaled; |