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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations