Search in sources :

Example 1 with RepeatedPostprocessor

use of com.facebook.imagepipeline.request.RepeatedPostprocessor in project fresco by facebook.

the class PostprocessorProducer method produceResults.

@Override
public void produceResults(final Consumer<CloseableReference<CloseableImage>> consumer, ProducerContext context) {
    final ProducerListener listener = context.getListener();
    final Postprocessor postprocessor = context.getImageRequest().getPostprocessor();
    final PostprocessorConsumer basePostprocessorConsumer = new PostprocessorConsumer(consumer, listener, context.getId(), postprocessor, context);
    final Consumer<CloseableReference<CloseableImage>> postprocessorConsumer;
    if (postprocessor instanceof RepeatedPostprocessor) {
        postprocessorConsumer = new RepeatedPostprocessorConsumer(basePostprocessorConsumer, (RepeatedPostprocessor) postprocessor, context);
    } else {
        postprocessorConsumer = new SingleUsePostprocessorConsumer(basePostprocessorConsumer);
    }
    mInputProducer.produceResults(postprocessorConsumer, context);
}
Also used : CloseableReference(com.facebook.common.references.CloseableReference) Postprocessor(com.facebook.imagepipeline.request.Postprocessor) RepeatedPostprocessor(com.facebook.imagepipeline.request.RepeatedPostprocessor) RepeatedPostprocessor(com.facebook.imagepipeline.request.RepeatedPostprocessor)

Example 2 with RepeatedPostprocessor

use of com.facebook.imagepipeline.request.RepeatedPostprocessor in project fresco by facebook.

the class PostprocessedBitmapMemoryCacheProducer method produceResults.

@Override
public void produceResults(final Consumer<CloseableReference<CloseableImage>> consumer, final ProducerContext producerContext) {
    final ProducerListener listener = producerContext.getListener();
    final String requestId = producerContext.getId();
    final ImageRequest imageRequest = producerContext.getImageRequest();
    final Object callerContext = producerContext.getCallerContext();
    // If there's no postprocessor or the postprocessor doesn't require caching, forward results.
    final Postprocessor postprocessor = imageRequest.getPostprocessor();
    if (postprocessor == null || postprocessor.getPostprocessorCacheKey() == null) {
        mInputProducer.produceResults(consumer, producerContext);
        return;
    }
    listener.onProducerStart(requestId, getProducerName());
    final CacheKey cacheKey = mCacheKeyFactory.getPostprocessedBitmapCacheKey(imageRequest, callerContext);
    CloseableReference<CloseableImage> cachedReference = mMemoryCache.get(cacheKey);
    if (cachedReference != null) {
        listener.onProducerFinishWithSuccess(requestId, getProducerName(), listener.requiresExtraMap(requestId) ? ImmutableMap.of(VALUE_FOUND, "true") : null);
        consumer.onProgressUpdate(1.0f);
        consumer.onNewResult(cachedReference, true);
        cachedReference.close();
    } else {
        final boolean isRepeatedProcessor = postprocessor instanceof RepeatedPostprocessor;
        Consumer<CloseableReference<CloseableImage>> cachedConsumer = new CachedPostprocessorConsumer(consumer, cacheKey, isRepeatedProcessor, mMemoryCache);
        listener.onProducerFinishWithSuccess(requestId, getProducerName(), listener.requiresExtraMap(requestId) ? ImmutableMap.of(VALUE_FOUND, "false") : null);
        mInputProducer.produceResults(cachedConsumer, producerContext);
    }
}
Also used : CloseableReference(com.facebook.common.references.CloseableReference) Postprocessor(com.facebook.imagepipeline.request.Postprocessor) RepeatedPostprocessor(com.facebook.imagepipeline.request.RepeatedPostprocessor) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) RepeatedPostprocessor(com.facebook.imagepipeline.request.RepeatedPostprocessor) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CacheKey(com.facebook.cache.common.CacheKey)

Aggregations

CloseableReference (com.facebook.common.references.CloseableReference)2 Postprocessor (com.facebook.imagepipeline.request.Postprocessor)2 RepeatedPostprocessor (com.facebook.imagepipeline.request.RepeatedPostprocessor)2 CacheKey (com.facebook.cache.common.CacheKey)1 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)1 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)1