Loading core/jni/android/graphics/BitmapFactory.cpp +12 −3 Original line number Diff line number Diff line Loading @@ -235,6 +235,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding int sampleSize = 1; bool onlyDecodeSize = false; SkColorType prefColorType = kN32_SkColorType; bool isHardware = false; bool isMutable = false; float scale = 1.0f; bool requireUnpremultiplied = false; Loading @@ -260,6 +261,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding jobject jconfig = env->GetObjectField(options, gOptions_configFieldID); prefColorType = GraphicsJNI::getNativeBitmapColorType(env, jconfig); isHardware = GraphicsJNI::isHardwareConfig(env, jconfig); isMutable = env->GetBooleanField(options, gOptions_mutableFieldID); requireUnpremultiplied = !env->GetBooleanField(options, gOptions_premultipliedFieldID); javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID); Loading Loading @@ -352,9 +354,10 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding decodeAllocator = &scaleCheckingAllocator; } else if (javaBitmap != nullptr) { decodeAllocator = &recyclingAllocator; } else if (willScale) { // This will allocate pixels using a HeapAllocator, since there will be an extra // scaling step. } else if (willScale || isHardware) { // This will allocate pixels using a HeapAllocator, // for scale case: there will be an extra scaling step. // for hardware case: there will be extra swizzling & upload to gralloc step. decodeAllocator = &heapAllocator; } else { decodeAllocator = &defaultAllocator; Loading Loading @@ -539,6 +542,12 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding if (isMutable) bitmapCreateFlags |= android::bitmap::kBitmapCreateFlag_Mutable; if (isPremultiplied) bitmapCreateFlags |= android::bitmap::kBitmapCreateFlag_Premultiplied; if (isHardware) { sk_sp<Bitmap> hardwareBitmap = Bitmap::allocateHardwareBitmap(outputBitmap); return bitmap::createBitmap(env, hardwareBitmap.release(), bitmapCreateFlags, ninePatchChunk, ninePatchInsets, -1); } // now create the java bitmap return bitmap::createBitmap(env, defaultAllocator.getStorageObjAndReset(), bitmapCreateFlags, ninePatchChunk, ninePatchInsets, -1); Loading core/jni/android/graphics/BitmapRegionDecoder.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -131,12 +131,13 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in SkColorType colorType = kN32_SkColorType; bool requireUnpremul = false; jobject javaBitmap = NULL; bool isHardware = false; // Update the default options with any options supplied by the client. if (NULL != options) { sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID); jobject jconfig = env->GetObjectField(options, gOptions_configFieldID); colorType = GraphicsJNI::getNativeBitmapColorType(env, jconfig); isHardware = GraphicsJNI::isHardwareConfig(env, jconfig); requireUnpremul = !env->GetBooleanField(options, gOptions_premultipliedFieldID); javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID); // The Java options of ditherMode and preferQualityOverSpeed are deprecated. We will Loading Loading @@ -202,6 +203,10 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in if (!requireUnpremul) { bitmapCreateFlags |= android::bitmap::kBitmapCreateFlag_Premultiplied; } if (isHardware) { sk_sp<Bitmap> hardwareBitmap = Bitmap::allocateHardwareBitmap(bitmap); return bitmap::createBitmap(env, hardwareBitmap.release(), bitmapCreateFlags); } return android::bitmap::createBitmap(env, heapAlloc.getStorageObjAndReset(), bitmapCreateFlags); } Loading core/jni/android/graphics/Graphics.cpp +12 −1 Original line number Diff line number Diff line Loading @@ -297,8 +297,9 @@ enum LegacyBitmapConfig { kRGB_565_LegacyBitmapConfig = 3, kARGB_4444_LegacyBitmapConfig = 4, kARGB_8888_LegacyBitmapConfig = 5, kHardware_LegacyBitmapConfig = 6, kLastEnum_LegacyBitmapConfig = kARGB_8888_LegacyBitmapConfig kLastEnum_LegacyBitmapConfig = kHardware_LegacyBitmapConfig }; jint GraphicsJNI::colorTypeToLegacyBitmapConfig(SkColorType colorType) { Loading Loading @@ -327,6 +328,7 @@ SkColorType GraphicsJNI::legacyBitmapConfigToColorType(jint legacyConfig) { kIndex_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kN32_SkColorType, kN32_SkColorType }; Loading Loading @@ -355,6 +357,15 @@ SkColorType GraphicsJNI::getNativeBitmapColorType(JNIEnv* env, jobject jconfig) return legacyBitmapConfigToColorType(c); } bool GraphicsJNI::isHardwareConfig(JNIEnv* env, jobject jconfig) { SkASSERT(env); if (NULL == jconfig) { return false; } int c = env->GetIntField(jconfig, gBitmapConfig_nativeInstanceID); return c == kHardware_LegacyBitmapConfig; } android::Canvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) { SkASSERT(env); SkASSERT(canvas); Loading core/jni/android/graphics/GraphicsJNI.h +2 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,8 @@ public: */ static SkColorType getNativeBitmapColorType(JNIEnv*, jobject jconfig); static bool isHardwareConfig(JNIEnv* env, jobject jconfig); static jobject createRegion(JNIEnv* env, SkRegion* region); static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap); Loading graphics/java/android/graphics/Bitmap.java +8 −2 Original line number Diff line number Diff line Loading @@ -463,12 +463,18 @@ public final class Bitmap implements Parcelable { * This configuration is very flexible and offers the best * quality. It should be used whenever possible. */ ARGB_8888 (5); ARGB_8888 (5), /** * @hide */ HARDWARE (6); final int nativeInt; private static Config sConfigs[] = { null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888 null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888, HARDWARE }; Config(int ni) { Loading Loading
core/jni/android/graphics/BitmapFactory.cpp +12 −3 Original line number Diff line number Diff line Loading @@ -235,6 +235,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding int sampleSize = 1; bool onlyDecodeSize = false; SkColorType prefColorType = kN32_SkColorType; bool isHardware = false; bool isMutable = false; float scale = 1.0f; bool requireUnpremultiplied = false; Loading @@ -260,6 +261,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding jobject jconfig = env->GetObjectField(options, gOptions_configFieldID); prefColorType = GraphicsJNI::getNativeBitmapColorType(env, jconfig); isHardware = GraphicsJNI::isHardwareConfig(env, jconfig); isMutable = env->GetBooleanField(options, gOptions_mutableFieldID); requireUnpremultiplied = !env->GetBooleanField(options, gOptions_premultipliedFieldID); javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID); Loading Loading @@ -352,9 +354,10 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding decodeAllocator = &scaleCheckingAllocator; } else if (javaBitmap != nullptr) { decodeAllocator = &recyclingAllocator; } else if (willScale) { // This will allocate pixels using a HeapAllocator, since there will be an extra // scaling step. } else if (willScale || isHardware) { // This will allocate pixels using a HeapAllocator, // for scale case: there will be an extra scaling step. // for hardware case: there will be extra swizzling & upload to gralloc step. decodeAllocator = &heapAllocator; } else { decodeAllocator = &defaultAllocator; Loading Loading @@ -539,6 +542,12 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding if (isMutable) bitmapCreateFlags |= android::bitmap::kBitmapCreateFlag_Mutable; if (isPremultiplied) bitmapCreateFlags |= android::bitmap::kBitmapCreateFlag_Premultiplied; if (isHardware) { sk_sp<Bitmap> hardwareBitmap = Bitmap::allocateHardwareBitmap(outputBitmap); return bitmap::createBitmap(env, hardwareBitmap.release(), bitmapCreateFlags, ninePatchChunk, ninePatchInsets, -1); } // now create the java bitmap return bitmap::createBitmap(env, defaultAllocator.getStorageObjAndReset(), bitmapCreateFlags, ninePatchChunk, ninePatchInsets, -1); Loading
core/jni/android/graphics/BitmapRegionDecoder.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -131,12 +131,13 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in SkColorType colorType = kN32_SkColorType; bool requireUnpremul = false; jobject javaBitmap = NULL; bool isHardware = false; // Update the default options with any options supplied by the client. if (NULL != options) { sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID); jobject jconfig = env->GetObjectField(options, gOptions_configFieldID); colorType = GraphicsJNI::getNativeBitmapColorType(env, jconfig); isHardware = GraphicsJNI::isHardwareConfig(env, jconfig); requireUnpremul = !env->GetBooleanField(options, gOptions_premultipliedFieldID); javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID); // The Java options of ditherMode and preferQualityOverSpeed are deprecated. We will Loading Loading @@ -202,6 +203,10 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in if (!requireUnpremul) { bitmapCreateFlags |= android::bitmap::kBitmapCreateFlag_Premultiplied; } if (isHardware) { sk_sp<Bitmap> hardwareBitmap = Bitmap::allocateHardwareBitmap(bitmap); return bitmap::createBitmap(env, hardwareBitmap.release(), bitmapCreateFlags); } return android::bitmap::createBitmap(env, heapAlloc.getStorageObjAndReset(), bitmapCreateFlags); } Loading
core/jni/android/graphics/Graphics.cpp +12 −1 Original line number Diff line number Diff line Loading @@ -297,8 +297,9 @@ enum LegacyBitmapConfig { kRGB_565_LegacyBitmapConfig = 3, kARGB_4444_LegacyBitmapConfig = 4, kARGB_8888_LegacyBitmapConfig = 5, kHardware_LegacyBitmapConfig = 6, kLastEnum_LegacyBitmapConfig = kARGB_8888_LegacyBitmapConfig kLastEnum_LegacyBitmapConfig = kHardware_LegacyBitmapConfig }; jint GraphicsJNI::colorTypeToLegacyBitmapConfig(SkColorType colorType) { Loading Loading @@ -327,6 +328,7 @@ SkColorType GraphicsJNI::legacyBitmapConfigToColorType(jint legacyConfig) { kIndex_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kN32_SkColorType, kN32_SkColorType }; Loading Loading @@ -355,6 +357,15 @@ SkColorType GraphicsJNI::getNativeBitmapColorType(JNIEnv* env, jobject jconfig) return legacyBitmapConfigToColorType(c); } bool GraphicsJNI::isHardwareConfig(JNIEnv* env, jobject jconfig) { SkASSERT(env); if (NULL == jconfig) { return false; } int c = env->GetIntField(jconfig, gBitmapConfig_nativeInstanceID); return c == kHardware_LegacyBitmapConfig; } android::Canvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) { SkASSERT(env); SkASSERT(canvas); Loading
core/jni/android/graphics/GraphicsJNI.h +2 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,8 @@ public: */ static SkColorType getNativeBitmapColorType(JNIEnv*, jobject jconfig); static bool isHardwareConfig(JNIEnv* env, jobject jconfig); static jobject createRegion(JNIEnv* env, SkRegion* region); static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap); Loading
graphics/java/android/graphics/Bitmap.java +8 −2 Original line number Diff line number Diff line Loading @@ -463,12 +463,18 @@ public final class Bitmap implements Parcelable { * This configuration is very flexible and offers the best * quality. It should be used whenever possible. */ ARGB_8888 (5); ARGB_8888 (5), /** * @hide */ HARDWARE (6); final int nativeInt; private static Config sConfigs[] = { null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888 null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888, HARDWARE }; Config(int ni) { Loading