From 3afa9e054736a5302b63b687b76300f3bb134393 Mon Sep 17 00:00:00 2001 From: whilecrow <1759992708@qq.com> Date: Thu, 27 May 2021 18:31:01 +0800 Subject: [PATCH] change imageId in AnimatedImageResult from the class hash to decodeHash(encodeRef valueHash + option.hashcode) --- .../animation/factory/AnimatedFactoryV2Impl.java | 2 +- .../ExperimentalBitmapAnimationDrawableFactory.java | 2 +- .../animated/base/AnimatedImageResult.java | 6 ++++++ .../animated/base/AnimatedImageResultBuilder.java | 11 +++++++++++ .../animated/factory/AnimatedImageFactoryImpl.java | 9 +++++++-- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/animated-base/src/main/java/com/facebook/fresco/animation/factory/AnimatedFactoryV2Impl.java b/animated-base/src/main/java/com/facebook/fresco/animation/factory/AnimatedFactoryV2Impl.java index d9036b84a0..65ecb3df91 100644 --- a/animated-base/src/main/java/com/facebook/fresco/animation/factory/AnimatedFactoryV2Impl.java +++ b/animated-base/src/main/java/com/facebook/fresco/animation/factory/AnimatedFactoryV2Impl.java @@ -134,7 +134,7 @@ public Integer get() { } }; - final Supplier useDeepEquals = Suppliers.BOOLEAN_FALSE; + final Supplier useDeepEquals = Suppliers.BOOLEAN_TRUE; return new ExperimentalBitmapAnimationDrawableFactory( getAnimatedDrawableBackendProvider(), diff --git a/animated-base/src/main/java/com/facebook/fresco/animation/factory/ExperimentalBitmapAnimationDrawableFactory.java b/animated-base/src/main/java/com/facebook/fresco/animation/factory/ExperimentalBitmapAnimationDrawableFactory.java index 14caa75261..cd411cb967 100644 --- a/animated-base/src/main/java/com/facebook/fresco/animation/factory/ExperimentalBitmapAnimationDrawableFactory.java +++ b/animated-base/src/main/java/com/facebook/fresco/animation/factory/ExperimentalBitmapAnimationDrawableFactory.java @@ -163,7 +163,7 @@ private BitmapFrameCache createBitmapFrameCache(AnimatedImageResult animatedImag private AnimatedFrameCache createAnimatedFrameCache( final AnimatedImageResult animatedImageResult) { return new AnimatedFrameCache( - new AnimationFrameCacheKey(animatedImageResult.hashCode(), mUseDeepEqualsForCacheKey.get()), + new AnimationFrameCacheKey(animatedImageResult.getDecodeHash(), mUseDeepEqualsForCacheKey.get()), mBackingCache); } } diff --git a/animated-base/src/main/java/com/facebook/imagepipeline/animated/base/AnimatedImageResult.java b/animated-base/src/main/java/com/facebook/imagepipeline/animated/base/AnimatedImageResult.java index f64b998b95..03cecc191f 100644 --- a/animated-base/src/main/java/com/facebook/imagepipeline/animated/base/AnimatedImageResult.java +++ b/animated-base/src/main/java/com/facebook/imagepipeline/animated/base/AnimatedImageResult.java @@ -22,6 +22,7 @@ @Nullsafe(Nullsafe.Mode.LOCAL) public class AnimatedImageResult { + private int mDecodeHash; private final AnimatedImage mImage; private final int mFrameForPreview; private @Nullable CloseableReference mPreviewBitmap; @@ -34,6 +35,7 @@ public class AnimatedImageResult { mPreviewBitmap = builder.getPreviewBitmap(); mDecodedFrames = builder.getDecodedFrames(); mBitmapTransformation = builder.getBitmapTransformation(); + mDecodeHash = builder.getDecodeHash(); } private AnimatedImageResult(AnimatedImage image) { @@ -41,6 +43,10 @@ private AnimatedImageResult(AnimatedImage image) { mFrameForPreview = 0; } + public int getDecodeHash(){ + return mDecodeHash == 0 ? hashCode() : mDecodeHash; + } + /** * Creates an {@link AnimatedImageResult} with no additional options. * diff --git a/animated-base/src/main/java/com/facebook/imagepipeline/animated/base/AnimatedImageResultBuilder.java b/animated-base/src/main/java/com/facebook/imagepipeline/animated/base/AnimatedImageResultBuilder.java index 00d9a1b4dc..8d07bb0125 100644 --- a/animated-base/src/main/java/com/facebook/imagepipeline/animated/base/AnimatedImageResultBuilder.java +++ b/animated-base/src/main/java/com/facebook/imagepipeline/animated/base/AnimatedImageResultBuilder.java @@ -18,6 +18,7 @@ @Nullsafe(Nullsafe.Mode.LOCAL) public class AnimatedImageResultBuilder { + private int mDecodeHash; private final AnimatedImage mImage; private @Nullable CloseableReference mPreviewBitmap; private @Nullable List> mDecodedFrames; @@ -28,6 +29,16 @@ public class AnimatedImageResultBuilder { mImage = image; } + + public int getDecodeHash() { + return mDecodeHash; + } + + public AnimatedImageResultBuilder setDecodeHash(int decodeHash) { + this.mDecodeHash = decodeHash; + return this; + } + /** * Gets the image for the result. * diff --git a/animated-base/src/main/java/com/facebook/imagepipeline/animated/factory/AnimatedImageFactoryImpl.java b/animated-base/src/main/java/com/facebook/imagepipeline/animated/factory/AnimatedImageFactoryImpl.java index c6ea29cf31..8d13220de4 100644 --- a/animated-base/src/main/java/com/facebook/imagepipeline/animated/factory/AnimatedImageFactoryImpl.java +++ b/animated-base/src/main/java/com/facebook/imagepipeline/animated/factory/AnimatedImageFactoryImpl.java @@ -90,7 +90,7 @@ public CloseableImage decodeGif( sGifAnimatedImageDecoder.decodeFromNativeMemory( input.getNativePtr(), input.size(), options); } - return getCloseableImage(options, gifImage, bitmapConfig); + return getCloseableImage(bytesRef.getValueHash(), options, gifImage, bitmapConfig); } finally { CloseableReference.closeSafely(bytesRef); } @@ -130,8 +130,12 @@ public CloseableImage decodeWebP( } } + private CloseableImage getCloseableImage(ImageDecodeOptions options, AnimatedImage image, Bitmap.Config bitmapConfig) { + return getCloseableImage(0, options, image, bitmapConfig); + } + private CloseableImage getCloseableImage( - ImageDecodeOptions options, AnimatedImage image, Bitmap.Config bitmapConfig) { + int valueHash, ImageDecodeOptions options, AnimatedImage image, Bitmap.Config bitmapConfig) { List> decodedFrames = null; CloseableReference previewBitmap = null; try { @@ -157,6 +161,7 @@ private CloseableImage getCloseableImage( .setFrameForPreview(frameForPreview) .setDecodedFrames(decodedFrames) .setBitmapTransformation(options.bitmapTransformation) + .setDecodeHash(valueHash + options.hashCode()) .build(); return new CloseableAnimatedImage(animatedImageResult); } finally {