use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class BaseFrescoStethoPlugin method storeEntries.
private void storeEntries(List<CountingMemoryCacheInspector.DumpInfoEntry<CacheKey, CloseableImage>> entries, int i, PrintStream writer, File directory) throws IOException {
String filename;
for (CountingMemoryCacheInspector.DumpInfoEntry<CacheKey, CloseableImage> entry : entries) {
CloseableImage closeableImage = entry.value.get();
if (closeableImage instanceof CloseableBitmap) {
CloseableBitmap closeableBitmap = (CloseableBitmap) closeableImage;
filename = "tmp" + i + ".png";
writer.println(formatStrLocaleSafe("Storing image %d as %s. Key: %s", i, filename, entry.key));
storeImage(closeableBitmap.getUnderlyingBitmap(), new File(directory, filename), Bitmap.CompressFormat.PNG, 100);
} else {
writer.println(formatStrLocaleSafe("Image %d has unrecognized type %s. Key: %s", i, closeableImage, entry.key));
}
i++;
}
}
use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class PipelineDraweeController method createDrawable.
@Override
protected Drawable createDrawable(CloseableReference<CloseableImage> image) {
Preconditions.checkState(CloseableReference.isValid(image));
CloseableImage closeableImage = image.get();
maybeUpdateDebugOverlay(closeableImage);
if (mDrawableFactories != null) {
for (DrawableFactory factory : mDrawableFactories) {
if (factory.supportsImageType(closeableImage)) {
Drawable drawable = factory.createDrawable(closeableImage);
if (drawable != null) {
return drawable;
}
}
}
}
Drawable defaultDrawable = mDefaultDrawableFactory.createDrawable(closeableImage);
if (defaultDrawable != null) {
return defaultDrawable;
}
throw new UnsupportedOperationException("Unrecognized image class: " + closeableImage);
}
use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class AnimatedFrameCacheTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MemoryCacheParams params = new MemoryCacheParams(4 * ByteConstants.MB, 256, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
when(mMemoryCacheParamsSupplier.get()).thenReturn(params);
CountingMemoryCache<CacheKey, CloseableImage> countingMemoryCache = BitmapCountingMemoryCacheFactory.get(mMemoryCacheParamsSupplier, mMemoryTrimmableRegistry, mPlatformBitmapFactory, true);
mCacheKey = new SimpleCacheKey("key");
mAnimatedFrameCache = new AnimatedFrameCache(mCacheKey, countingMemoryCache);
mFrame1 = CloseableReference.of(mock(CloseableImage.class));
mFrame2 = CloseableReference.of(mock(CloseableImage.class));
}
use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class AnimatedSingleUsePostprocessorProducerTest method testNonStaticBitmapIsPassedOn.
@Test
public void testNonStaticBitmapIsPassedOn() {
SingleUsePostprocessorConsumer postprocessorConsumer = produceResults();
CloseableAnimatedImage sourceCloseableAnimatedImage = mock(CloseableAnimatedImage.class);
CloseableReference<CloseableImage> sourceCloseableImageRef = CloseableReference.<CloseableImage>of(sourceCloseableAnimatedImage);
postprocessorConsumer.onNewResult(sourceCloseableImageRef, true);
sourceCloseableImageRef.close();
mTestExecutorService.runUntilIdle();
mInOrder.verify(mConsumer).onNewResult(any(CloseableReference.class), eq(true));
mInOrder.verifyNoMoreInteractions();
assertEquals(1, mResults.size());
CloseableReference<CloseableImage> res0 = mResults.get(0);
assertTrue(CloseableReference.isValid(res0));
assertSame(sourceCloseableAnimatedImage, res0.get());
res0.close();
verify(sourceCloseableAnimatedImage).close();
}
use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class FrescoFrameCache method onFrameRendered.
@Override
public synchronized void onFrameRendered(int frameNumber, CloseableReference<Bitmap> bitmapReference, @BitmapAnimationBackend.FrameType int frameType) {
Preconditions.checkNotNull(bitmapReference);
CloseableReference<CloseableImage> closableReference = null;
try {
// The given CloseableStaticBitmap will be cached and then released by the resource releaser
// of the closeable reference
CloseableImage closeableImage = new CloseableStaticBitmap(bitmapReference, ImmutableQualityInfo.FULL_QUALITY, 0);
closableReference = CloseableReference.of(closeableImage);
CloseableReference.closeSafely(mLastCachedItem);
mLastCachedItem = mAnimatedFrameCache.cache(frameNumber, closableReference);
} finally {
CloseableReference.closeSafely(closableReference);
}
}
Aggregations