use of com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend in project fresco by facebook.
the class AnimatedImageFactoryWebPImplTest method testCreateWithDecodeAlFrames.
@Test
public void testCreateWithDecodeAlFrames() throws Exception {
WebPImage mockWebPImage = mock(WebPImage.class);
Bitmap mockBitmap1 = MockBitmapFactory.create(50, 50, DEFAULT_BITMAP_CONFIG);
Bitmap mockBitmap2 = MockBitmapFactory.create(50, 50, DEFAULT_BITMAP_CONFIG);
// Expect a call to WebPImage.create
TrivialPooledByteBuffer byteBuffer = createByteBuffer();
when(mWebPImageMock.decode(byteBuffer.getNativePtr(), byteBuffer.size())).thenReturn(mockWebPImage);
when(mockWebPImage.getWidth()).thenReturn(50);
when(mockWebPImage.getHeight()).thenReturn(50);
// For decoding preview frame, expect some calls.
final AnimatedDrawableBackend mockAnimatedDrawableBackend = createAnimatedDrawableBackendMock(2);
when(mMockAnimatedDrawableBackendProvider.get(any(AnimatedImageResult.class), isNull(Rect.class))).thenReturn(mockAnimatedDrawableBackend);
when(mMockBitmapFactory.createBitmapInternal(50, 50, DEFAULT_BITMAP_CONFIG)).thenReturn(CloseableReference.of(mockBitmap1, FAKE_BITMAP_RESOURCE_RELEASER)).thenReturn(CloseableReference.of(mockBitmap2, FAKE_BITMAP_RESOURCE_RELEASER));
AnimatedImageCompositor mockCompositor = mock(AnimatedImageCompositor.class);
PowerMockito.whenNew(AnimatedImageCompositor.class).withAnyArguments().thenReturn(mockCompositor);
ImageDecodeOptions imageDecodeOptions = ImageDecodeOptions.newBuilder().setDecodePreviewFrame(true).setDecodeAllFrames(true).build();
EncodedImage encodedImage = new EncodedImage(CloseableReference.of(byteBuffer, FAKE_RESOURCE_RELEASER));
encodedImage.setImageFormat(ImageFormat.UNKNOWN);
CloseableAnimatedImage closeableImage = (CloseableAnimatedImage) mAnimatedImageFactory.decodeWebP(encodedImage, imageDecodeOptions, DEFAULT_BITMAP_CONFIG);
// Verify we got the right result
AnimatedImageResult imageResult = closeableImage.getImageResult();
assertSame(mockWebPImage, imageResult.getImage());
assertNotNull(imageResult.getDecodedFrame(0));
assertNotNull(imageResult.getDecodedFrame(1));
assertNotNull(imageResult.getPreviewBitmap());
// Should not have interacted with these.
verify(mMockAnimatedDrawableBackendProvider).get(any(AnimatedImageResult.class), isNull(Rect.class));
verifyNoMoreInteractions(mMockAnimatedDrawableBackendProvider);
verify(mMockBitmapFactory, times(2)).createBitmapInternal(50, 50, DEFAULT_BITMAP_CONFIG);
verifyNoMoreInteractions(mMockBitmapFactory);
verify(mockCompositor).renderFrame(0, mockBitmap1);
verify(mockCompositor).renderFrame(1, mockBitmap2);
}
use of com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend in project fresco by facebook.
the class ExperimentalAnimationFactory method createAnimationBackend.
private AnimationBackend createAnimationBackend(AnimatedImageResult animatedImageResult) {
// Create the animated drawable backend
AnimatedImage animatedImage = animatedImageResult.getImage();
Rect initialBounds = new Rect(0, 0, animatedImage.getWidth(), animatedImage.getHeight());
AnimatedDrawableBackend animatedDrawableBackend = mAnimatedDrawableBackendProvider.get(animatedImageResult, initialBounds);
// Add caching backend
AnimatedDrawableCachingBackend animatedDrawableCachingBackend = mAnimatedDrawableCachingBackendProvider.get(animatedDrawableBackend, AnimatedDrawableOptions.DEFAULTS);
AnimatedDrawableCachingBackendWrapper animatedDrawableCachingBackendWrapper = new AnimatedDrawableCachingBackendWrapper(animatedDrawableCachingBackend);
// Add inactivity check
return AnimationBackendDelegateWithInactivityCheck.createForBackend(animatedDrawableCachingBackendWrapper, mMonotonicClock, mScheduledExecutorServiceForUiThread);
}
use of com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend in project fresco by facebook.
the class ExperimentalBitmapAnimationDrawableFactory method createAnimationBackend.
private AnimationBackend createAnimationBackend(AnimatedImageResult animatedImageResult, @Nullable Bitmap.Config animatedBitmapConig) {
AnimatedDrawableBackend animatedDrawableBackend = createAnimatedDrawableBackend(animatedImageResult);
BitmapFrameCache bitmapFrameCache = createBitmapFrameCache(animatedImageResult);
BitmapFrameRenderer bitmapFrameRenderer = new AnimatedDrawableBackendFrameRenderer(bitmapFrameCache, animatedDrawableBackend);
int numberOfFramesToPrefetch = mNumberOfFramesToPrepareSupplier.get();
BitmapFramePreparationStrategy bitmapFramePreparationStrategy = null;
BitmapFramePreparer bitmapFramePreparer = null;
if (numberOfFramesToPrefetch > 0) {
bitmapFramePreparationStrategy = new FixedNumberBitmapFramePreparationStrategy(numberOfFramesToPrefetch);
bitmapFramePreparer = createBitmapFramePreparer(bitmapFrameRenderer, animatedBitmapConig);
}
BitmapAnimationBackend bitmapAnimationBackend = new BitmapAnimationBackend(mPlatformBitmapFactory, bitmapFrameCache, new AnimatedDrawableBackendAnimationInformation(animatedDrawableBackend), bitmapFrameRenderer, bitmapFramePreparationStrategy, bitmapFramePreparer);
return AnimationBackendDelegateWithInactivityCheck.createForBackend(bitmapAnimationBackend, mMonotonicClock, mScheduledExecutorServiceForUiThread);
}
use of com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend in project fresco by facebook.
the class AnimatedDrawableBackendFrameRenderer method setBounds.
@Override
public void setBounds(@Nullable Rect bounds) {
AnimatedDrawableBackend newBackend = mAnimatedDrawableBackend.forNewBounds(bounds);
if (newBackend != mAnimatedDrawableBackend) {
mAnimatedDrawableBackend = newBackend;
mAnimatedImageCompositor = new AnimatedImageCompositor(mAnimatedDrawableBackend, mCallback);
}
}
use of com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend in project fresco by facebook.
the class AnimatedImageFactoryGifImplTest method testCreateWithPreviewBitmap.
private void testCreateWithPreviewBitmap(GifImage mockGifImage, Bitmap mockBitmap, PooledByteBuffer byteBuffer) throws Exception {
// For decoding preview frame, expect some calls.
final AnimatedDrawableBackend mockAnimatedDrawableBackend = createAnimatedDrawableBackendMock(1);
when(mMockAnimatedDrawableBackendProvider.get(any(AnimatedImageResult.class), isNull(Rect.class))).thenReturn(mockAnimatedDrawableBackend);
when(mMockBitmapFactory.createBitmapInternal(50, 50, DEFAULT_BITMAP_CONFIG)).thenReturn(CloseableReference.of(mockBitmap, FAKE_BITMAP_RESOURCE_RELEASER));
AnimatedImageCompositor mockCompositor = mock(AnimatedImageCompositor.class);
PowerMockito.whenNew(AnimatedImageCompositor.class).withAnyArguments().thenReturn(mockCompositor);
ImageDecodeOptions imageDecodeOptions = ImageDecodeOptions.newBuilder().setDecodePreviewFrame(true).build();
EncodedImage encodedImage = new EncodedImage(CloseableReference.of(byteBuffer, FAKE_RESOURCE_RELEASER));
encodedImage.setImageFormat(ImageFormat.UNKNOWN);
CloseableAnimatedImage closeableImage = (CloseableAnimatedImage) mAnimatedImageFactory.decodeGif(encodedImage, imageDecodeOptions, DEFAULT_BITMAP_CONFIG);
// Verify we got the right result
AnimatedImageResult imageResult = closeableImage.getImageResult();
assertSame(mockGifImage, imageResult.getImage());
assertNotNull(imageResult.getPreviewBitmap());
assertFalse(imageResult.hasDecodedFrame(0));
// Should not have interacted with these.
verify(mMockAnimatedDrawableBackendProvider).get(any(AnimatedImageResult.class), isNull(Rect.class));
verifyNoMoreInteractions(mMockAnimatedDrawableBackendProvider);
verify(mMockBitmapFactory).createBitmapInternal(50, 50, DEFAULT_BITMAP_CONFIG);
verifyNoMoreInteractions(mMockBitmapFactory);
verify(mockCompositor).renderFrame(0, mockBitmap);
}
Aggregations