summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
authorLeon Scroggins III <scroggo@google.com>2013-12-03 16:26:51 -0500
committerLeon Scroggins III <scroggo@google.com>2014-01-15 11:37:04 -0500
commit8790be6de3644e332ec6a17c855da89ffc13a9bf (patch)
tree45dd6bf1f37585b02335b9ed5e35d35463c2a650 /graphics/java
parentcae6b43b03d0be44c6e63ed1db5ef835633a3b86 (diff)
downloadframeworks_base-8790be6de3644e332ec6a17c855da89ffc13a9bf.zip
frameworks_base-8790be6de3644e332ec6a17c855da89ffc13a9bf.tar.gz
frameworks_base-8790be6de3644e332ec6a17c855da89ffc13a9bf.tar.bz2
Remove calls to deprecated SkBitmap::setIsOpaque()
setIsOpaque() has been removed from ToT Skia. Update setters for mIsPremultiplied and hasAlpha to take the other into consideration. Change-Id: I1b36b0b0ce7126031eb7b769b563c17dcd4b306a
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/Bitmap.java40
-rw-r--r--graphics/java/android/graphics/BitmapFactory.java7
2 files changed, 40 insertions, 7 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 3c24683..4d82264 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;
@@ -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 b714fab..2b69a15 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;