use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class AnimatedFrameCache method getForReuse.
/**
* Gets the image to be reused, or null if there is no such image.
*
* <p>The returned image is the least recently used image that has no more clients referencing it,
* and it has not yet been evicted from the cache.
*
* <p>The client can freely modify the bitmap of the returned image and can cache it again without
* any restrictions.
*/
@Nullable
public CloseableReference<CloseableImage> getForReuse() {
while (true) {
CacheKey key = popFirstFreeItemKey();
if (key == null) {
return null;
}
CloseableReference<CloseableImage> imageRef = mBackingCache.reuse(key);
if (imageRef != null) {
return imageRef;
}
}
}
use of com.facebook.imagepipeline.image.CloseableImage in project fresco by facebook.
the class AnimatedFrameCacheTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MemoryCacheParams params = new MemoryCacheParams(4 * ByteConstants.MB, 256, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, TimeUnit.MINUTES.toMillis(5));
when(mMemoryCacheParamsSupplier.get()).thenReturn(params);
CountingMemoryCache<CacheKey, CloseableImage> countingMemoryCache = new CountingLruBitmapMemoryCacheFactory().create(mMemoryCacheParamsSupplier, mMemoryTrimmableRegistry, new BitmapMemoryCacheTrimStrategy(), false, false, null);
mCacheKey = new SimpleCacheKey("key");
mAnimatedFrameCache = new AnimatedFrameCache(mCacheKey, countingMemoryCache);
mFrame1 = CloseableReference.of(mock(CloseableImage.class));
mFrame2 = CloseableReference.of(mock(CloseableImage.class));
}
use of com.facebook.imagepipeline.image.CloseableImage 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.imagepipeline.image.CloseableImage in project fresco by facebook.
the class BaseFrescoStethoPlugin method memcache.
private void memcache(PrintStream writer, List<String> args) throws DumpException {
CountingMemoryCacheInspector.DumpInfo<CacheKey, CloseableImage> dumpInfo = mBitmapMemoryCacheInspector.dumpCacheContent();
try {
writer.println(mBitmapMemoryCacheInspector.getClass().getSimpleName());
writer.println();
writer.println("Params:");
writer.println(formatStrLocaleSafe("Max size: %7.2fMB", dumpInfo.maxSize / (1024.0 * KB)));
writer.println(formatStrLocaleSafe("Max entries count: %9d", dumpInfo.maxEntriesCount));
writer.println(formatStrLocaleSafe("Max entry size: %7.2fMB", dumpInfo.maxEntrySize / (1024.0 * KB)));
writer.println();
writer.println("Summary of current content:");
writer.println(formatStrLocaleSafe("Total size: %7.2fMB (includes in-use content)", dumpInfo.size / (1024.0 * KB)));
writer.println(formatStrLocaleSafe("Entries count: %9d", dumpInfo.lruEntries.size() + dumpInfo.sharedEntries.size()));
writer.println(formatStrLocaleSafe("LRU size: %7.2fMB", dumpInfo.lruSize / (1024.0 * KB)));
writer.println(formatStrLocaleSafe("LRU count: %9d", dumpInfo.lruEntries.size()));
writer.println(formatStrLocaleSafe("Shared size: %7.2fMB", (dumpInfo.size - dumpInfo.lruSize) / (1024.0 * KB)));
writer.println(formatStrLocaleSafe("Shared count: %9d", dumpInfo.sharedEntries.size()));
writer.println();
writer.println("The cache consists of two parts: Things " + "currently being used and things not.");
writer.println("Those things that are *not* currently being used are in the LRU.");
writer.println("Things currently being used are considered to be shared. They will be added");
writer.println("to the LRU if/when they stop being used.");
writer.println();
writer.println("LRU contents: (things near the top will be evicted first)");
for (CountingMemoryCacheInspector.DumpInfoEntry entry : dumpInfo.lruEntries) {
writeCacheEntry(writer, entry);
}
writer.println();
writer.println("Shared contents:");
for (CountingMemoryCacheInspector.DumpInfoEntry entry : dumpInfo.sharedEntries) {
writeCacheEntry(writer, entry);
}
if (!args.isEmpty() && "-g".equals(args.get(0))) {
getFiles(writer, dumpInfo);
}
} catch (IOException e) {
throw new DumpException(e.getMessage());
} finally {
dumpInfo.release();
}
}
Aggregations