use of com.facebook.common.references.CloseableReference in project fresco by facebook.
the class AnimatedImageFactoryImpl method decodeAllFrames.
private List<CloseableReference<Bitmap>> decodeAllFrames(AnimatedImage image, Bitmap.Config bitmapConfig) {
AnimatedImageResult tempResult = AnimatedImageResult.forAnimatedImage(image);
AnimatedDrawableBackend drawableBackend = mAnimatedDrawableBackendProvider.get(tempResult, null);
final List<CloseableReference<Bitmap>> bitmaps = new ArrayList<>(drawableBackend.getFrameCount());
AnimatedImageCompositor animatedImageCompositor = new AnimatedImageCompositor(drawableBackend, new AnimatedImageCompositor.Callback() {
@Override
public void onIntermediateResult(int frameNumber, Bitmap bitmap) {
// Don't care.
}
@Override
@Nullable
public CloseableReference<Bitmap> getCachedBitmap(int frameNumber) {
return CloseableReference.cloneOrNull(bitmaps.get(frameNumber));
}
});
for (int i = 0; i < drawableBackend.getFrameCount(); i++) {
CloseableReference<Bitmap> bitmap = createBitmap(drawableBackend.getWidth(), drawableBackend.getHeight(), bitmapConfig);
animatedImageCompositor.renderFrame(i, bitmap.get());
bitmaps.add(bitmap);
}
return bitmaps;
}
use of com.facebook.common.references.CloseableReference in project fresco by facebook.
the class AnimatedImageFactoryImpl method createPreviewBitmap.
private CloseableReference<Bitmap> createPreviewBitmap(AnimatedImage image, Bitmap.Config bitmapConfig, int frameForPreview) {
CloseableReference<Bitmap> bitmap = createBitmap(image.getWidth(), image.getHeight(), bitmapConfig);
AnimatedImageResult tempResult = AnimatedImageResult.forAnimatedImage(image);
AnimatedDrawableBackend drawableBackend = mAnimatedDrawableBackendProvider.get(tempResult, null);
AnimatedImageCompositor animatedImageCompositor = new AnimatedImageCompositor(drawableBackend, new AnimatedImageCompositor.Callback() {
@Override
public void onIntermediateResult(int frameNumber, Bitmap bitmap) {
// Don't care.
}
@Override
@Nullable
public CloseableReference<Bitmap> getCachedBitmap(int frameNumber) {
return null;
}
});
animatedImageCompositor.renderFrame(frameForPreview, bitmap.get());
return bitmap;
}
use of com.facebook.common.references.CloseableReference in project fresco by facebook.
the class AnimatedRepeatedPostprocessorProducerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mTestExecutorService = new TestExecutorService(new FakeClock());
mPostprocessorProducer = new PostprocessorProducer(mInputProducer, mPlatformBitmapFactory, mTestExecutorService);
mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, /* isPrefetch */
false, /* isIntermediateResultExpected */
Priority.MEDIUM, mConfig);
when(mImageRequest.getPostprocessor()).thenReturn(mPostprocessor);
mResults = new ArrayList<>();
when(mPostprocessor.getName()).thenReturn(POSTPROCESSOR_NAME);
when(mProducerListener.requiresExtraMap(mProducerContext, POSTPROCESSOR_NAME)).thenReturn(true);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mResults.add(((CloseableReference<CloseableImage>) invocation.getArguments()[0]).clone());
return null;
}
}).when(mConsumer).onNewResult(any(CloseableReference.class), anyInt());
mInOrder = inOrder(mPostprocessor, mProducerListener, mConsumer);
}
use of com.facebook.common.references.CloseableReference in project fresco by facebook.
the class AnimatedSingleUsePostprocessorProducerTest method testNonStaticBitmapIsPassedOn.
@Test
public void testNonStaticBitmapIsPassedOn() {
SingleUsePostprocessorConsumer postprocessorConsumer = produceResults();
CloseableAnimatedImage sourceCloseableAnimatedImage = mock(CloseableAnimatedImage.class);
CloseableReference<CloseableImage> sourceCloseableImageRef = CloseableReference.<CloseableImage>of(sourceCloseableAnimatedImage);
postprocessorConsumer.onNewResult(sourceCloseableImageRef, Consumer.IS_LAST);
sourceCloseableImageRef.close();
mTestExecutorService.runUntilIdle();
mInOrder.verify(mConsumer).onNewResult(any(CloseableReference.class), eq(Consumer.IS_LAST));
mInOrder.verifyNoMoreInteractions();
assertEquals(1, mResults.size());
CloseableReference<CloseableImage> res0 = mResults.get(0);
assertTrue(CloseableReference.isValid(res0));
assertSame(sourceCloseableAnimatedImage, res0.get());
res0.close();
verify(sourceCloseableAnimatedImage).close();
}
use of com.facebook.common.references.CloseableReference in project fresco by facebook.
the class RemoveImageTransformMetaDataProducerTest method testOnNewResult.
@Test
public void testOnNewResult() {
when(mEncodedImage.getByteBufferRef()).thenReturn(mIntermediateResult);
when(mEncodedImage.isValid()).thenReturn(true);
mRemoveMetaDataConsumer.onNewResult(mEncodedImage, Consumer.NO_FLAGS);
ArgumentCaptor<CloseableReference> argumentCaptor = ArgumentCaptor.forClass(CloseableReference.class);
verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(Consumer.NO_FLAGS));
CloseableReference intermediateResult = argumentCaptor.getValue();
assertEquals(mIntermediateResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly(), intermediateResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
when(mEncodedImage.getByteBufferRef()).thenReturn(mFinalResult);
mRemoveMetaDataConsumer.onNewResult(mEncodedImage, Consumer.IS_LAST);
verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(Consumer.NO_FLAGS));
CloseableReference finalResult = argumentCaptor.getValue();
assertEquals(mFinalResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly(), finalResult.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
}
Aggregations