@Override protected void releasePauseCover() { try { if (mCurrentState != CURRENT_STATE_PAUSE && mFullPauseBitmap != null && !mFullPauseBitmap.isRecycled() && mShowPauseCover) { mFullPauseBitmap.recycle(); mFullPauseBitmap = null; } } catch (Exception e) { e.printStackTrace(); } }
protected void updatePauseCover() { if ((mFullPauseBitmap == null || mFullPauseBitmap.isRecycled()) && mShowPauseCover) { try { initCover(); } catch (Exception e) { e.printStackTrace(); mFullPauseBitmap = null; } } }
@Override public void drawLayer(@NonNull Canvas canvas, Matrix parentMatrix, int parentAlpha) { Bitmap bitmap = getBitmap(); if (bitmap == null || bitmap.isRecycled()) { return; } float density = Utils.dpScale(); paint.setAlpha(parentAlpha); if (colorFilterAnimation != null) { paint.setColorFilter(colorFilterAnimation.getValue()); } canvas.save(); canvas.concat(parentMatrix); src.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); dst.set(0, 0, (int) (bitmap.getWidth() * density), (int) (bitmap.getHeight() * density)); canvas.drawBitmap(bitmap, src, dst , paint); canvas.restore(); }
@Override void complete(RequestHandler.Result result) { if (result == null) { throw new AssertionError( String.format("Attempted to complete action with no result!\n%s", this)); } Bitmap bitmap = result.getBitmap(); if (bitmap != null) { target.onBitmapLoaded(bitmap, result.getLoadedFrom()); if (bitmap.isRecycled()) { throw new IllegalStateException("Target callback must not recycle bitmap!"); } } }
@Override public void releaseAll() { super.releaseAll(); Bitmap bitmap = mBitmapEffect.getBitmap(); if (bitmap != null && !bitmap.isRecycled()) { bitmap.recycle(); } }
@Test public void shouldRecycleBitmap() throws Exception { Bitmap bitmap = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888); bitmap.recycle(); assertThat(bitmap.isRecycled()).isTrue(); }
public void isNotRecycled() { if (actual().isRecycled()) { fail("is not recycled"); } }
@Test public void recycle_doesNotRecycleWrappedBitmap() { resource.recycle(); assertThat(bitmap.isRecycled()).isFalse(); }
@Test public void transform_withBitmapDrawable_andUnitBitmapTransformation_doesNotRecycle() { when( bitmapTransformation .transform( any(Context.class), anyBitmapResource(), anyInt(), anyInt())) .thenAnswer(new ReturnGivenResource()); Bitmap bitmap = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888); BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap); @SuppressWarnings("unchecked") Resource<Drawable> input = (Resource<Drawable>) (Resource<?>) new BitmapDrawableResource(drawable, bitmapPool); transformation.transform(context, input, /*outWidth=*/ 100, /*outHeight=*/ 200); assertThat(bitmap.isRecycled()).isFalse(); }
@Test public void testEvictedBitmapsAreRecycled() { fillPool(pool, MAX_SIZE); List<Bitmap> bitmaps = new ArrayList<>(MAX_SIZE); bitmaps.addAll(strategy.bitmaps); pool.clearMemory(); for (Bitmap b : bitmaps) { assertTrue(b.isRecycled()); } }
@Test public void shouldCreateActiveBitmap() throws Exception { Bitmap bitmap = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888); assertThat(bitmap.isRecycled()).isFalse(); assertThat(bitmap.getPixel(0, 0)).isEqualTo(0); assertThat(bitmap.getWidth()).isEqualTo(100); assertThat(bitmap.getHeight()).isEqualTo(200); assertThat(bitmap.getConfig()).isEqualTo(Bitmap.Config.ARGB_8888); }
@Test public void reusedBitmapIsNotRecycled() { Request data = new Request.Builder(URI_1).build(); Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888); Bitmap result = transformResult(data, source, 0); assertThat(result).isSameAs(source); assertThat(result.isRecycled()).isFalse(); }
@Test public void transform_withLoadedBitmapDrawable_doesNotRecycleBitmap() { Glide.init( context, 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(); }
@Test public void clear_withLoadedBitmapDrawable_doesNotRecycleBitmap() { Glide.init( context, glideBuilder .setMemoryCache(new MemoryCacheAdapter()) .setBitmapPool(new BitmapPoolAdapter())); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .load(drawable) .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(); }
@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(); }
@Test public void clearFromRequestManager_withLoadedBitmap_doesNotRecycleBitmap() { Glide.init( context, new GlideBuilder() .setMemoryCache(new MemoryCacheAdapter()) .setBitmapPool(new BitmapPoolAdapter())); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .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(); }
@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(); }
@Test public void clearFromRequestBuilder_asDrawable_withLoadedBitmap_doesNotRecycleBitmap() { Glide.init( context, new GlideBuilder() .setMemoryCache(new MemoryCacheAdapter()) .setBitmapPool(new BitmapPoolAdapter())); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResourceIds.raw.canonical); Target<Drawable> target = concurrency.wait( GlideApp.with(context) .asDrawable() .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(); }
@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(); }
@Test public void transformFromRequestBuilder_withLoadedBitmap_asBitmap_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) .asBitmap() .load(bitmap) .centerCrop() .submit(100, 100)); assertThat(bitmap.isRecycled()).isFalse(); }