BitmapResource.java revision 5f4610b54d517be58105bcf73ce3291ba79f9f40
1package com.bumptech.glide.load.resource.bitmap;
2
3import android.graphics.Bitmap;
4import com.bumptech.glide.load.engine.Resource;
5import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
6import com.bumptech.glide.util.Util;
7
8/**
9 * A resource wrapping a {@link android.graphics.Bitmap} object.
10 */
11public class BitmapResource extends Resource<Bitmap> {
12    private Bitmap bitmap;
13    private BitmapPool bitmapPool;
14
15    public BitmapResource(Bitmap bitmap, BitmapPool bitmapPool) {
16        this.bitmap = bitmap;
17        this.bitmapPool = bitmapPool;
18    }
19
20    @Override
21    public Bitmap get() {
22        return bitmap;
23    }
24
25    @Override
26    public int getSize() {
27        return Util.getSize(bitmap);
28    }
29
30    @Override
31    public void recycleInternal() {
32        if (!bitmapPool.put(bitmap)) {
33            bitmap.recycle();
34        }
35    }
36}
37