use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.
the class GlideBuilder method createGlide.
Glide createGlide(Context context) {
if (sourceExecutor == null) {
sourceExecutor = GlideExecutor.newSourceExecutor();
}
if (diskCacheExecutor == null) {
diskCacheExecutor = GlideExecutor.newDiskCacheExecutor();
}
if (memorySizeCalculator == null) {
memorySizeCalculator = new MemorySizeCalculator.Builder(context).build();
}
if (connectivityMonitorFactory == null) {
connectivityMonitorFactory = new DefaultConnectivityMonitorFactory();
}
if (bitmapPool == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
int size = memorySizeCalculator.getBitmapPoolSize();
bitmapPool = new LruBitmapPool(size);
} else {
bitmapPool = new BitmapPoolAdapter();
}
}
if (arrayPool == null) {
arrayPool = new LruArrayPool(memorySizeCalculator.getArrayPoolSizeInBytes());
}
if (memoryCache == null) {
memoryCache = new LruResourceCache(memorySizeCalculator.getMemoryCacheSize());
}
if (diskCacheFactory == null) {
diskCacheFactory = new InternalCacheDiskCacheFactory(context);
}
if (engine == null) {
engine = new Engine(memoryCache, diskCacheFactory, diskCacheExecutor, sourceExecutor, GlideExecutor.newUnlimitedSourceExecutor());
}
return new Glide(context, engine, memoryCache, bitmapPool, arrayPool, connectivityMonitorFactory, logLevel, defaultRequestOptions.lock());
}
use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project MVPFrames by RockyQu.
the class GlideConfiguration method applyOptions.
@Override
public void applyOptions(Context context, GlideBuilder builder) {
final AppComponent component = AppUtils.obtainAppComponentFromContext(context);
builder.setDiskCache(new DiskCache.Factory() {
@Override
public DiskCache build() {
// Careful: the external cache directory doesn't enforce permissions
return DiskLruCacheWrapper.get(FileUtils.makeDirs(new File(component.getCacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
}
});
MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);
builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
// 图片框架最终会走到 GlideImageLoader 的 load 方法中进行处理
// 如果你想自己自定义图片框架或自己实现 Glide BaseImageLoader 你需要实现 GlideAppliesOptions 接口
BaseImageLoader baseImageLoader = component.getImageLoader().getImageLoader();
if (baseImageLoader instanceof GlideAppliesOptions) {
((GlideAppliesOptions) baseImageLoader).applyGlideOptions(context, builder);
}
}
use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.
the class LoadBitmapTest method loadFromRequestManager_withBitmap_doesNotLoadFromDiskCache.
@Test
public void loadFromRequestManager_withBitmap_doesNotLoadFromDiskCache() {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
Glide.init(context, new GlideBuilder().setMemoryCache(new LruResourceCache(Util.getBitmapByteSize(bitmap) * 10)).setBitmapPool(new LruBitmapPool(Util.getBitmapByteSize(bitmap) * 10)));
Target<Drawable> target = concurrency.wait(GlideApp.with(context).load(bitmap).centerCrop().submit(100, 100));
Glide.with(context).clear(target);
assertThat(bitmap.isRecycled()).isFalse();
concurrency.runOnMainThread(new Runnable() {
@Override
public void run() {
Glide.get(context).clearMemory();
}
});
concurrency.wait(GlideApp.with(context).load(bitmap).centerCrop().listener(drawableListener).submit(100, 100));
verify(drawableListener).onResourceReady(anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.LOCAL), anyBoolean());
}
use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.
the class LoadBitmapTest method loadFromRequestBuilder_asDrawable_withBitmap_doesNotLoadFromDiskCache.
@Test
public void loadFromRequestBuilder_asDrawable_withBitmap_doesNotLoadFromDiskCache() {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
Glide.init(context, new GlideBuilder().setMemoryCache(new LruResourceCache(Util.getBitmapByteSize(bitmap) * 10)).setBitmapPool(new LruBitmapPool(Util.getBitmapByteSize(bitmap) * 10)));
Target<Drawable> target = concurrency.wait(GlideApp.with(context).asDrawable().load(bitmap).centerCrop().submit(100, 100));
Glide.with(context).clear(target);
assertThat(bitmap.isRecycled()).isFalse();
concurrency.runOnMainThread(new Runnable() {
@Override
public void run() {
Glide.get(context).clearMemory();
}
});
concurrency.wait(GlideApp.with(context).load(bitmap).centerCrop().listener(drawableListener).submit(100, 100));
verify(drawableListener).onResourceReady(anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.LOCAL), anyBoolean());
}
use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.
the class WideGamutTest method loadWideGamutImage_withArgb888OfSufficientSizeInPool_usesArgb8888Bitmap.
@Test
public void loadWideGamutImage_withArgb888OfSufficientSizeInPool_usesArgb8888Bitmap() {
Bitmap wideGamut = Bitmap.createBitmap(100, 50, Bitmap.Config.RGBA_F16);
byte[] data = asPng(wideGamut);
Bitmap argb8888 = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Glide.init(context, new GlideBuilder().setBitmapPool(new LruBitmapPool(wideGamut.getAllocationByteCount() * 5)));
Glide.get(context).getBitmapPool().put(argb8888);
Bitmap result = concurrency.get(Glide.with(context).asBitmap().load(data).submit());
assertThat(result).isSameAs(argb8888);
}
Aggregations