diff options
| author | 2019-08-15 23:29:03 +0000 | |
|---|---|---|
| committer | 2019-08-15 23:29:03 +0000 | |
| commit | f333b2caa29520a2c02e8b88d8a58fad48d3f385 (patch) | |
| tree | 80e136fc703307f4077f5042006138f2532d5ce2 /graphics/java/android | |
| parent | ff31612e9891d9b12ccbf6a9d59d55f303fa719f (diff) | |
| parent | cba2792567e06693c96cfeb1a14176ca14add41d (diff) | |
Merge "Prefer animation in ImageDecoder.decodeDrawable"
Diffstat (limited to 'graphics/java/android')
| -rw-r--r-- | graphics/java/android/graphics/ImageDecoder.java | 80 |
1 files changed, 41 insertions, 39 deletions
diff --git a/graphics/java/android/graphics/ImageDecoder.java b/graphics/java/android/graphics/ImageDecoder.java index 2d5babc5ebdb..150a941c061e 100644 --- a/graphics/java/android/graphics/ImageDecoder.java +++ b/graphics/java/android/graphics/ImageDecoder.java @@ -214,7 +214,7 @@ public final class ImageDecoder implements AutoCloseable { /* @hide */ @NonNull - abstract ImageDecoder createImageDecoder() throws IOException; + abstract ImageDecoder createImageDecoder(boolean preferAnimation) throws IOException; }; private static class ByteArraySource extends Source { @@ -228,8 +228,8 @@ public final class ImageDecoder implements AutoCloseable { private final int mLength; @Override - public ImageDecoder createImageDecoder() throws IOException { - return nCreate(mData, mOffset, mLength, this); + public ImageDecoder createImageDecoder(boolean preferAnimation) throws IOException { + return nCreate(mData, mOffset, mLength, preferAnimation, this); } } @@ -240,14 +240,14 @@ public final class ImageDecoder implements AutoCloseable { private final ByteBuffer mBuffer; @Override - public ImageDecoder createImageDecoder() throws IOException { + public ImageDecoder createImageDecoder(boolean preferAnimation) throws IOException { if (!mBuffer.isDirect() && mBuffer.hasArray()) { int offset = mBuffer.arrayOffset() + mBuffer.position(); int length = mBuffer.limit() - mBuffer.position(); - return nCreate(mBuffer.array(), offset, length, this); + return nCreate(mBuffer.array(), offset, length, preferAnimation, this); } ByteBuffer buffer = mBuffer.slice(); - return nCreate(buffer, buffer.position(), buffer.limit(), this); + return nCreate(buffer, buffer.position(), buffer.limit(), preferAnimation, this); } } @@ -267,7 +267,7 @@ public final class ImageDecoder implements AutoCloseable { Resources getResources() { return mResources; } @Override - public ImageDecoder createImageDecoder() throws IOException { + public ImageDecoder createImageDecoder(boolean preferAnimation) throws IOException { AssetFileDescriptor assetFd = null; try { if (mUri.getScheme() == ContentResolver.SCHEME_CONTENT) { @@ -284,26 +284,26 @@ public final class ImageDecoder implements AutoCloseable { throw new FileNotFoundException(mUri.toString()); } - return createFromStream(is, true, this); + return createFromStream(is, true, preferAnimation, this); } - return createFromAssetFileDescriptor(assetFd, this); + return createFromAssetFileDescriptor(assetFd, preferAnimation, this); } } @NonNull private static ImageDecoder createFromFile(@NonNull File file, - @NonNull Source source) throws IOException { + boolean preferAnimation, @NonNull Source source) throws IOException { FileInputStream stream = new FileInputStream(file); FileDescriptor fd = stream.getFD(); try { Os.lseek(fd, 0, SEEK_CUR); } catch (ErrnoException e) { - return createFromStream(stream, true, source); + return createFromStream(stream, true, preferAnimation, source); } ImageDecoder decoder = null; try { - decoder = nCreate(fd, source); + decoder = nCreate(fd, preferAnimation, source); } finally { if (decoder == null) { IoUtils.closeQuietly(stream); @@ -317,12 +317,12 @@ public final class ImageDecoder implements AutoCloseable { @NonNull private static ImageDecoder createFromStream(@NonNull InputStream is, - boolean closeInputStream, Source source) throws IOException { + boolean closeInputStream, boolean preferAnimation, Source source) throws IOException { // Arbitrary size matches BitmapFactory. byte[] storage = new byte[16 * 1024]; ImageDecoder decoder = null; try { - decoder = nCreate(is, storage, source); + decoder = nCreate(is, storage, preferAnimation, source); } finally { if (decoder == null) { if (closeInputStream) { @@ -340,7 +340,7 @@ public final class ImageDecoder implements AutoCloseable { @NonNull private static ImageDecoder createFromAssetFileDescriptor(@NonNull AssetFileDescriptor assetFd, - Source source) throws IOException { + boolean preferAnimation, Source source) throws IOException { final FileDescriptor fd = assetFd.getFileDescriptor(); final long offset = assetFd.getStartOffset(); @@ -348,9 +348,9 @@ public final class ImageDecoder implements AutoCloseable { try { try { Os.lseek(fd, offset, SEEK_SET); - decoder = nCreate(fd, source); + decoder = nCreate(fd, preferAnimation, source); } catch (ErrnoException e) { - decoder = createFromStream(new FileInputStream(fd), true, source); + decoder = createFromStream(new FileInputStream(fd), true, preferAnimation, source); } } finally { if (decoder == null) { @@ -388,7 +388,7 @@ public final class ImageDecoder implements AutoCloseable { public int getDensity() { return mInputDensity; } @Override - public ImageDecoder createImageDecoder() throws IOException { + public ImageDecoder createImageDecoder(boolean preferAnimation) throws IOException { synchronized (this) { if (mInputStream == null) { @@ -396,7 +396,7 @@ public final class ImageDecoder implements AutoCloseable { } InputStream is = mInputStream; mInputStream = null; - return createFromStream(is, false, this); + return createFromStream(is, false, preferAnimation, this); } } } @@ -434,14 +434,14 @@ public final class ImageDecoder implements AutoCloseable { } @Override - public ImageDecoder createImageDecoder() throws IOException { + public ImageDecoder createImageDecoder(boolean preferAnimation) throws IOException { synchronized (this) { if (mAssetInputStream == null) { throw new IOException("Cannot reuse AssetInputStreamSource"); } AssetInputStream ais = mAssetInputStream; mAssetInputStream = null; - return createFromAsset(ais, this); + return createFromAsset(ais, preferAnimation, this); } } } @@ -469,7 +469,7 @@ public final class ImageDecoder implements AutoCloseable { } @Override - public ImageDecoder createImageDecoder() throws IOException { + public ImageDecoder createImageDecoder(boolean preferAnimation) throws IOException { TypedValue value = new TypedValue(); // This is just used in order to access the underlying Asset and // keep it alive. @@ -483,7 +483,7 @@ public final class ImageDecoder implements AutoCloseable { } } - return createFromAsset((AssetInputStream) is, this); + return createFromAsset((AssetInputStream) is, preferAnimation, this); } } @@ -491,11 +491,11 @@ public final class ImageDecoder implements AutoCloseable { * ImageDecoder will own the AssetInputStream. */ private static ImageDecoder createFromAsset(AssetInputStream ais, - Source source) throws IOException { + boolean preferAnimation, Source source) throws IOException { ImageDecoder decoder = null; try { long asset = ais.getNativeAsset(); - decoder = nCreate(asset, source); + decoder = nCreate(asset, preferAnimation, source); } finally { if (decoder == null) { IoUtils.closeQuietly(ais); @@ -517,9 +517,9 @@ public final class ImageDecoder implements AutoCloseable { private final String mFileName; @Override - public ImageDecoder createImageDecoder() throws IOException { + public ImageDecoder createImageDecoder(boolean preferAnimation) throws IOException { InputStream is = mAssets.open(mFileName); - return createFromAsset((AssetInputStream) is, this); + return createFromAsset((AssetInputStream) is, preferAnimation, this); } } @@ -531,8 +531,8 @@ public final class ImageDecoder implements AutoCloseable { private final File mFile; @Override - public ImageDecoder createImageDecoder() throws IOException { - return createFromFile(mFile, this); + public ImageDecoder createImageDecoder(boolean preferAnimation) throws IOException { + return createFromFile(mFile, preferAnimation, this); } } @@ -544,7 +544,7 @@ public final class ImageDecoder implements AutoCloseable { private final Callable<AssetFileDescriptor> mCallable; @Override - public ImageDecoder createImageDecoder() throws IOException { + public ImageDecoder createImageDecoder(boolean preferAnimation) throws IOException { AssetFileDescriptor assetFd = null; try { assetFd = mCallable.call(); @@ -555,7 +555,7 @@ public final class ImageDecoder implements AutoCloseable { throw new IOException(e); } } - return createFromAssetFileDescriptor(assetFd, this); + return createFromAssetFileDescriptor(assetFd, preferAnimation, this); } } @@ -1740,7 +1740,7 @@ public final class ImageDecoder implements AutoCloseable { @NonNull private static Drawable decodeDrawableImpl(@NonNull Source src, @Nullable OnHeaderDecodedListener listener) throws IOException { - try (ImageDecoder decoder = src.createImageDecoder()) { + try (ImageDecoder decoder = src.createImageDecoder(true /*preferAnimation*/)) { decoder.mSource = src; decoder.callHeaderDecoded(listener, src); @@ -1844,7 +1844,7 @@ public final class ImageDecoder implements AutoCloseable { @NonNull private static Bitmap decodeBitmapImpl(@NonNull Source src, @Nullable OnHeaderDecodedListener listener) throws IOException { - try (ImageDecoder decoder = src.createImageDecoder()) { + try (ImageDecoder decoder = src.createImageDecoder(false /*preferAnimation*/)) { decoder.mSource = src; decoder.callHeaderDecoded(listener, src); @@ -1971,15 +1971,17 @@ public final class ImageDecoder implements AutoCloseable { } } - private static native ImageDecoder nCreate(long asset, Source src) throws IOException; - private static native ImageDecoder nCreate(ByteBuffer buffer, int position, - int limit, Source src) throws IOException; + private static native ImageDecoder nCreate(long asset, + boolean preferAnimation, Source src) throws IOException; + private static native ImageDecoder nCreate(ByteBuffer buffer, int position, int limit, + boolean preferAnimation, Source src) throws IOException; private static native ImageDecoder nCreate(byte[] data, int offset, int length, - Source src) throws IOException; + boolean preferAnimation, Source src) throws IOException; private static native ImageDecoder nCreate(InputStream is, byte[] storage, - Source src) throws IOException; + boolean preferAnimation, Source src) throws IOException; // The fd must be seekable. - private static native ImageDecoder nCreate(FileDescriptor fd, Source src) throws IOException; + private static native ImageDecoder nCreate(FileDescriptor fd, + boolean preferAnimation, Source src) throws IOException; @NonNull private static native Bitmap nDecodeBitmap(long nativePtr, @NonNull ImageDecoder decoder, |