Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change imageId in AnimatedImageResult from the class hash to decodeHa… #2612

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Integer get() {
}
};

final Supplier<Boolean> useDeepEquals = Suppliers.BOOLEAN_FALSE;
final Supplier<Boolean> useDeepEquals = Suppliers.BOOLEAN_TRUE;

return new ExperimentalBitmapAnimationDrawableFactory(
getAnimatedDrawableBackendProvider(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bitmap> mPreviewBitmap;
Expand All @@ -34,13 +35,18 @@ public class AnimatedImageResult {
mPreviewBitmap = builder.getPreviewBitmap();
mDecodedFrames = builder.getDecodedFrames();
mBitmapTransformation = builder.getBitmapTransformation();
mDecodeHash = builder.getDecodeHash();
}

private AnimatedImageResult(AnimatedImage image) {
mImage = Preconditions.checkNotNull(image);
mFrameForPreview = 0;
}

public int getDecodeHash(){
return mDecodeHash == 0 ? hashCode() : mDecodeHash;
}

/**
* Creates an {@link AnimatedImageResult} with no additional options.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@Nullsafe(Nullsafe.Mode.LOCAL)
public class AnimatedImageResultBuilder {

private int mDecodeHash;
private final AnimatedImage mImage;
private @Nullable CloseableReference<Bitmap> mPreviewBitmap;
private @Nullable List<CloseableReference<Bitmap>> mDecodedFrames;
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I should replace it with cache key

} finally {
CloseableReference.closeSafely(bytesRef);
}
Expand Down Expand Up @@ -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<CloseableReference<Bitmap>> decodedFrames = null;
CloseableReference<Bitmap> previewBitmap = null;
try {
Expand All @@ -157,6 +161,7 @@ private CloseableImage getCloseableImage(
.setFrameForPreview(frameForPreview)
.setDecodedFrames(decodedFrames)
.setBitmapTransformation(options.bitmapTransformation)
.setDecodeHash(valueHash + options.hashCode())
.build();
return new CloseableAnimatedImage(animatedImageResult);
} finally {
Expand Down