use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class BitmapMemoryCacheProducer method produceResults.
@Override
public void produceResults(final Consumer<CloseableReference<CloseableImage>> consumer, final ProducerContext producerContext) {
try {
if (FrescoSystrace.isTracing()) {
FrescoSystrace.beginSection("BitmapMemoryCacheProducer#produceResults");
}
final ProducerListener2 listener = producerContext.getProducerListener();
listener.onProducerStart(producerContext, getProducerName());
final ImageRequest imageRequest = producerContext.getImageRequest();
final Object callerContext = producerContext.getCallerContext();
final CacheKey cacheKey = mCacheKeyFactory.getBitmapCacheKey(imageRequest, callerContext);
final boolean isBitmapCacheEnabledForRead = producerContext.getImageRequest().isCacheEnabled(ImageRequest.CachesLocationsMasks.BITMAP_READ);
CloseableReference<CloseableImage> cachedReference = isBitmapCacheEnabledForRead ? mMemoryCache.get(cacheKey) : null;
if (cachedReference != null) {
maybeSetExtrasFromCloseableImage(cachedReference.get(), producerContext);
boolean isFinal = cachedReference.get().getQualityInfo().isOfFullQuality();
if (isFinal) {
listener.onProducerFinishWithSuccess(producerContext, getProducerName(), listener.requiresExtraMap(producerContext, getProducerName()) ? ImmutableMap.of(EXTRA_CACHED_VALUE_FOUND, "true") : null);
listener.onUltimateProducerReached(producerContext, getProducerName(), true);
producerContext.putOriginExtra("memory_bitmap", getOriginSubcategory());
consumer.onProgressUpdate(1f);
}
consumer.onNewResult(cachedReference, BaseConsumer.simpleStatusForIsLast(isFinal));
cachedReference.close();
if (isFinal) {
return;
}
}
if (producerContext.getLowestPermittedRequestLevel().getValue() >= ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE.getValue()) {
listener.onProducerFinishWithSuccess(producerContext, getProducerName(), listener.requiresExtraMap(producerContext, getProducerName()) ? ImmutableMap.of(EXTRA_CACHED_VALUE_FOUND, "false") : null);
listener.onUltimateProducerReached(producerContext, getProducerName(), false);
producerContext.putOriginExtra("memory_bitmap", getOriginSubcategory());
consumer.onNewResult(null, Consumer.IS_LAST);
return;
}
Consumer<CloseableReference<CloseableImage>> wrappedConsumer = wrapConsumer(consumer, cacheKey, producerContext.getImageRequest().isCacheEnabled(ImageRequest.CachesLocationsMasks.BITMAP_WRITE));
listener.onProducerFinishWithSuccess(producerContext, getProducerName(), listener.requiresExtraMap(producerContext, getProducerName()) ? ImmutableMap.of(EXTRA_CACHED_VALUE_FOUND, "false") : null);
if (FrescoSystrace.isTracing()) {
FrescoSystrace.beginSection("mInputProducer.produceResult");
}
mInputProducer.produceResults(wrappedConsumer, producerContext);
if (FrescoSystrace.isTracing()) {
FrescoSystrace.endSection();
}
} finally {
if (FrescoSystrace.isTracing()) {
FrescoSystrace.endSection();
}
}
}
use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class PipelineDraweeController method createDrawable.
@Override
protected Drawable createDrawable(CloseableReference<CloseableImage> image) {
try {
if (FrescoSystrace.isTracing()) {
FrescoSystrace.beginSection("PipelineDraweeController#createDrawable");
}
Preconditions.checkState(CloseableReference.isValid(image));
CloseableImage closeableImage = image.get();
maybeUpdateDebugOverlay(closeableImage);
Drawable drawable = maybeCreateDrawableFromFactories(mCustomDrawableFactories, closeableImage);
if (drawable != null) {
return drawable;
}
drawable = maybeCreateDrawableFromFactories(mGlobalDrawableFactories, closeableImage);
if (drawable != null) {
return drawable;
}
drawable = mDefaultDrawableFactory.createDrawable(closeableImage);
if (drawable != null) {
return drawable;
}
throw new UnsupportedOperationException("Unrecognized image class: " + closeableImage);
} finally {
if (FrescoSystrace.isTracing()) {
FrescoSystrace.endSection();
}
}
}
use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class ImagePipeline method isInBitmapMemoryCache.
/**
* Returns whether the image is stored in the bitmap memory cache.
*
* @param imageRequest the imageRequest for the image to be looked up.
* @return true if the image was found in the bitmap memory cache, false otherwise.
*/
public boolean isInBitmapMemoryCache(final ImageRequest imageRequest) {
if (imageRequest == null) {
return false;
}
final CacheKey cacheKey = mCacheKeyFactory.getBitmapCacheKey(imageRequest, null);
CloseableReference<CloseableImage> ref = mBitmapMemoryCache.get(cacheKey);
try {
return CloseableReference.isValid(ref);
} finally {
CloseableReference.closeSafely(ref);
}
}
use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class FrescoDrawable2ImplTest method setup.
@Before
public void setup() {
mFrescoDrawable = new FrescoDrawable2Impl(false, null, new BaseVitoImagePerfListener());
mLatch = new CountDownLatch(1);
mCloseableImage = new DummyCloseableImage();
mCloseableReference = CloseableReference.of(mCloseableImage, new ResourceReleaser<CloseableImage>() {
@Override
public void release(CloseableImage value) {
value.close();
mLatch.countDown();
}
});
}
use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class BitmapDrawableFactoryTest method testCreateDrawable_whenImageUnknown_thenReturnNull.
@Test
public void testCreateDrawable_whenImageUnknown_thenReturnNull() {
final CloseableImage closeableImage = mock(CloseableImage.class);
final ImageOptions options = mock(ImageOptions.class);
Drawable drawable = mDrawableFactory.createDrawable(closeableImage, options);
assertThat(drawable).isNull();
}
Aggregations