Search in sources :

Example 1 with LruBitmapPool

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());
}
Also used : LruArrayPool(com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool) DefaultConnectivityMonitorFactory(com.bumptech.glide.manager.DefaultConnectivityMonitorFactory) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) BitmapPoolAdapter(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter) InternalCacheDiskCacheFactory(com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory) Engine(com.bumptech.glide.load.engine.Engine)

Example 2 with LruBitmapPool

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);
    }
}
Also used : BaseImageLoader(com.tool.common.widget.imageloader.BaseImageLoader) AppComponent(com.tool.common.di.component.AppComponent) MemorySizeCalculator(com.bumptech.glide.load.engine.cache.MemorySizeCalculator) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) DiskCache(com.bumptech.glide.load.engine.cache.DiskCache) File(java.io.File)

Example 3 with LruBitmapPool

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());
}
Also used : Matchers.anyBitmap(com.bumptech.glide.test.Matchers.anyBitmap) Bitmap(android.graphics.Bitmap) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) Drawable(android.graphics.drawable.Drawable) Matchers.anyDrawable(com.bumptech.glide.test.Matchers.anyDrawable) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) Test(org.junit.Test)

Example 4 with LruBitmapPool

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());
}
Also used : Matchers.anyBitmap(com.bumptech.glide.test.Matchers.anyBitmap) Bitmap(android.graphics.Bitmap) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) Drawable(android.graphics.drawable.Drawable) Matchers.anyDrawable(com.bumptech.glide.test.Matchers.anyDrawable) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) Test(org.junit.Test)

Example 5 with LruBitmapPool

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);
}
Also used : Bitmap(android.graphics.Bitmap) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) Test(org.junit.Test)

Aggregations

LruBitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool)17 LruResourceCache (com.bumptech.glide.load.engine.cache.LruResourceCache)14 Bitmap (android.graphics.Bitmap)11 Test (org.junit.Test)11 Drawable (android.graphics.drawable.Drawable)6 Matchers.anyDrawable (com.bumptech.glide.test.Matchers.anyDrawable)6 MemorySizeCalculator (com.bumptech.glide.load.engine.cache.MemorySizeCalculator)5 Matchers.anyBitmap (com.bumptech.glide.test.Matchers.anyBitmap)5 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 File (java.io.File)3 DiskCache (com.bumptech.glide.load.engine.cache.DiskCache)2 InternalCacheDiskCacheFactory (com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory)2 GlideBuilder (com.bumptech.glide.GlideBuilder)1 Engine (com.bumptech.glide.load.engine.Engine)1 BitmapPoolAdapter (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter)1 LruArrayPool (com.bumptech.glide.load.engine.bitmap_recycle.LruArrayPool)1 ExternalPreferredCacheDiskCacheFactory (com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory)1 MemoryCacheAdapter (com.bumptech.glide.load.engine.cache.MemoryCacheAdapter)1 DefaultConnectivityMonitorFactory (com.bumptech.glide.manager.DefaultConnectivityMonitorFactory)1 RequestOptions (com.bumptech.glide.request.RequestOptions)1