Search in sources :

Example 56 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class MediaVariationsFallbackProducer method attemptCacheReadForVariant.

private Task attemptCacheReadForVariant(final Consumer<EncodedImage> consumer, final ProducerContext producerContext, ImageRequest imageRequest, MediaVariations mediaVariations, List<MediaVariations.Variant> sortedVariants, int index, AtomicBoolean isCancelled) {
    final MediaVariations.Variant variant = sortedVariants.get(index);
    final CacheKey cacheKey = mCacheKeyFactory.getEncodedCacheKey(imageRequest, variant.getUri(), producerContext.getCallerContext());
    final ImageRequest.CacheChoice cacheChoice;
    if (variant.getCacheChoice() == null) {
        cacheChoice = imageRequest.getCacheChoice();
    } else {
        cacheChoice = variant.getCacheChoice();
    }
    final BufferedDiskCache preferredCache = cacheChoice == ImageRequest.CacheChoice.SMALL ? mSmallImageBufferedDiskCache : mDefaultBufferedDiskCache;
    Task<EncodedImage> readTask = preferredCache.get(cacheKey, isCancelled);
    Continuation<EncodedImage, Void> continuation = onFinishDiskReads(consumer, producerContext, imageRequest, mediaVariations, sortedVariants, index, isCancelled);
    return readTask.continueWith(continuation);
}
Also used : BufferedDiskCache(com.facebook.imagepipeline.cache.BufferedDiskCache) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) MediaVariations(com.facebook.imagepipeline.request.MediaVariations)

Example 57 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class JobScheduler method updateJob.

/**
   * Updates the job.
   *
   * <p> This just updates the job, but it doesn't schedule it. In order to be executed, the job has
   * to be scheduled after being set. In case there was a previous job scheduled that has not yet
   * started, this new job will be executed instead.
   *
   * @return whether the job was successfully updated.
   */
public boolean updateJob(EncodedImage encodedImage, boolean isLast) {
    if (!shouldProcess(encodedImage, isLast)) {
        return false;
    }
    EncodedImage oldEncodedImage;
    synchronized (this) {
        oldEncodedImage = mEncodedImage;
        mEncodedImage = EncodedImage.cloneOrNull(encodedImage);
        mIsLast = isLast;
    }
    EncodedImage.closeSafely(oldEncodedImage);
    return true;
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 58 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class SplitCachesByImageSizeDiskCachePolicyTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    List<CacheKey> keys = new ArrayList<>(1);
    keys.add(new SimpleCacheKey("http://dummy.uri"));
    mCacheKey = new MultiCacheKey(keys);
    when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
    when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT);
    when(mImageRequest.isDiskCacheEnabled()).thenReturn(true);
    mIsCancelled = new AtomicBoolean(false);
    mEncodedImage = new EncodedImage(CloseableReference.of(mImagePooledByteBuffer));
    mSplitCachesByImageSizeDiskCachePolicy = new SplitCachesByImageSizeDiskCachePolicy(mDefaultBufferedDiskCache, mSmallImageBufferedDiskCache, mCacheKeyFactory, FORCE_SMALL_CACHE_THRESHOLD);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) ArrayList(java.util.ArrayList) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Before(org.junit.Before)

Example 59 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class DiskCacheWriteProducerTest method testInputProducerSuccess.

@Test
public void testInputProducerSuccess() {
    setupInputProducerSuccess();
    mDiskCacheWriteProducer.produceResults(mConsumer, mProducerContext);
    verify(mDiskCachePolicy, never()).writeToCache(mIntermediateEncodedImage, mImageRequest, mCallerContext);
    ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
    verify(mDiskCachePolicy).writeToCache(argumentCaptor.capture(), eq(mImageRequest), eq(mCallerContext));
    EncodedImage encodedImage = argumentCaptor.getValue();
    assertSame(encodedImage.getByteBufferRef().getUnderlyingReferenceTestOnly(), mFinalImageReference.getUnderlyingReferenceTestOnly());
    verify(mConsumer).onNewResult(mIntermediateEncodedImage, false);
    verify(mConsumer).onNewResult(mFinalEncodedImage, true);
    verifyZeroInteractions(mProducerListener);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 60 with EncodedImage

use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.

the class BranchOnSeparateImagesProducerTest method testFirstProducerResultNotGoodEnough.

@Test
public void testFirstProducerResultNotGoodEnough() {
    EncodedImage firstProducerEncodedImage = new EncodedImage(mFirstProducerFinalResult.getByteBufferRef());
    firstProducerEncodedImage.setRotationAngle(-1);
    firstProducerEncodedImage.setWidth(WIDTH / 2);
    firstProducerEncodedImage.setHeight(HEIGHT / 2);
    mFirstProducerConsumer.onNewResult(firstProducerEncodedImage, Consumer.IS_LAST);
    verify(mConsumer).onNewResult(firstProducerEncodedImage, Consumer.NO_FLAGS);
    EncodedImage intermediateEncodedImage = new EncodedImage(mIntermediateResult.getByteBufferRef());
    intermediateEncodedImage.setRotationAngle(-1);
    intermediateEncodedImage.setWidth(WIDTH / 2);
    intermediateEncodedImage.setHeight(HEIGHT / 2);
    mSecondProducerConsumer.onNewResult(intermediateEncodedImage, Consumer.NO_FLAGS);
    verify(mConsumer).onNewResult(intermediateEncodedImage, Consumer.NO_FLAGS);
    EncodedImage secondProducerEncodedImage = new EncodedImage(mSecondProducerFinalResult.getByteBufferRef());
    secondProducerEncodedImage.setRotationAngle(-1);
    secondProducerEncodedImage.setWidth(WIDTH / 2);
    secondProducerEncodedImage.setHeight(HEIGHT / 2);
    mSecondProducerConsumer.onNewResult(secondProducerEncodedImage, Consumer.IS_LAST);
    verify(mConsumer).onNewResult(secondProducerEncodedImage, Consumer.IS_LAST);
}
Also used : EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Test(org.junit.Test)

Aggregations

EncodedImage (com.facebook.imagepipeline.image.EncodedImage)108 Test (org.junit.Test)32 PooledByteBuffer (com.facebook.common.memory.PooledByteBuffer)20 AnimatedImageResult (com.facebook.imagepipeline.animated.base.AnimatedImageResult)12 CloseableAnimatedImage (com.facebook.imagepipeline.image.CloseableAnimatedImage)12 CacheKey (com.facebook.cache.common.CacheKey)11 Rect (android.graphics.Rect)9 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)9 InputStream (java.io.InputStream)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)9 AnimatedDrawableBackend (com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend)8 AnimatedImageCompositor (com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor)8 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)8 Before (org.junit.Before)8 Bitmap (android.graphics.Bitmap)7 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)7 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)7 FakeClock (com.facebook.imagepipeline.testing.FakeClock)6 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)6