diff options
| author | Bryan Mawhinney <bryanmawhinney@google.com> | 2010-11-03 14:05:54 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-11-03 14:05:54 -0700 |
| commit | 8dc287de7f111fe96b953e459c6d25877538fb5c (patch) | |
| tree | e1f27f87033811e1ab40b82f670315dd3f9d8b7e /core | |
| parent | e9702c3989909699444a4fac39b2f1250f2e617b (diff) | |
| parent | 2a3d754549abc4b55e6cfc2d0c986d29782b2492 (diff) | |
| download | frameworks_base-8dc287de7f111fe96b953e459c6d25877538fb5c.zip frameworks_base-8dc287de7f111fe96b953e459c6d25877538fb5c.tar.gz frameworks_base-8dc287de7f111fe96b953e459c6d25877538fb5c.tar.bz2 | |
Merge "Avoid copying byte arrays when just decoding bounds."
Diffstat (limited to 'core')
| -rw-r--r-- | core/jni/android/graphics/BitmapFactory.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 90a0243..3b2406c 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -146,6 +146,11 @@ static bool optionsShareable(JNIEnv* env, jobject options) { env->GetBooleanField(options, gOptions_shareableFieldID); } +static bool optionsJustBounds(JNIEnv* env, jobject options) { + return options != NULL && + env->GetBooleanField(options, gOptions_justBoundsFieldID); +} + static bool optionsReportSizeToVM(JNIEnv* env, jobject options) { return NULL == options || !env->GetBooleanField(options, gOptions_nativeAllocFieldID); @@ -183,7 +188,7 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding, if (NULL != options) { sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID); - if (env->GetBooleanField(options, gOptions_justBoundsFieldID)) { + if (optionsJustBounds(env, options)) { mode = SkImageDecoder::kDecodeBounds_Mode; } // initialize these, in case we fail later on @@ -415,13 +420,14 @@ static jobject nativeDecodeByteArray(JNIEnv* env, jobject, jbyteArray byteArray, /* If optionsShareable() we could decide to just wrap the java array and share it, but that means adding a globalref to the java array object and managing its lifetime. For now we just always copy the array's data - if optionsPurgeable(). + if optionsPurgeable(), unless we're just decoding bounds. */ + bool purgeable = optionsPurgeable(env, options) + && !optionsJustBounds(env, options); AutoJavaByteArray ar(env, byteArray); - SkStream* stream = new SkMemoryStream(ar.ptr() + offset, length, - optionsPurgeable(env, options)); + SkStream* stream = new SkMemoryStream(ar.ptr() + offset, length, purgeable); SkAutoUnref aur(stream); - return doDecode(env, stream, NULL, options, true); + return doDecode(env, stream, NULL, options, purgeable); } static void nativeRequestCancel(JNIEnv*, jobject joptions) { |
