blob: 616204d5733c17b49390d14599881a74c0b1b125 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package com.bumptech.glide.load.resource.bitmap;
import android.graphics.drawable.BitmapDrawable;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.drawable.DrawableResource;
import com.bumptech.glide.util.Util;
/**
* A {@link com.bumptech.glide.load.engine.Resource} that wraps an {@link android.graphics.drawable.BitmapDrawable}
* <p>
* This class ensures that every call to {@link #get()}} always returns a new
* {@link android.graphics.drawable.BitmapDrawable} to avoid rendering issues if used in multiple views and
* is also responsible for returning the underlying {@link android.graphics.Bitmap} to the given
* {@link com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool} when the resource is recycled.
* </p>
*/
public class BitmapDrawableResource extends DrawableResource<BitmapDrawable> {
private final BitmapPool bitmapPool;
public BitmapDrawableResource(BitmapDrawable drawable, BitmapPool bitmapPool) {
super(drawable);
this.bitmapPool = bitmapPool;
}
@Override
public int getSize() {
return Util.getBitmapByteSize(drawable.getBitmap());
}
@Override
public void recycle() {
bitmapPool.put(drawable.getBitmap());
}
}
|