diff options
| author | Leon Scroggins III <scroggo@google.com> | 2018-01-31 20:39:37 -0500 |
|---|---|---|
| committer | Leon Scroggins III <scroggo@google.com> | 2018-02-06 10:21:36 -0500 |
| commit | 40c59fdef0087ea0325e447ae0ee113cc8ca7c15 (patch) | |
| tree | a1eb2bd7e4d0f9fa5c01611c1c4e17b946026300 /core/java/android | |
| parent | 34b58512cbec4b77803d412e4ce089a95dd1fec2 (diff) | |
Call ImageDecoder directly in ResourcesImpl
Test: Existing tests
Add a new (hidden) ImageDecoder.Source that accepts an AssetInputStream.
This allows us to create an AnimatedImageDrawable without fear of the
client closing the stream.
Call it from ResourcesImpl instead of Drawable.createFromResourceStream.
Change-Id: I07e00ca60c97538335a6310e830b73211fd8e7bb
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/content/res/ResourcesImpl.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/core/java/android/content/res/ResourcesImpl.java b/core/java/android/content/res/ResourcesImpl.java index 97cb78bc4243..00e4841044cd 100644 --- a/core/java/android/content/res/ResourcesImpl.java +++ b/core/java/android/content/res/ResourcesImpl.java @@ -27,9 +27,11 @@ import android.annotation.StyleRes; import android.annotation.StyleableRes; import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo.Config; +import android.content.res.AssetManager.AssetInputStream; import android.content.res.Configuration.NativeConfig; import android.content.res.Resources.NotFoundException; import android.graphics.Bitmap; +import android.graphics.ImageDecoder; import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; @@ -809,8 +811,13 @@ public class ResourcesImpl { } else { final InputStream is = mAssets.openNonAsset( value.assetCookie, file, AssetManager.ACCESS_STREAMING); - dr = Drawable.createFromResourceStream(wrapper, value, is, file, null); - is.close(); + AssetInputStream ais = (AssetInputStream) is; + // ImageDecoder will close the input stream. + ImageDecoder.Source src = new ImageDecoder.AssetInputStreamSource(ais, + wrapper, value); + dr = ImageDecoder.decodeDrawable(src, (decoder, info, s) -> { + decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE); + }); } } finally { stack.pop(); |
