Merge "Remove bitmap::getBitmapAllocationByteCount"

This commit is contained in:
TreeHugger Robot
2019-03-27 19:03:27 +00:00
committed by Android (Google) Code Review
5 changed files with 12 additions and 15 deletions

View File

@@ -39,7 +39,6 @@ static jclass gBitmap_class;
static jfieldID gBitmap_nativePtr;
static jmethodID gBitmap_constructorMethodID;
static jmethodID gBitmap_reinitMethodID;
static jmethodID gBitmap_getAllocationByteCountMethodID;
namespace android {
@@ -193,11 +192,6 @@ void reinitBitmap(JNIEnv* env, jobject javaBitmap, const SkImageInfo& info,
info.width(), info.height(), isPremultiplied);
}
int getBitmapAllocationByteCount(JNIEnv* env, jobject javaBitmap)
{
return env->CallIntMethod(javaBitmap, gBitmap_getAllocationByteCountMethodID);
}
jobject createBitmap(JNIEnv* env, Bitmap* bitmap,
int bitmapCreateFlags, jbyteArray ninePatchChunk, jobject ninePatchInsets,
int density) {
@@ -1227,7 +1221,6 @@ int register_android_graphics_Bitmap(JNIEnv* env)
gBitmap_nativePtr = GetFieldIDOrDie(env, gBitmap_class, "mNativePtr", "J");
gBitmap_constructorMethodID = GetMethodIDOrDie(env, gBitmap_class, "<init>", "(JIIIZ[BLandroid/graphics/NinePatch$InsetStruct;Z)V");
gBitmap_reinitMethodID = GetMethodIDOrDie(env, gBitmap_class, "reinit", "(IIZ)V");
gBitmap_getAllocationByteCountMethodID = GetMethodIDOrDie(env, gBitmap_class, "getAllocationByteCount", "()I");
return android::RegisterMethodsOrDie(env, "android/graphics/Bitmap", gBitmapMethods,
NELEM(gBitmapMethods));
}

View File

@@ -56,8 +56,6 @@ bool unlockPixels(JNIEnv* env, jobject bitmap);
void reinitBitmap(JNIEnv* env, jobject javaBitmap, const SkImageInfo& info,
bool isPremultiplied);
int getBitmapAllocationByteCount(JNIEnv* env, jobject javaBitmap);
} // namespace bitmap
} // namespace android

View File

@@ -327,10 +327,10 @@ static jobject doDecode(JNIEnv* env, std::unique_ptr<SkStreamRewindable> stream,
reuseBitmap = &bitmap::toBitmap(env, javaBitmap);
if (reuseBitmap->isImmutable()) {
ALOGW("Unable to reuse an immutable bitmap as an image decoder target.");
javaBitmap = NULL;
javaBitmap = nullptr;
reuseBitmap = nullptr;
} else {
existingBufferSize = bitmap::getBitmapAllocationByteCount(env, javaBitmap);
existingBufferSize = reuseBitmap->getAllocationByteCount();
}
}

View File

@@ -162,7 +162,7 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in
if (recycledBitmap->isImmutable()) {
ALOGW("Warning: Reusing an immutable bitmap as an image decoder target.");
}
recycledBytes = bitmap::getBitmapAllocationByteCount(env, javaBitmap);
recycledBytes = recycledBitmap->getAllocationByteCount();
}
SkBitmapRegionDecoder* brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);

View File

@@ -436,9 +436,15 @@ public class BitmapFactory {
static void validate(Options opts) {
if (opts == null) return;
if (opts.inBitmap != null && opts.inBitmap.getConfig() == Bitmap.Config.HARDWARE) {
throw new IllegalArgumentException(
"Bitmaps with Config.HARDWARE are always immutable");
if (opts.inBitmap != null) {
if (opts.inBitmap.getConfig() == Bitmap.Config.HARDWARE) {
throw new IllegalArgumentException(
"Bitmaps with Config.HARDWARE are always immutable");
}
if (opts.inBitmap.isRecycled()) {
throw new IllegalArgumentException(
"Cannot reuse a recycled Bitmap");
}
}
if (opts.inMutable && opts.inPreferredConfig == Bitmap.Config.HARDWARE) {