public BitmapAnimationBackend( PlatformBitmapFactory platformBitmapFactory, BitmapFrameCache bitmapFrameCache, AnimationInformation animationInformation, BitmapFrameRenderer bitmapFrameRenderer, @Nullable BitmapFramePreparationStrategy bitmapFramePreparationStrategy, @Nullable BitmapFramePreparer bitmapFramePreparer) { mPlatformBitmapFactory = platformBitmapFactory; mBitmapFrameCache = bitmapFrameCache; mAnimationInformation = animationInformation; mBitmapFrameRenderer = bitmapFrameRenderer; mBitmapFramePreparationStrategy = bitmapFramePreparationStrategy; mBitmapFramePreparer = bitmapFramePreparer; mPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG); updateBitmapDimensions(); }
public ExperimentalBitmapAnimationDrawableFactory( AnimatedDrawableBackendProvider animatedDrawableBackendProvider, ScheduledExecutorService scheduledExecutorServiceForUiThread, ExecutorService executorServiceForFramePreparing, MonotonicClock monotonicClock, PlatformBitmapFactory platformBitmapFactory, CountingMemoryCache<CacheKey, CloseableImage> backingCache, Supplier<Integer> cachingStrategySupplier, Supplier<Integer> numberOfFramesToPrepareSupplier) { mAnimatedDrawableBackendProvider = animatedDrawableBackendProvider; mScheduledExecutorServiceForUiThread = scheduledExecutorServiceForUiThread; mExecutorServiceForFramePreparing = executorServiceForFramePreparing; mMonotonicClock = monotonicClock; mPlatformBitmapFactory = platformBitmapFactory; mBackingCache = backingCache; mCachingStrategySupplier = cachingStrategySupplier; mNumberOfFramesToPrepareSupplier = numberOfFramesToPrepareSupplier; }
public CountingMemoryCache( ValueDescriptor<V> valueDescriptor, CacheTrimStrategy cacheTrimStrategy, Supplier<MemoryCacheParams> memoryCacheParamsSupplier, PlatformBitmapFactory platformBitmapFactory, boolean isExternalCreatedBitmapLogEnabled) { mValueDescriptor = valueDescriptor; mExclusiveEntries = new CountingLruMap<>(wrapValueDescriptor(valueDescriptor)); mCachedEntries = new CountingLruMap<>(wrapValueDescriptor(valueDescriptor)); mCacheTrimStrategy = cacheTrimStrategy; mMemoryCacheParamsSupplier = memoryCacheParamsSupplier; mMemoryCacheParams = mMemoryCacheParamsSupplier.get(); mLastCacheParamsCheck = SystemClock.uptimeMillis(); if (isExternalCreatedBitmapLogEnabled) { platformBitmapFactory.setCreationListener( new PlatformBitmapFactory.BitmapCreationObserver() { @Override public void onBitmapCreated( Bitmap bitmap, Object callerContext) { mOtherEntries.put(bitmap, callerContext); } }); } }
public static AnimatedFactory getAnimatedFactory( PlatformBitmapFactory platformBitmapFactory, ExecutorSupplier executorSupplier, CountingMemoryCache<CacheKey, CloseableImage> backingCache) { if (!sImplLoaded) { try { final Class<?> clazz = Class.forName("com.facebook.fresco.animation.factory.AnimatedFactoryV2Impl"); final Constructor<?> constructor = clazz.getConstructor( PlatformBitmapFactory.class, ExecutorSupplier.class, CountingMemoryCache.class); sImpl = (AnimatedFactory) constructor.newInstance( platformBitmapFactory, executorSupplier, backingCache); } catch (Throwable e) { // Head in the sand } if (sImpl != null) { sImplLoaded = true; } } return sImpl; }
/** * Clients should override this method only if the post-processed bitmap has to be of a different * size than the source bitmap. If the post-processed bitmap is of the same size, clients should * override one of the other two methods. * * <p> The source bitmap must not be modified as it may be shared by the other clients. The * implementation must create a new bitmap that is safe to be modified and return a reference * to it. Clients should use <code>bitmapFactory</code> to create a new bitmap. * * @param sourceBitmap The source bitmap. * @param bitmapFactory The factory to create a destination bitmap. * @return a reference to the newly created bitmap */ @Override public CloseableReference<Bitmap> process( Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) { final Bitmap.Config sourceBitmapConfig = sourceBitmap.getConfig(); CloseableReference<Bitmap> destBitmapRef = bitmapFactory.createBitmapInternal( sourceBitmap.getWidth(), sourceBitmap.getHeight(), sourceBitmapConfig != null ? sourceBitmapConfig : FALLBACK_BITMAP_CONFIGURATION); try { process(destBitmapRef.get(), sourceBitmap); return CloseableReference.cloneOrNull(destBitmapRef); } finally { CloseableReference.closeSafely(destBitmapRef); } }
ProducerFactory createProducerFactory( Context context, ByteArrayPool byteArrayPool, ImageDecoder imageDecoder, ProgressiveJpegConfig progressiveJpegConfig, boolean downsampleEnabled, boolean resizeAndRotateEnabledForNetwork, boolean decodeCancellationEnabled, Supplier<Boolean> experimentalSmartResizingEnabled, ExecutorSupplier executorSupplier, PooledByteBufferFactory pooledByteBufferFactory, MemoryCache<CacheKey, CloseableImage> bitmapMemoryCache, MemoryCache<CacheKey, PooledByteBuffer> encodedMemoryCache, BufferedDiskCache defaultBufferedDiskCache, BufferedDiskCache smallImageBufferedDiskCache, MediaVariationsIndex mediaVariationsIndex, CacheKeyFactory cacheKeyFactory, PlatformBitmapFactory platformBitmapFactory, int bitmapPrepareToDrawMinSizeBytes, int bitmapPrepareToDrawMaxSizeBytes, boolean bitmapPrepareToDrawForPrefetch);
@Override public CloseableReference<Bitmap> process( Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) { final CloseableReference<Bitmap> bitmapRef = bitmapFactory.createBitmap( sourceBitmap.getWidth() / SCALE_RATIO, sourceBitmap.getHeight() / SCALE_RATIO); try { final Bitmap destBitmap = bitmapRef.get(); final Canvas canvas = new Canvas(destBitmap); canvas.drawBitmap( sourceBitmap, null, new Rect(0, 0, destBitmap.getWidth(), destBitmap.getHeight()), mPaint); NativeBlurFilter.iterativeBoxBlur(destBitmap, mIterations, mBlurRadius / SCALE_RATIO); return CloseableReference.cloneOrNull(bitmapRef); } finally { CloseableReference.closeSafely(bitmapRef); } }
@Override public CloseableReference<Bitmap> process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) { float scale = 1.0f * width / sourceBitmap.getWidth(); Log.e("ReScalePostprocessor", "scale:" + scale); scaledWidth = (int) (sourceBitmap.getWidth() * scale); scaledHeight = (int) (sourceBitmap.getHeight() * scale); listener.onProcessFinished(scaledWidth, scaledHeight); Matrix matrix = new Matrix(); matrix.postScale(scale, scale); Bitmap bitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix, true); CloseableReference<Bitmap> bitmapRef = bitmapFactory.createBitmap(bitmap); try { return CloseableReference.cloneOrNull(bitmapRef); } finally { CloseableReference.closeSafely(bitmapRef); } }
@Override public CloseableReference<Bitmap> process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) { CloseableReference<Bitmap> bitmapRef; if (isFull) { bitmapRef = bitmapFactory.createBitmap( sourceBitmap.getWidth() / 2, sourceBitmap.getHeight()); } else { bitmapRef = bitmapFactory.createBitmap( sourceBitmap.getWidth(), sourceBitmap.getHeight()); } try { Bitmap destBitmap = bitmapRef.get(); Canvas canvas2d = new Canvas(destBitmap); canvas2d.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth() / 2, sourceBitmap.getHeight()), new Rect(0, 0, destBitmap.getWidth(), destBitmap.getHeight()), null); return CloseableReference.cloneOrNull(bitmapRef); } finally { CloseableReference.closeSafely(bitmapRef); } }
@Override public CloseableReference<Bitmap> process( Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) { final CloseableReference<Bitmap> bitmapRef = bitmapFactory.createBitmap( sourceBitmap.getWidth() / mScaleRatio, sourceBitmap.getHeight() / mScaleRatio); try { final Bitmap destBitmap = bitmapRef.get(); final Canvas canvas = new Canvas(destBitmap); canvas.drawBitmap( sourceBitmap, null, new Rect(0, 0, destBitmap.getWidth(), destBitmap.getHeight()), mPaint); NativeBlurFilter.iterativeBoxBlur( destBitmap, mIterations, Math.max(1, mBlurRadius / mScaleRatio)); return CloseableReference.cloneOrNull(bitmapRef); } finally { CloseableReference.closeSafely(bitmapRef); } }
public DefaultBitmapFramePreparer( PlatformBitmapFactory platformBitmapFactory, BitmapFrameRenderer bitmapFrameRenderer, Bitmap.Config bitmapConfig, ExecutorService executorService) { mPlatformBitmapFactory = platformBitmapFactory; mBitmapFrameRenderer = bitmapFrameRenderer; mBitmapConfig = bitmapConfig; mExecutorService = executorService; mPendingFrameDecodeJobs = new SparseArray<>(); }
@DoNotStrip public AnimatedFactoryV2Impl( PlatformBitmapFactory platformBitmapFactory, ExecutorSupplier executorSupplier, CountingMemoryCache<CacheKey, CloseableImage> backingCache) { mPlatformBitmapFactory = platformBitmapFactory; mExecutorSupplier = executorSupplier; mBackingCache = backingCache; }
public static CountingMemoryCache<CacheKey, CloseableImage> get( Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry, PlatformBitmapFactory platformBitmapFactory, boolean isExternalCreatedBitmapLogEnabled) { return get( bitmapMemoryCacheParamsSupplier, memoryTrimmableRegistry, platformBitmapFactory, isExternalCreatedBitmapLogEnabled, new BitmapMemoryCacheTrimStrategy()); }
public static CountingMemoryCache<CacheKey, CloseableImage> get( Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry, PlatformBitmapFactory platformBitmapFactory, boolean isExternalCreatedBitmapLogEnabled, CountingMemoryCache.CacheTrimStrategy trimStrategy) { ValueDescriptor<CloseableImage> valueDescriptor = new ValueDescriptor<CloseableImage>() { @Override public int getSizeInBytes(CloseableImage value) { return value.getSizeInBytes(); } }; CountingMemoryCache<CacheKey, CloseableImage> countingCache = new CountingMemoryCache<>( valueDescriptor, trimStrategy, bitmapMemoryCacheParamsSupplier, platformBitmapFactory, isExternalCreatedBitmapLogEnabled); memoryTrimmableRegistry.registerMemoryTrimmable(countingCache); return countingCache; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); PowerMockito.mockStatic(SystemClock.class); PowerMockito.when(SystemClock.uptimeMillis()).thenReturn(0L); mValueDescriptor = new ValueDescriptor<Integer>() { @Override public int getSizeInBytes(Integer value) { return value; } }; mParams = new MemoryCacheParams( CACHE_MAX_SIZE, CACHE_MAX_COUNT, CACHE_EVICTION_QUEUE_MAX_SIZE, CACHE_EVICTION_QUEUE_MAX_COUNT, CACHE_ENTRY_MAX_SIZE); when(mParamsSupplier.get()).thenReturn(mParams); mPlatformBitmapFactory = Mockito.mock(PlatformBitmapFactory.class); mBitmapReference = CloseableReference.of(mBitmap, FAKE_BITMAP_RESOURCE_RELEASER); mCache = new CountingMemoryCache<>( mValueDescriptor, mCacheTrimStrategy, mParamsSupplier, mPlatformBitmapFactory, true); }
@Test public void testOnBitmapCreated() throws Exception { mPlatformBitmapFactory = mock(PlatformBitmapFactory.class, CALLS_REAL_METHODS); mCache = new CountingMemoryCache<>( mValueDescriptor, mCacheTrimStrategy, mParamsSupplier, mPlatformBitmapFactory, true); assertEquals("other entries count mismatch", 0, mCache.mOtherEntries.size()); mPlatformBitmapFactory.addBitmapReference(mBitmapReference.get(), null); assertEquals("other entries count mismatch" ,1, mCache.mOtherEntries.size()); }
@Before public void setup() { PowerMockito.mockStatic(WebPImage.class); mWebPImageMock = mock(WebPImage.class); mMockAnimatedDrawableBackendProvider = mock(AnimatedDrawableBackendProvider.class); mMockBitmapFactory = mock(PlatformBitmapFactory.class); mAnimatedImageFactory = new AnimatedImageFactoryImpl( mMockAnimatedDrawableBackendProvider, mMockBitmapFactory); ((AnimatedImageFactoryImpl) mAnimatedImageFactory).sWebpAnimatedImageDecoder = mWebPImageMock; }
public static CountingMemoryCache<CacheKey, PooledByteBuffer> get( Supplier<MemoryCacheParams> encodedMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry, PlatformBitmapFactory platformBitmapFactory) { ValueDescriptor<PooledByteBuffer> valueDescriptor = new ValueDescriptor<PooledByteBuffer>() { @Override public int getSizeInBytes(PooledByteBuffer value) { return value.size(); } }; CountingMemoryCache.CacheTrimStrategy trimStrategy = new NativeMemoryCacheTrimStrategy(); CountingMemoryCache<CacheKey, PooledByteBuffer> countingCache = new CountingMemoryCache<>( valueDescriptor, trimStrategy, encodedMemoryCacheParamsSupplier, platformBitmapFactory, false); memoryTrimmableRegistry.registerMemoryTrimmable(countingCache); return countingCache; }
public PostprocessorProducer( Producer<CloseableReference<CloseableImage>> inputProducer, PlatformBitmapFactory platformBitmapFactory, Executor executor) { mInputProducer = Preconditions.checkNotNull(inputProducer); mBitmapFactory = platformBitmapFactory; mExecutor = Preconditions.checkNotNull(executor); }
/** * Provide the implementation of the PlatformBitmapFactory for the current platform * using the provided PoolFactory * * @param poolFactory The PoolFactory * @param platformDecoder The PlatformDecoder * @return The PlatformBitmapFactory implementation */ public static PlatformBitmapFactory buildPlatformBitmapFactory( PoolFactory poolFactory, PlatformDecoder platformDecoder) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new ArtBitmapFactory(poolFactory.getBitmapPool()); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { return new HoneycombBitmapFactory( new EmptyJpegGenerator(poolFactory.getPooledByteBufferFactory()), platformDecoder); } else { return new GingerbreadBitmapFactory(); } }
public PlatformBitmapFactory getPlatformBitmapFactory() { if (mPlatformBitmapFactory == null) { mPlatformBitmapFactory = buildPlatformBitmapFactory( mConfig.getPoolFactory(), getPlatformDecoder()); } return mPlatformBitmapFactory; }
@Before public void setup() { PowerMockito.mockStatic(GifImage.class); mGifImageMock = mock(GifImage.class); mMockAnimatedDrawableBackendProvider = mock(AnimatedDrawableBackendProvider.class); mMockBitmapFactory = mock(PlatformBitmapFactory.class); mAnimatedImageFactory = new AnimatedImageFactoryImpl( mMockAnimatedDrawableBackendProvider, mMockBitmapFactory); ((AnimatedImageFactoryImpl) mAnimatedImageFactory).sGifAnimatedImageDecoder = mGifImageMock; }
public static BitmapAnimationBackend createColorBitmapAnimationBackend( final int[] colors, final int animationDurationMs, final BitmapFrameCache bitmapFrameCache) { final PlatformBitmapFactory platformBitmapFactory = Fresco.getImagePipelineFactory().getPlatformBitmapFactory(); final BitmapFrameRenderer bitmapFrameRenderer = new ColorAndFrameNumberRenderer(colors); final AnimationInformation animationInformation = new ColorListAnimationInformation( colors, animationDurationMs); final ExecutorService executorServiceForFramePreparer = new DefaultSerialExecutorService( new DefaultExecutorSupplier(1).forDecode()); final BitmapFramePreparationStrategy framePreparationStrategy = new FixedNumberBitmapFramePreparationStrategy(NUMBER_OF_FRAMES_TO_PREPARE); final BitmapFramePreparer bitmapFramePreparer = new DefaultBitmapFramePreparer( platformBitmapFactory, bitmapFrameRenderer, Bitmap.Config.ARGB_8888, executorServiceForFramePreparer); BitmapAnimationBackend bitmapAnimationBackend = new BitmapAnimationBackend( platformBitmapFactory, bitmapFrameCache, animationInformation, bitmapFrameRenderer, framePreparationStrategy, bitmapFramePreparer); bitmapAnimationBackend.setFrameListener(new DebugBitmapAnimationFrameListener()); return bitmapAnimationBackend; }
@Override public CloseableReference<Bitmap> process( Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) { long startTime = System.nanoTime(); CloseableReference<Bitmap> result = super.process(sourceBitmap, bitmapFactory); showDuration(System.nanoTime() - startTime); return result; }
public CloseableReference<Bitmap> process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) { CloseableReference<Bitmap> bitmapRef = bitmapFactory.createBitmap(width, height); try { Bitmap destBitmap = bitmapRef.get(); Canvas canvas = new Canvas(destBitmap); final int color = 0xff424242; final Paint paint = new Paint(); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(width / 2, height / 2, width / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()), new Rect(0, 0, width, height), paint); return CloseableReference.cloneOrNull(bitmapRef); } finally { CloseableReference.closeSafely(bitmapRef); } }