KiteBitmapCache

class KiteBitmapCache<T : Any>(budgetBytes: Long = DEFAULT_BUDGET_BYTES)(source)

Platform bitmaps that a canvas built from images, so that an image drawn many times on a page, such as a tiled background or a row of icons, converts once (#117). A viewer can keep one cache across draws without retaining decoded source images (#371).

A bitmap is kept for one image identity and one KiteImageSampling: the same image drawn at another size needs another bitmap. The cache holds at most budgetBytes of bitmaps and drops the bitmap used least recently first. A bitmap larger than the whole budget is not kept. A nonpositive budget disables retention. Entries retain only opaque identities and bitmaps, never source image buffers. Map operations are synchronized; conversions and size callbacks run outside the lock.

Constructors

Link copied to clipboard
constructor(budgetBytes: Long = DEFAULT_BUDGET_BYTES)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The bytes of the bitmaps that the cache holds.

Functions

Link copied to clipboard
fun clear()

Releases every retained bitmap. A conversion already running may return its bitmap, but cannot repopulate this cleared generation. This does not recycle native resources: a recorded page or another caller may still be drawing a returned bitmap.

Link copied to clipboard
fun getOrPut(image: KiteImageData, sampling: KiteImageSampling, sizeOf: (T) -> Long, build: () -> T?): T?

The bitmap for image drawn with sampling. On a miss, build makes it and sizeOf gives its size in bytes. Returns null when build does. A nonpositive size is not retained. Concurrent misses may build twice; the first retained result wins and both callers receive it. No callback runs while the cache lock is held.