diff options
author | Leon Scroggins III <scroggo@google.com> | 2013-08-29 10:24:21 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-08-29 10:24:21 -0700 |
commit | f7142e3e8bfba982ad73a7c7a6a992491b7cfb43 (patch) | |
tree | d865e27f612159e371787b6bd3df45ae1ba4a8b1 /graphics | |
parent | f5b43bdc6231df8b646d5bbb215e639230f37260 (diff) | |
parent | af1725190fbb8dd7c29726f8b7c072f3af734aed (diff) | |
download | frameworks_base-f7142e3e8bfba982ad73a7c7a6a992491b7cfb43.zip frameworks_base-f7142e3e8bfba982ad73a7c7a6a992491b7cfb43.tar.gz frameworks_base-f7142e3e8bfba982ad73a7c7a6a992491b7cfb43.tar.bz2 |
am af172519: am 4b299312: Merge "Replace stream wrap-function w/ more specific ones" into klp-dev
* commit 'af1725190fbb8dd7c29726f8b7c072f3af734aed':
Replace stream wrap-function w/ more specific ones
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/BitmapFactory.java | 74 | ||||
-rw-r--r-- | graphics/java/android/graphics/BitmapRegionDecoder.java | 7 |
2 files changed, 44 insertions, 37 deletions
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java index 5ace987..ea53f20 100644 --- a/graphics/java/android/graphics/BitmapFactory.java +++ b/graphics/java/android/graphics/BitmapFactory.java @@ -23,7 +23,6 @@ import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; -import java.io.BufferedInputStream; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.IOException; @@ -550,28 +549,28 @@ public class BitmapFactory { return null; } - Bitmap bm; + Bitmap bm = null; Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap"); try { - // we need mark/reset to work properly - if (!is.markSupported()) { - is = new BufferedInputStream(is, DECODE_BUFFER_SIZE); - } - - // so we can call reset() if a given codec gives up after reading up to - // this many bytes. FIXME: need to find out from the codecs what this - // value should be. - is.mark(1024); - + boolean decodeGenericStream = true; if (is instanceof AssetManager.AssetInputStream) { final int asset = ((AssetManager.AssetInputStream) is).getAssetInt(); bm = nativeDecodeAsset(asset, outPadding, opts); - } else { - // pass some temp storage down to the native code. 1024 is made up, - // but should be large enough to avoid too many small calls back - // into is.read(...) This number is not related to the value passed - // to mark(...) above. + // Do not follow the normal case. + decodeGenericStream = false; + } else if (is instanceof FileInputStream) { + try { + FileDescriptor fd = ((FileInputStream) is).getFD(); + // decodeFileDescriptor will take care of throwing the IAE and + // calling setDensityFromOptions. + return decodeFileDescriptor(fd, outPadding, opts); + } catch (IOException e) { + // Fall through to nativeDecodeStream. + } + } + + if (decodeGenericStream) { byte [] tempStorage = null; if (opts != null) tempStorage = opts.inTempStorage; if (tempStorage == null) tempStorage = new byte[DECODE_BUFFER_SIZE]; @@ -615,26 +614,41 @@ public class BitmapFactory { * no bitmap is returned (null) then padding is * unchanged. * @param opts null-ok; Options that control downsampling and whether the - * image should be completely decoded, or just is size returned. + * image should be completely decoded, or just its size returned. * @return the decoded bitmap, or null */ public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts) { - if (nativeIsSeekable(fd)) { - Bitmap bm = nativeDecodeFileDescriptor(fd, outPadding, opts); + Bitmap bm; + + Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeFileDescriptor"); + try { + if (nativeIsSeekable(fd)) { + bm = nativeDecodeFileDescriptor(fd, outPadding, opts); + } else { + FileInputStream fis = new FileInputStream(fd); + // FIXME: If nativeDecodeStream grabbed the pointer to tempStorage + // from Options, this code would not need to be duplicated. + byte [] tempStorage = null; + if (opts != null) tempStorage = opts.inTempStorage; + if (tempStorage == null) tempStorage = new byte[DECODE_BUFFER_SIZE]; + try { + bm = nativeDecodeStream(fis, tempStorage, outPadding, opts); + } finally { + try { + fis.close(); + } catch (Throwable t) {/* ignore */} + } + } + if (bm == null && opts != null && opts.inBitmap != null) { throw new IllegalArgumentException("Problem decoding into existing bitmap"); } - return bm; - } else { - FileInputStream fis = new FileInputStream(fd); - try { - return decodeStream(fis, outPadding, opts); - } finally { - try { - fis.close(); - } catch (Throwable t) {/* ignore */} - } + + setDensityFromOptions(bm, opts); + } finally { + Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS); } + return bm; } /** diff --git a/graphics/java/android/graphics/BitmapRegionDecoder.java b/graphics/java/android/graphics/BitmapRegionDecoder.java index b38d107..3524b25 100644 --- a/graphics/java/android/graphics/BitmapRegionDecoder.java +++ b/graphics/java/android/graphics/BitmapRegionDecoder.java @@ -17,7 +17,6 @@ package android.graphics; import android.content.res.AssetManager; -import java.io.BufferedInputStream; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.IOException; @@ -108,12 +107,6 @@ public final class BitmapRegionDecoder { */ public static BitmapRegionDecoder newInstance(InputStream is, boolean isShareable) throws IOException { - // we need mark/reset to work properly in JNI - - if (!is.markSupported()) { - is = new BufferedInputStream(is, 16 * 1024); - } - if (is instanceof AssetManager.AssetInputStream) { return nativeNewInstance( ((AssetManager.AssetInputStream) is).getAssetInt(), |