Search in sources :

Example 1 with MemoryCacheAdapter

use of com.bumptech.glide.load.engine.cache.MemoryCacheAdapter in project glide by bumptech.

the class LoadBitmapTest method transformFromRequestManager_withLoadedBitmap_doesNotRecycleBitmap.

@Test
public void transformFromRequestManager_withLoadedBitmap_doesNotRecycleBitmap() {
    Glide.init(context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()).setBitmapPool(new BitmapPoolAdapter()));
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
    concurrency.wait(GlideApp.with(context).load(bitmap).centerCrop().submit(100, 100));
    assertThat(bitmap.isRecycled()).isFalse();
}
Also used : Matchers.anyBitmap(com.bumptech.glide.test.Matchers.anyBitmap) Bitmap(android.graphics.Bitmap) MemoryCacheAdapter(com.bumptech.glide.load.engine.cache.MemoryCacheAdapter) BitmapPoolAdapter(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter) Test(org.junit.Test)

Example 2 with MemoryCacheAdapter

use of com.bumptech.glide.load.engine.cache.MemoryCacheAdapter in project glide by bumptech.

the class LoadBitmapTest method clearFromRequestBuilder_withLoadedBitmap_asBitmap_doesNotRecycleBitmap.

@Test
public void clearFromRequestBuilder_withLoadedBitmap_asBitmap_doesNotRecycleBitmap() {
    Glide.init(context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()).setBitmapPool(new BitmapPoolAdapter()));
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
    Target<Bitmap> target = concurrency.wait(GlideApp.with(context).asBitmap().load(bitmap).submit(100, 100));
    Glide.with(context).clear(target);
    // Allow Glide's resource recycler to run on the main thread.
    concurrency.pokeMainThread();
    assertThat(bitmap.isRecycled()).isFalse();
}
Also used : Matchers.anyBitmap(com.bumptech.glide.test.Matchers.anyBitmap) Bitmap(android.graphics.Bitmap) MemoryCacheAdapter(com.bumptech.glide.load.engine.cache.MemoryCacheAdapter) BitmapPoolAdapter(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter) Test(org.junit.Test)

Example 3 with MemoryCacheAdapter

use of com.bumptech.glide.load.engine.cache.MemoryCacheAdapter in project glide by bumptech.

the class LoadBitmapTest method transformFromRequestBuilder_asDrawable_withLoadedBitmap_doesNotRecycleBitmap.

@Test
public void transformFromRequestBuilder_asDrawable_withLoadedBitmap_doesNotRecycleBitmap() {
    Glide.init(context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()).setBitmapPool(new BitmapPoolAdapter()));
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
    concurrency.wait(GlideApp.with(context).asDrawable().load(bitmap).centerCrop().submit(100, 100));
    assertThat(bitmap.isRecycled()).isFalse();
}
Also used : Matchers.anyBitmap(com.bumptech.glide.test.Matchers.anyBitmap) Bitmap(android.graphics.Bitmap) MemoryCacheAdapter(com.bumptech.glide.load.engine.cache.MemoryCacheAdapter) BitmapPoolAdapter(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter) Test(org.junit.Test)

Example 4 with MemoryCacheAdapter

use of com.bumptech.glide.load.engine.cache.MemoryCacheAdapter in project glide by bumptech.

the class CachingTest method submit_withRequestClearedFromMemory_doesNotLoadFromMemory.

@Test
public void submit_withRequestClearedFromMemory_doesNotLoadFromMemory() {
    Glide.init(context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()));
    // Allow the request to be run and GCed without being cleared.
    concurrency.loadOnOtherThread(new Runnable() {

        @Override
        public void run() {
            FutureTarget<Drawable> first = GlideApp.with(context).load(raw.canonical).submit();
            concurrency.get(first);
        }
    });
    // Wait for the weak reference to be cleared and the request to be removed from active
    // resources.
    // De-flake by allowing multiple tries
    boolean isWeakRefCleared = false;
    for (int j = 0; j < 100; j++) {
        Runtime.getRuntime().gc();
        concurrency.pokeMainThread();
        try {
            // Loading again here won't shuffle our resource around because it only changes our
            // reference count from 1 to 2 and back. The reference we're waiting for will only be
            // decremented when the target is GCed.
            Target<Drawable> target = concurrency.wait(GlideApp.with(context).load(ResourceIds.raw.canonical).onlyRetrieveFromCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).submit());
            GlideApp.with(context).clear(target);
        } catch (RuntimeException e) {
            // The item has been cleared from active resources.
            isWeakRefCleared = true;
            break;
        }
    }
    if (!isWeakRefCleared) {
        fail("Failed to clear weak ref.");
    }
    concurrency.get(GlideApp.with(context).load(ResourceIds.raw.canonical).listener(requestListener).submit());
    verify(requestListener).onResourceReady(anyDrawable(), any(), anyDrawableTarget(), not(eq(DataSource.MEMORY_CACHE)), anyBoolean());
}
Also used : FutureTarget(com.bumptech.glide.request.FutureTarget) MemoryCacheAdapter(com.bumptech.glide.load.engine.cache.MemoryCacheAdapter) ThrowingRunnable(org.junit.function.ThrowingRunnable) Drawable(android.graphics.drawable.Drawable) Matchers.anyDrawable(com.bumptech.glide.test.Matchers.anyDrawable) Test(org.junit.Test)

Example 5 with MemoryCacheAdapter

use of com.bumptech.glide.load.engine.cache.MemoryCacheAdapter in project glide by bumptech.

the class LoadDrawableTest method transform_withLoadedBitmapDrawable_doesNotRecycleBitmap.

@Test
public void transform_withLoadedBitmapDrawable_doesNotRecycleBitmap() {
    Glide.init(context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()).setBitmapPool(new BitmapPoolAdapter()));
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical);
    BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
    concurrency.wait(GlideApp.with(context).load(drawable).centerCrop().submit(100, 100));
    assertThat(bitmap.isRecycled()).isFalse();
}
Also used : Bitmap(android.graphics.Bitmap) MemoryCacheAdapter(com.bumptech.glide.load.engine.cache.MemoryCacheAdapter) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapPoolAdapter(com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter) Test(org.junit.Test)

Aggregations

MemoryCacheAdapter (com.bumptech.glide.load.engine.cache.MemoryCacheAdapter)10 Test (org.junit.Test)10 Bitmap (android.graphics.Bitmap)9 BitmapPoolAdapter (com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter)8 Matchers.anyBitmap (com.bumptech.glide.test.Matchers.anyBitmap)6 Drawable (android.graphics.drawable.Drawable)4 Matchers.anyDrawable (com.bumptech.glide.test.Matchers.anyDrawable)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 LruBitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool)1 FutureTarget (com.bumptech.glide.request.FutureTarget)1 CreateBitmap (com.bumptech.glide.tests.Util.CreateBitmap)1 HashMap (java.util.HashMap)1 ThrowingRunnable (org.junit.function.ThrowingRunnable)1