diff options
Diffstat (limited to 'library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java')
-rw-r--r-- | library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java | 39 |
1 files changed, 3 insertions, 36 deletions
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java index 773203b9..32dce79a 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java @@ -5,26 +5,17 @@ import android.graphics.Bitmap; import android.os.Handler; import android.os.Looper; import android.os.SystemClock; - import com.bumptech.glide.Glide; import com.bumptech.glide.gifdecoder.GifDecoder; import com.bumptech.glide.load.Encoder; -import com.bumptech.glide.load.ResourceDecoder; -import com.bumptech.glide.load.ResourceEncoder; import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import com.bumptech.glide.load.engine.cache.MemorySizeCalculator; -import com.bumptech.glide.load.resource.NullDecoder; import com.bumptech.glide.load.resource.NullEncoder; -import com.bumptech.glide.load.resource.NullResourceEncoder; -import com.bumptech.glide.load.resource.bitmap.BitmapEncoder; -import com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder; -import com.bumptech.glide.load.resource.file.FileToStreamDecoder; import com.bumptech.glide.request.animation.GlideAnimation; import com.bumptech.glide.request.target.SimpleTarget; - -import java.io.File; +import com.bumptech.glide.util.Util; class GifFrameManager { /** 60fps is {@value #MIN_FRAME_DELAY}ms per frame. */ @@ -32,10 +23,8 @@ class GifFrameManager { private final MemorySizeCalculator calculator; private final GifFrameModelLoader frameLoader; private final GifFrameResourceDecoder frameResourceDecoder; - private final ResourceDecoder<File, Bitmap> cacheDecoder; private final GifDecoder decoder; private final Handler mainHandler; - private final ResourceEncoder<Bitmap> encoder; private final Context context; private final Encoder<GifDecoder> sourceEncoder; private final Transformation<Bitmap>[] transformation; @@ -69,23 +58,11 @@ class GifFrameManager { this.transformation = new Transformation[] {transformation}; this.targetWidth = targetWidth; this.targetHeight = targetHeight; - this.totalFrameSize = frameWidth * frameHeight * (decoder.isTransparent() ? 4 : 2); + this.totalFrameSize = Util.getBitmapByteSize(frameWidth, frameHeight, Bitmap.Config.ARGB_8888); this.calculator = new MemorySizeCalculator(context); this.frameLoader = new GifFrameModelLoader(); this.sourceEncoder = NullEncoder.get(); - - if (!decoder.isTransparent()) { - // For non transparent gifs, we can beat the performance of our gif decoder for each frame by decoding jpegs - // from disk. - this.cacheDecoder = new FileToStreamDecoder<Bitmap>(new StreamBitmapDecoder(context)); - this.encoder = new BitmapEncoder(); - } else { - // For transparent gifs, we would have to encode as pngs which is actually slower than our gif decoder so we - // avoid writing frames to the disk cache entirely. - this.cacheDecoder = NullDecoder.get(); - this.encoder = NullResourceEncoder.get(); - } } Transformation<Bitmap> getTransformation() { @@ -95,17 +72,9 @@ class GifFrameManager { public void getNextFrame(FrameCallback cb) { decoder.advance(); - /** - * Note - Using the disk cache can potentially cause frames to be decoded incorrectly because the decoder is - * sequential. If earlier frames are evicted for some reason, later ones may then not be decoded correctly. - */ - // We don't want to blow out the entire memory cache with frames of gifs, so try to set some // maximum size beyond which we will always just decode one frame at a time. boolean skipCache = totalFrameSize > calculator.getMemoryCacheSize() / 2; - // We can decode non transparent (cached as jpegs) frames more quickly from cache, but transparent - // (cached as png) frames more quickly from the gif data. - boolean skipDiskCache = decoder.isTransparent(); long targetTime = SystemClock.uptimeMillis() + Math.max(MIN_FRAME_DELAY, decoder.getNextDelay()); next = new DelayTarget(cb, targetTime); @@ -117,11 +86,9 @@ class GifFrameManager { .as(Bitmap.class) .sourceEncoder(sourceEncoder) .decoder(frameResourceDecoder) - .cacheDecoder(cacheDecoder) - .encoder(encoder) .transform(transformation) .skipMemoryCache(skipCache) - .diskCacheStrategy(skipDiskCache ? DiskCacheStrategy.NONE : DiskCacheStrategy.RESULT) + .diskCacheStrategy(DiskCacheStrategy.NONE) .into(next); } |