use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class StagingArea method remove.
/**
* Removes item from the StagingArea.
* @param key
* @return true if item was removed
*/
public boolean remove(final CacheKey key) {
Preconditions.checkNotNull(key);
final EncodedImage encodedImage;
synchronized (this) {
encodedImage = mMap.remove(key);
}
if (encodedImage == null) {
return false;
}
try {
return encodedImage.isValid();
} finally {
encodedImage.close();
}
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class ProducerSequenceFactory method getBackgroundLocalFileFetchToEncodeMemorySequence.
/**
* background-thread hand-off -> multiplex -> encoded cache ->
* disk cache -> (webp transcode) -> local file fetch
*/
private synchronized Producer<EncodedImage> getBackgroundLocalFileFetchToEncodeMemorySequence() {
if (mBackgroundLocalFileFetchToEncodedMemorySequence == null) {
final LocalFileFetchProducer localFileFetchProducer = mProducerFactory.newLocalFileFetchProducer();
final Producer<EncodedImage> toEncodedMultiplexProducer = newEncodedCacheMultiplexToTranscodeSequence(localFileFetchProducer);
mBackgroundLocalFileFetchToEncodedMemorySequence = mProducerFactory.newBackgroundThreadHandoffProducer(toEncodedMultiplexProducer, mThreadHandoffProducerQueue);
}
return mBackgroundLocalFileFetchToEncodedMemorySequence;
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class DiskCacheReadProducer method produceResults.
public void produceResults(final Consumer<EncodedImage> consumer, final ProducerContext producerContext) {
final ImageRequest imageRequest = producerContext.getImageRequest();
if (!imageRequest.isDiskCacheEnabled()) {
maybeStartInputProducer(consumer, producerContext);
return;
}
producerContext.getListener().onProducerStart(producerContext.getId(), PRODUCER_NAME);
final AtomicBoolean isCancelled = new AtomicBoolean(false);
Task<EncodedImage> diskLookupTask = mDiskCachePolicy.createAndStartCacheReadTask(imageRequest, producerContext.getCallerContext(), isCancelled);
Continuation<EncodedImage, Void> continuation = onFinishDiskReads(consumer, producerContext);
diskLookupTask.continueWith(continuation);
subscribeTaskForRequestCancellation(isCancelled, producerContext);
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class LocalFetchProducer method produceResults.
@Override
public void produceResults(final Consumer<EncodedImage> consumer, final ProducerContext producerContext) {
final ProducerListener listener = producerContext.getListener();
final String requestId = producerContext.getId();
final ImageRequest imageRequest = producerContext.getImageRequest();
final StatefulProducerRunnable cancellableProducerRunnable = new StatefulProducerRunnable<EncodedImage>(consumer, listener, getProducerName(), requestId) {
@Override
protected EncodedImage getResult() throws Exception {
EncodedImage encodedImage = getEncodedImage(imageRequest);
if (encodedImage == null) {
return null;
}
encodedImage.parseMetaData();
return encodedImage;
}
@Override
protected void disposeResult(EncodedImage result) {
EncodedImage.closeSafely(result);
}
};
producerContext.addCallbacks(new BaseProducerContextCallbacks() {
@Override
public void onCancellationRequested() {
cancellableProducerRunnable.cancel();
}
});
mExecutor.execute(cancellableProducerRunnable);
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class NetworkFetchProducer method notifyConsumer.
private void notifyConsumer(PooledByteBufferOutputStream pooledOutputStream, boolean isFinal, Consumer<EncodedImage> consumer) {
CloseableReference<PooledByteBuffer> result = CloseableReference.of(pooledOutputStream.toByteBuffer());
EncodedImage encodedImage = null;
try {
encodedImage = new EncodedImage(result);
encodedImage.parseMetaData();
consumer.onNewResult(encodedImage, isFinal);
} finally {
EncodedImage.closeSafely(encodedImage);
CloseableReference.closeSafely(result);
}
}
Aggregations