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
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index 38a9ba3..c5c0eee 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -352,6 +352,18 @@
///////////////////////////////////////////////////////////////////////////////////////////
+// Assert that bitmap's SkAlphaType is consistent with isPremultiplied.
+static void assert_premultiplied(const SkBitmap& bitmap, bool isPremultiplied) {
+ // kOpaque_SkAlphaType and kIgnore_SkAlphaType mean that isPremultiplied is
+ // irrelevant. This just tests to ensure that the SkAlphaType is not
+ // opposite of isPremultiplied.
+ if (isPremultiplied) {
+ SkASSERT(bitmap.alphaType() != kUnpremul_SkAlphaType);
+ } else {
+ SkASSERT(bitmap.alphaType() != kPremul_SkAlphaType);
+ }
+}
+
jobject GraphicsJNI::createBitmap(JNIEnv* env, SkBitmap* bitmap, jbyteArray buffer,
int bitmapCreateFlags, jbyteArray ninepatch, jintArray layoutbounds, int density)
{
@@ -360,6 +372,10 @@
bool isMutable = bitmapCreateFlags & kBitmapCreateFlag_Mutable;
bool isPremultiplied = bitmapCreateFlags & kBitmapCreateFlag_Premultiplied;
+ // The caller needs to have already set the alpha type properly, so the
+ // native SkBitmap stays in sync with the Java Bitmap.
+ assert_premultiplied(*bitmap, isPremultiplied);
+
jobject obj = env->NewObject(gBitmap_class, gBitmap_constructorMethodID,
static_cast<jint>(reinterpret_cast<uintptr_t>(bitmap)), buffer,
bitmap->width(), bitmap->height(), density, isMutable, isPremultiplied,
@@ -377,6 +393,10 @@
void GraphicsJNI::reinitBitmap(JNIEnv* env, jobject javaBitmap, SkBitmap* bitmap,
bool isPremultiplied)
{
+ // The caller needs to have already set the alpha type properly, so the
+ // native SkBitmap stays in sync with the Java Bitmap.
+ assert_premultiplied(*bitmap, isPremultiplied);
+
env->CallVoidMethod(javaBitmap, gBitmap_reinitMethodID,
bitmap->width(), bitmap->height(), isPremultiplied);
}