Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return valid bitmap references for FrescoFrameCache
Summary: We cannot use `CloseableStaticBitmap.convertToBitmapReference()` to create the `CloseableReference<Bitmap>` from a `CloseableReference<CloseableImage>`. It works fine if prefetching is disabled (if we do not hold on to the references), but if prefetching is enabled and we hold on to the bitmaps until they are first drawn (see stacked diff), this does NOT work correctly. The reason for this is the implementations of `CountingMemoryCache` and `CountingLruMap` make use of `CloseableImage.getSizeInBytes()` to update their respective sizes in bytes. `CloseableStaticBitmap.convertToBitmapReference()` will detach the underlying bitmap from the `CloseableStaticBitmap`, which is used to calculate the size in bytes. Hence, the size will be reported as 0 when the elements are changed and the cache cannot correctly decrease its size. This means that the cache thinks its size is constantly increasing until it will eventually stop caching new items - which will break all other images as well. The solution to this problem is to not detach the bitmap reference from the bitmap. Instead, I am just returning a new `CloseableReference` with the underlying bitmap with a custom `ResourceReleaser` that will close the `CloseableImage` when appropriate, which will result in correct computations. Reviewed By: kirwan Differential Revision: D4914167 fbshipit-source-id: b34ce0b3bff0a6b3e93e0c7d15379cb2f2872f1a
- Loading branch information