Search in sources :

Example 36 with EncodedImage

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();
    }
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 37 with EncodedImage

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;
}
Also used : LocalFileFetchProducer(com.facebook.imagepipeline.producers.LocalFileFetchProducer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 38 with EncodedImage

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 39 with EncodedImage

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);
}
Also used : ImageRequest(com.facebook.imagepipeline.request.ImageRequest) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 40 with EncodedImage

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);
    }
}
Also used : PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Aggregations

EncodedImage (com.facebook.imagepipeline.image.EncodedImage)91 Test (org.junit.Test)24 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)19 CacheKey (com.facebook.cache.common.CacheKey)9 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)9 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)9 InputStream (java.io.InputStream)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Bitmap (android.graphics.Bitmap)7 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)7 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)6 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)6 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)6 FakeClock (com.facebook.imagepipeline.testing.FakeClock)6 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)6 Before (org.junit.Before)6 Rect (android.graphics.Rect)5 MultiCacheKey (com.facebook.cache.common.MultiCacheKey)5 ArrayList (java.util.ArrayList)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5