public class

FrescoFrameCache

extends Object
implements BitmapFrameCache
java.lang.Object
   ↳ com.facebook.fresco.animation.bitmap.cache.FrescoFrameCache

Class Overview

Bitmap frame cache that uses Fresco's AnimatedFrameCache to cache frames.

Summary

Public Constructors
FrescoFrameCache(AnimatedFrameCache animatedFrameCache, boolean enableBitmapReusing)
Public Methods
synchronized void clear()
Clear the cache.
synchronized boolean contains(int frameNumber)
Check whether the cache contains a certain frame.
synchronized CloseableReference<Bitmap> getBitmapToReuseForFrame(int frameNumber, int width, int height)
Return a reusable bitmap that should be used to render the given frame.
synchronized CloseableReference<Bitmap> getCachedFrame(int frameNumber)
Get the cached frame for the given frame number.
synchronized CloseableReference<Bitmap> getFallbackFrame(int frameNumber)
Get a fallback frame for the given frame number.
synchronized int getSizeInBytes()
synchronized void onFramePrepared(int frameNumber, CloseableReference<Bitmap> bitmapReference, int frameType)
Callback when a bitmap reference for a given frame has been prepared for future rendering.
synchronized void onFrameRendered(int frameNumber, CloseableReference<Bitmap> bitmapReference, int frameType)
Callback when the given bitmap has been drawn to a canvas.
void setFrameCacheListener(BitmapFrameCache.FrameCacheListener frameCacheListener)
Set a frame cache listener that gets notified about caching events.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.facebook.fresco.animation.bitmap.BitmapFrameCache

Public Constructors

public FrescoFrameCache (AnimatedFrameCache animatedFrameCache, boolean enableBitmapReusing)

Public Methods

public synchronized void clear ()

Clear the cache.

public synchronized boolean contains (int frameNumber)

Check whether the cache contains a certain frame.

Parameters
frameNumber the frame number to check
Returns
  • true if the frame is cached

public synchronized CloseableReference<Bitmap> getBitmapToReuseForFrame (int frameNumber, int width, int height)

Return a reusable bitmap that should be used to render the given frame.

Parameters
frameNumber the frame number to be rendered
width the width of the target bitmap
height the height of the target bitmap
Returns
  • the reusable bitmap or null if no reusable bitmaps available

public synchronized CloseableReference<Bitmap> getCachedFrame (int frameNumber)

Get the cached frame for the given frame number.

Parameters
frameNumber the frame number to get the cached frame for
Returns
  • the cached frame or null if not cached

public synchronized CloseableReference<Bitmap> getFallbackFrame (int frameNumber)

Get a fallback frame for the given frame number. This method is called if all other attempts to draw a frame failed. The bitmap returned could for example be the last drawn frame (if any).

Parameters
frameNumber the frame number to get the fallback
Returns
  • the fallback frame or null if not cached

public synchronized int getSizeInBytes ()

public synchronized void onFramePrepared (int frameNumber, CloseableReference<Bitmap> bitmapReference, int frameType)

Callback when a bitmap reference for a given frame has been prepared for future rendering.

This method is called ahead of render time (i.e. when future frames have been prepared in the background), whereas onFrameRendered(int, CloseableReference, int) is invoked when the actual frame has been drawn on a Canvas.

The supplied bitmap reference can either hold a reused bitmap returned by getBitmapToReuseForFrame(int, int, int) or a new bitmap as indicated by the frame type parameter.

Note: the implementation of this interface must manually clone the given bitmap reference if it wants to hold on to the bitmap. The original reference will be automatically closed after this call.

Parameters
frameNumber the frame number of the passed bitmapReference
bitmapReference the bitmap reference that has been prepared for future rendering
frameType the frame type of the prepared frame
Returns
  • true if the frame has been successfully cached

public synchronized void onFrameRendered (int frameNumber, CloseableReference<Bitmap> bitmapReference, int frameType)

Callback when the given bitmap has been drawn to a canvas. This bitmap can either be a reused bitmap returned by getBitmapToReuseForFrame(int, int, int) or a new bitmap.

Note: the implementation of this interface must manually clone the given bitmap reference if it wants to hold on to the bitmap. The original reference will be automatically closed after this call.

Parameters
frameNumber the frame number that has been rendered
bitmapReference the bitmap reference that has been rendered
frameType the frame type that has been rendered

public void setFrameCacheListener (BitmapFrameCache.FrameCacheListener frameCacheListener)

Set a frame cache listener that gets notified about caching events.

Parameters
frameCacheListener the listener to use