Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm authored Oct 31, 2023
2 parents 21d44f7 + 9551d39 commit 3a9951a
Show file tree
Hide file tree
Showing 40 changed files with 408 additions and 1,145 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Fresco supports Android 2.3 (Gingerbread) and later.
If you are building with Gradle, simply add the following line to the `dependencies` section of your `build.gradle` file:

```groovy
implementation 'com.facebook.fresco:fresco:3.1.1'
implementation 'com.facebook.fresco:fresco:3.1.3'
```

For full details, visit the documentation on our web site, available in English and Chinese:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.facebook.imagepipeline.animated.impl.AnimatedDrawableBackendProvider;
import com.facebook.imagepipeline.animated.util.AnimatedDrawableUtil;
import com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory;
import com.facebook.imagepipeline.cache.AnimatedCache;
import com.facebook.imagepipeline.cache.CountingMemoryCache;
import com.facebook.imagepipeline.common.ImageDecodeOptions;
import com.facebook.imagepipeline.core.ExecutorSupplier;
Expand All @@ -47,8 +46,6 @@
public class AnimatedFactoryV2Impl implements AnimatedFactory {

private static final int NUMBER_OF_FRAMES_TO_PREPARE = 3;
private static final int BALANCED_STRATEGY_PREPARATION_MS = 10000; // No CPU

private final PlatformBitmapFactory mPlatformBitmapFactory;
private final ExecutorSupplier mExecutorSupplier;
private final CountingMemoryCache<CacheKey, CloseableImage> mBackingCache;
Expand All @@ -60,30 +57,24 @@ public class AnimatedFactoryV2Impl implements AnimatedFactory {
private @Nullable DrawableFactory mAnimatedDrawableFactory;
private @Nullable SerialExecutorService mSerialExecutorService;
private int mAnimationFpsLimit;
private final AnimatedCache mAnimatedCache;
private final boolean mUseBalancedAnimationStrategy;
private final int mBalancedStrategyPreparationMs;
private final boolean mUseBufferLoaderStrategy;

@DoNotStrip
public AnimatedFactoryV2Impl(
PlatformBitmapFactory platformBitmapFactory,
ExecutorSupplier executorSupplier,
CountingMemoryCache<CacheKey, CloseableImage> backingCache,
AnimatedCache animatedCache,
boolean downscaleFrameToDrawableDimensions,
boolean useBalancedAnimationStrategy,
int balancedStrategyPreparationMs,
boolean useBufferLoaderStrategy,
int animationFpsLimit,
SerialExecutorService serialExecutorServiceForFramePreparing) {
@Nullable SerialExecutorService serialExecutorServiceForFramePreparing) {
mPlatformBitmapFactory = platformBitmapFactory;
mExecutorSupplier = executorSupplier;
mBackingCache = backingCache;
mAnimatedCache = animatedCache;
mAnimationFpsLimit = animationFpsLimit;
mUseBalancedAnimationStrategy = useBalancedAnimationStrategy;
mUseBufferLoaderStrategy = useBufferLoaderStrategy;
mDownscaleFrameToDrawableDimensions = downscaleFrameToDrawableDimensions;
mSerialExecutorService = serialExecutorServiceForFramePreparing;
mBalancedStrategyPreparationMs = balancedStrategyPreparationMs;
}

@Nullable
Expand Down Expand Up @@ -128,7 +119,6 @@ private DefaultBitmapAnimationDrawableFactory createDrawableFactory() {
Supplier<Integer> numberOfFramesToPrepareSupplier = () -> NUMBER_OF_FRAMES_TO_PREPARE;

final Supplier<Boolean> useDeepEquals = Suppliers.BOOLEAN_FALSE;
final Supplier<AnimatedCache> animatedCacheSupplier = () -> mAnimatedCache;

return new DefaultBitmapAnimationDrawableFactory(
getAnimatedDrawableBackendProvider(),
Expand All @@ -137,14 +127,12 @@ private DefaultBitmapAnimationDrawableFactory createDrawableFactory() {
RealtimeSinceBootClock.get(),
mPlatformBitmapFactory,
mBackingCache,
animatedCacheSupplier,
cachingStrategySupplier,
numberOfFramesToPrepareSupplier,
useDeepEquals,
Suppliers.of(mUseBalancedAnimationStrategy),
Suppliers.of(mUseBufferLoaderStrategy),
Suppliers.of(mDownscaleFrameToDrawableDimensions),
Suppliers.of(mAnimationFpsLimit),
Suppliers.of(mBalancedStrategyPreparationMs));
Suppliers.of(mAnimationFpsLimit));
}

private AnimatedDrawableUtil getAnimatedDrawableUtil() {
Expand Down Expand Up @@ -193,8 +181,6 @@ public AnimatedDrawableBackend get(
}
};
return new AnimatedImageFactoryImpl(
animatedDrawableBackendProvider,
mPlatformBitmapFactory,
this.mUseBalancedAnimationStrategy);
animatedDrawableBackendProvider, mPlatformBitmapFactory, mUseBufferLoaderStrategy);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@
import com.facebook.fresco.animation.bitmap.BitmapFrameCache;
import com.facebook.fresco.animation.bitmap.BitmapFrameRenderer;
import com.facebook.fresco.animation.bitmap.cache.AnimationFrameCacheKey;
import com.facebook.fresco.animation.bitmap.cache.FrescoFpsCache;
import com.facebook.fresco.animation.bitmap.cache.FrescoFrameCache;
import com.facebook.fresco.animation.bitmap.cache.KeepLastFrameCache;
import com.facebook.fresco.animation.bitmap.cache.NoOpCache;
import com.facebook.fresco.animation.bitmap.preparation.BalancedAnimationStrategy;
import com.facebook.fresco.animation.bitmap.preparation.BitmapFramePreparationStrategy;
import com.facebook.fresco.animation.bitmap.preparation.BitmapFramePreparer;
import com.facebook.fresco.animation.bitmap.preparation.DefaultBitmapFramePreparer;
import com.facebook.fresco.animation.bitmap.preparation.FixedNumberBitmapFramePreparationStrategy;
import com.facebook.fresco.animation.bitmap.preparation.FrameLoaderStrategy;
import com.facebook.fresco.animation.bitmap.preparation.loadframe.FpsCompressorInfo;
import com.facebook.fresco.animation.bitmap.preparation.loadframe.LoadFrameTaskFactory;
import com.facebook.fresco.animation.bitmap.preparation.ondemandanimation.FrameLoaderFactory;
import com.facebook.fresco.animation.bitmap.wrapper.AnimatedDrawableBackendAnimationInformation;
import com.facebook.fresco.animation.bitmap.wrapper.AnimatedDrawableBackendFrameRenderer;
Expand All @@ -49,7 +45,6 @@
import com.facebook.imagepipeline.animated.impl.AnimatedDrawableBackendProvider;
import com.facebook.imagepipeline.animated.impl.AnimatedFrameCache;
import com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory;
import com.facebook.imagepipeline.cache.AnimatedCache;
import com.facebook.imagepipeline.cache.CountingMemoryCache;
import com.facebook.imagepipeline.drawable.DrawableFactory;
import com.facebook.imagepipeline.image.CloseableAnimatedImage;
Expand Down Expand Up @@ -81,8 +76,6 @@ public class DefaultBitmapAnimationDrawableFactory
private final Supplier<Boolean> mUseDeepEqualsForCacheKey;
private final Supplier<Boolean> mUseNewBitmapRender;
private final Supplier<Boolean> mDownscaleFrameToDrawableDimensions;
private final Supplier<AnimatedCache> mAnimatedDrawableCache;
private final Supplier<Integer> mBalancedStrategyPreparationMs;
private final Supplier<Integer> mAnimationFpsLimit;

// Change the value to true to use KAnimatedDrawable2.kt
Expand All @@ -95,14 +88,12 @@ public DefaultBitmapAnimationDrawableFactory(
MonotonicClock monotonicClock,
PlatformBitmapFactory platformBitmapFactory,
CountingMemoryCache<CacheKey, CloseableImage> backingCache,
Supplier<AnimatedCache> animatedDrawableCache,
Supplier<Integer> cachingStrategySupplier,
Supplier<Integer> numberOfFramesToPrepareSupplier,
Supplier<Boolean> useDeepEqualsForCacheKey,
Supplier<Boolean> useNewBitmapRender,
Supplier<Boolean> downscaleFrameToDrawableDimensions,
Supplier<Integer> animationFpsLimit,
Supplier<Integer> balancedStrategyPreparationMs) {
Supplier<Integer> animationFpsLimit) {
mAnimatedDrawableBackendProvider = animatedDrawableBackendProvider;
mScheduledExecutorServiceForUiThread = scheduledExecutorServiceForUiThread;
mExecutorServiceForFramePreparing = executorServiceForFramePreparing;
Expand All @@ -113,9 +104,7 @@ public DefaultBitmapAnimationDrawableFactory(
mNumberOfFramesToPrepareSupplier = numberOfFramesToPrepareSupplier;
mUseDeepEqualsForCacheKey = useDeepEqualsForCacheKey;
mUseNewBitmapRender = useNewBitmapRender;
mAnimatedDrawableCache = animatedDrawableCache;
mAnimationFpsLimit = animationFpsLimit;
mBalancedStrategyPreparationMs = balancedStrategyPreparationMs;
mDownscaleFrameToDrawableDimensions = downscaleFrameToDrawableDimensions;
}

Expand Down Expand Up @@ -186,23 +175,13 @@ private AnimationBackend createAnimationBackend(
}

if (mUseNewBitmapRender.get()) {
if (mBalancedStrategyPreparationMs.get() != 0) {
bitmapFramePreparationStrategy =
new BalancedAnimationStrategy(
animationInfo,
mBalancedStrategyPreparationMs.get(),
new LoadFrameTaskFactory(mPlatformBitmapFactory, bitmapFrameRenderer),
bitmapFrameCache,
mDownscaleFrameToDrawableDimensions.get());
} else {
bitmapFramePreparationStrategy =
new FrameLoaderStrategy(
animatedImageResult.getSource(),
animationInfo,
bitmapFrameRenderer,
new FrameLoaderFactory(mPlatformBitmapFactory, mAnimationFpsLimit.get()),
mDownscaleFrameToDrawableDimensions.get());
}
bitmapFramePreparationStrategy =
new FrameLoaderStrategy(
animatedImageResult.getSource(),
animationInfo,
bitmapFrameRenderer,
new FrameLoaderFactory(mPlatformBitmapFactory, mAnimationFpsLimit.get()),
mDownscaleFrameToDrawableDimensions.get());
}

BitmapAnimationBackend bitmapAnimationBackend =
Expand Down Expand Up @@ -237,13 +216,6 @@ private AnimatedDrawableBackend createAnimatedDrawableBackend(
}

private BitmapFrameCache createBitmapFrameCache(AnimatedImageResult animatedImageResult) {
if (mUseNewBitmapRender.get()) {
return new FrescoFpsCache(
animatedImageResult,
new FpsCompressorInfo(mAnimationFpsLimit.get()),
mAnimatedDrawableCache.get());
}

switch (mCachingStrategySupplier.get()) {
case CACHING_STRATEGY_FRESCO_CACHE:
return new FrescoFrameCache(createAnimatedFrameCache(animatedImageResult), true);
Expand Down
Loading

0 comments on commit 3a9951a

Please sign in to comment.