From ab4a0c164b5a44d5bfd37069cfe499db31e7620c Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Tue, 26 Jan 2010 10:13:53 -0500 Subject: add API to change default config on image decoders. May be called by the browser to get high-quality images when running in a 32bit window --- core/jni/android/graphics/BitmapFactory.cpp | 20 ++++++++++++++++++- graphics/java/android/graphics/BitmapFactory.java | 24 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 65f6845..9965fe5 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -645,6 +645,23 @@ static jbyteArray nativeScaleNinePatch(JNIEnv* env, jobject, jbyteArray chunkObj return chunkObject; } +static void nativeSetDefaultConfig(JNIEnv* env, jobject, int nativeConfig) { + SkBitmap::Config config = static_cast(nativeConfig); + + // these are the only default configs that make sense for codecs right now + static const SkBitmap::Config gValidDefConfig[] = { + SkBitmap::kRGB_565_Config, + SkBitmap::kARGB_8888_Config, + }; + + for (size_t i = 0; i < SK_ARRAY_COUNT(gValidDefConfig); i++) { + if (config == gValidDefConfig[i]) { + SkImageDecoder::SetDeviceConfig(config); + break; + } + } +} + /////////////////////////////////////////////////////////////////////////////// static JNINativeMethod gMethods[] = { @@ -671,8 +688,9 @@ static JNINativeMethod gMethods[] = { { "nativeScaleNinePatch", "([BFLandroid/graphics/Rect;)[B", (void*)nativeScaleNinePatch - } + }, + { "nativeSetDefaultConfig", "(I)V", (void*)nativeSetDefaultConfig }, }; static JNINativeMethod gOptionsMethods[] = { diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java index 3c03eed..2313f4c 100644 --- a/graphics/java/android/graphics/BitmapFactory.java +++ b/graphics/java/android/graphics/BitmapFactory.java @@ -558,6 +558,30 @@ public class BitmapFactory { return decodeFileDescriptor(fd, null, null); } + /** + * Set the default config used for decoding bitmaps. This config is + * presented to the codec if the caller did not specify a preferred config + * in their call to decode... + * + * The default value is chosen by the system to best match the device's + * screen and memory constraints. + * + * @param config The preferred config for decoding bitmaps. If null, then + * a suitable default is chosen by the system. + * + * @hide - only called by the browser at the moment, but should be stable + * enough to expose if needed + */ + public static void setDefaultConfig(Bitmap.Config config) { + if (config == null) { + // pick this for now, as historically it was our default. + // However, if we have a smarter algorithm, we can change this. + config = Bitmap.Config.RGB_565; + } + nativeSetDefaultConfig(config.nativeInt); + } + + private static native void nativeSetDefaultConfig(int nativeConfig); private static native Bitmap nativeDecodeStream(InputStream is, byte[] storage, Rect padding, Options opts); private static native Bitmap nativeDecodeFileDescriptor(FileDescriptor fd, -- cgit v1.1