Search in sources :

Example 11 with LruBitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.

the class LoadBitmapTest method loadFromRequestBuilder_asDrawable_withBitmapAndStrategyBeforeLoad_notFromCache.

@Test
public void loadFromRequestBuilder_asDrawable_withBitmapAndStrategyBeforeLoad_notFromCache() {
    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().diskCacheStrategy(DiskCacheStrategy.ALL).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 12 with LruBitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.

the class LoadDrawableTest method loadFromRequestManager_withBitmap_doesNotLoadFromDiskCache.

@Test
public void loadFromRequestManager_withBitmap_doesNotLoadFromDiskCache() {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
    BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
    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(drawable).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(drawable).centerCrop().listener(listener).submit(100, 100));
    verify(listener).onResourceReady(anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.LOCAL), anyBoolean());
}
Also used : 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) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Example 13 with LruBitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.

the class LoadDrawableTest method loadFromRequestBuilder_asDrawable_withBitmapAndStrategyBeforeLoad_notFromCache.

@Test
public void loadFromRequestBuilder_asDrawable_withBitmapAndStrategyBeforeLoad_notFromCache() {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
    BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
    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().diskCacheStrategy(DiskCacheStrategy.ALL).load(drawable).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(drawable).centerCrop().listener(listener).submit(100, 100));
    verify(listener).onResourceReady(anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.LOCAL), anyBoolean());
}
Also used : 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) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Example 14 with LruBitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.

the class LoadDrawableTest method loadFromRequestBuilder_asDrawable_withBitmap_doesNotLoadFromDiskCache.

@Test
public void loadFromRequestBuilder_asDrawable_withBitmap_doesNotLoadFromDiskCache() {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
    BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
    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(drawable).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(drawable).centerCrop().listener(listener).submit(100, 100));
    verify(listener).onResourceReady(anyDrawable(), any(), anyDrawableTarget(), eq(DataSource.LOCAL), anyBoolean());
}
Also used : 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) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Example 15 with LruBitmapPool

use of com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool in project glide by bumptech.

the class WideGamutTest method load_withWideGamutImage_bitmapInPoolWithSizeAndConfig_usesBitmapFromPool.

@Test
public void load_withWideGamutImage_bitmapInPoolWithSizeAndConfig_usesBitmapFromPool() {
    int bitmapDimension = 1000;
    Glide.init(context, new GlideBuilder().setBitmapPool(new LruBitmapPool(bitmapDimension * bitmapDimension * 8 * 4)));
    Bitmap expected = Bitmap.createBitmap(bitmapDimension, bitmapDimension, Bitmap.Config.RGBA_F16);
    Glide.get(context).getBitmapPool().put(expected);
    Bitmap bitmap = concurrency.get(Glide.with(context).asBitmap().load(ResourceIds.raw.webkit_logo_p3).submit());
    assertThat(bitmap).isSameAs(expected);
}
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