|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool
public class LruBitmapPool
An BitmapPool implementation that uses an
LruPoolStrategy to bucket Bitmaps and then uses an LRU
eviction policy to evict Bitmaps from the least recently used bucket in order to keep
the pool below a given maximum size limit.
| Constructor Summary | |
|---|---|
LruBitmapPool(int maxSize)
Constructor for LruBitmapPool. |
|
LruBitmapPool(int maxSize,
Set<Bitmap.Config> allowedConfigs)
Constructor for LruBitmapPool. |
|
| Method Summary | |
|---|---|
void |
clearMemory()
Removes all Bitmaps from the pool. |
Bitmap |
get(int width,
int height,
Bitmap.Config config)
Returns a Bitmap of exactly the given width, height, and configuration, and containing
only transparent pixels or null if no such Bitmap could be obtained from the pool. |
Bitmap |
getDirty(int width,
int height,
Bitmap.Config config)
Identical to BitmapPool.get(int, int, android.graphics.Bitmap.Config) except that any returned non-null
Bitmap may not have been erased and may contain random data. |
int |
getMaxSize()
Returns the current maximum size of the pool in bytes. |
boolean |
put(Bitmap bitmap)
Adds the given Bitmap and returns true if the Bitmap
was eligible to be added and false otherwise. |
void |
setSizeMultiplier(float sizeMultiplier)
Multiplies the initial size of the pool by the given multipler to dynamically and synchronously allow users to adjust the size of the pool. |
void |
trimMemory(int level)
Reduces the size of the cache by evicting items based on the given level. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LruBitmapPool(int maxSize)
maxSize - The initial maximum size of the pool in bytes.
public LruBitmapPool(int maxSize,
Set<Bitmap.Config> allowedConfigs)
maxSize - The initial maximum size of the pool in bytes.allowedConfigs - A white listed set of Bitmap.Config that are allowed to be put
into the pool. Configs not in the allowed set will be rejected.| Method Detail |
|---|
public int getMaxSize()
BitmapPool
getMaxSize in interface BitmapPoolpublic void setSizeMultiplier(float sizeMultiplier)
BitmapPool
If the current total size of the pool is larger than the max size after the given multiplier is applied,
Bitmaps should be evicted until the pool is smaller than the new max size.
setSizeMultiplier in interface BitmapPoolsizeMultiplier - The size multiplier to apply between 0 and 1.public boolean put(Bitmap bitmap)
BitmapPoolBitmap and returns true if the Bitmap
was eligible to be added and false otherwise.
Note - If the Bitmap is rejected (this method returns false) then it is the caller's
responsibility to call Bitmap.recycle().
Note - This method will return true if the given Bitmap is synchronously
evicted after being accepted. The only time this method will return false is if the
Bitmap is not eligible to be added to the pool (either it is not mutable or it is
larger than the max pool size).
put in interface BitmapPoolbitmap - The Bitmap to attempt to add.Bitmap.isMutable(),
Bitmap.recycle()
public Bitmap get(int width,
int height,
Bitmap.Config config)
BitmapPoolBitmap of exactly the given width, height, and configuration, and containing
only transparent pixels or null if no such Bitmap could be obtained from the pool.
Because this method erases all pixels in the Bitmap, this method is slightly slower than
BitmapPool.getDirty(int, int, android.graphics.Bitmap.Config). If the Bitmap is being
obtained to be used in BitmapFactory or in any other case where every pixel in the
Bitmap will always be overwritten or cleared,
BitmapPool.getDirty(int, int, android.graphics.Bitmap.Config) will be faster. When in doubt, use this method
to ensure correctness.
Implementations can should clear out every returned Bitmap using the following:
bitmap.eraseColor(Color.TRANSPARENT);
get in interface BitmapPoolwidth - The width in pixels of the desired Bitmap.height - The height in pixels of the desired Bitmap.config - The Bitmap.Config of the desired Bitmap.BitmapPool.getDirty(int, int, android.graphics.Bitmap.Config)
public Bitmap getDirty(int width,
int height,
Bitmap.Config config)
BitmapPoolBitmapPool.get(int, int, android.graphics.Bitmap.Config) except that any returned non-null
Bitmap may not have been erased and may contain random data.
Although this method is slightly more efficient than BitmapPool.get(int, int, android.graphics.Bitmap.Config)
it should be used with caution and only when the caller is sure that they are going to erase the
Bitmap entirely before writing new data to it.
getDirty in interface BitmapPoolwidth - The width in pixels of the desired Bitmap.height - The height in pixels of the desired Bitmap.config - The Bitmap.Config of the desired Bitmap.
Bitmap with exactly the given width, height, and config potentially containing
random image data or null if no such Bitmap could be obtained from the pool.BitmapPool.get(int, int, android.graphics.Bitmap.Config)public void clearMemory()
BitmapPoolBitmaps from the pool.
clearMemory in interface BitmapPoolpublic void trimMemory(int level)
BitmapPool
trimMemory in interface BitmapPoollevel - The level from ComponentCallbacks2 to use to determine how many
Bitmaps to evict.ComponentCallbacks2
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||