34static const char*
const s_tag =
"ra8_tile_cache";
99 const uint32_t last = (uint32_t)count - 1U;
100 return (uint16_t)((index > last) ? last : index);
115 if ((pw == 0U) || (ph == 0U)) {
120 if ((tile_w == 0U) || (tile_h == 0U) || (tile_cols == 0U) || (tile_rows == 0U)) {
136 (void)
memset(tc, 0,
sizeof(*tc));
166 *out_tile = (
ra8_tile_t){.pixels = v.
data, .width = dims->
w, .height = dims->
h};
280 const uint16_t v_run = (uint16_t)((v.
ty1 - v.
ty0) + 1U);
281 const uint16_t h_run = (uint16_t)((v.
tx1 - v.
tx0) + 1U);
284 if (((uint32_t)v.
tx1 + 1U) >= (uint32_t)req->
tile_cols) {
304 if (((uint32_t)v.
ty1 + 1U) >= (uint32_t)req->
tile_rows) {
308 .y = (uint16_t)(v.
ty1 + 1U),
318 .y = (uint16_t)(v.
ty0 - 1U),
331 uint16_t* out_warmed)
335 if (out_warmed !=
nullptr) {
347 uint16_t warmed = 0U;
348 for (uint16_t i = 0U; i < cap; ++i) {
350 .tile_x = (uint16_t)(line.
x + (uint16_t)(line.
step_x * i)),
351 .tile_y = (uint16_t)(line.
y + (uint16_t)(line.
step_y * i)),
358 if (out_warmed !=
nullptr) {
359 *out_warmed = warmed;
366 uint32_t* out_misses,
367 uint32_t* out_evictions)
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
The one reusable hash + pin + evict cache engine (#147, #345).
ra8_err_t ra8_keycache_get(ra8_keycache_t *kc, const void *key, ra8_keycache_view_t *out_view)
Get (and pin) the cell for key, rendering it on a miss.
ra8_err_t ra8_keycache_stats(const ra8_keycache_t *kc, uint32_t *out_hits, uint32_t *out_misses, uint32_t *out_evictions)
Report the cache hit / miss / eviction counters.
ra8_err_t ra8_keycache_init(ra8_keycache_t *kc, const ra8_keycache_cfg_t *cfg)
Initialise a cache engine over caller-supplied storage.
ra8_err_t ra8_keycache_put(ra8_keycache_t *kc, const uint8_t *data)
Release one pin on a cell previously returned by ra8_keycache_get.
ra8_err_t ra8_keycache_prefetch(ra8_keycache_t *kc, const void *key)
Warm the cell for key into the cache without holding a pin.
#define ra8_log_error(tag, message)
RA8 log error.
ra8_err_t ra8_tile_cache_get(ra8_tile_cache_t *tc, const ra8_tile_key_t *key, ra8_tile_t *out_tile)
Get (and pin) the decoded tile for key.
ra8_err_t ra8_tile_cache_prefetch_pan(ra8_tile_cache_t *tc, const ra8_tile_prefetch_req_t *req, uint16_t *out_warmed)
Predictively warm the tiles one step ahead of a panning viewport.
ra8_err_t ra8_tile_cache_stats(const ra8_tile_cache_t *tc, uint32_t *out_hits, uint32_t *out_misses, uint32_t *out_evictions)
Report the cache hit / miss / eviction counters.
ra8_err_t ra8_tile_cache_put(ra8_tile_cache_t *tc, const uint8_t *pixels)
Release one pin on a tile previously returned by ra8_tile_cache_get.
ra8_err_t ra8_tile_cache_init(ra8_tile_cache_t *tc, const ra8_tile_cache_cfg_t *cfg)
Initialise a tile cache over caller-supplied storage.
uint32_t ra8_tile_cache_capacity(const ra8_tile_cache_t *tc)
Report the number of cells the cache can hold.
ra8_err_t ra8_tile_cache_prefetch(ra8_tile_cache_t *tc, const ra8_tile_key_t *key)
Warm one tile into the cache without holding a pin (read-ahead).
static ra8_err_t internal_tile_decode(void *ctx, const void *key, uint8_t *cell, uint32_t cell_bytes, void *user)
Decode trampoline: adapt ra8_tile_decode_fn to the keycache seam.
ra8_err_t ra8_tile_rect_of_pixels(uint32_t px, uint32_t py, uint32_t pw, uint32_t ph, uint16_t tile_w, uint16_t tile_h, uint16_t tile_cols, uint16_t tile_rows, ra8_tile_rect_t *out)
Convert a pixel rectangle into the inclusive tile rectangle covering it.
static bool internal_pan_line(const ra8_tile_prefetch_req_t *req, priv_pan_line_t *out)
Compute the lead-edge tile run for a pan direction, or none at an edge.
static uint16_t internal_clamp_tile(uint32_t index, uint16_t count)
Clamp a tile index to the last valid index of a grid dimension.
static ra8_err_t internal_validate_req(const ra8_tile_prefetch_req_t *req)
Reject a structurally invalid prefetch request.
Fixed-RAM-budget image-tile cache with LRU eviction (Layer 3b, #147).
@ k_ra8_tile_pan_none
No travel: prefetch is a no-op.
@ k_ra8_tile_pan_up
Warm the row above the viewport.
@ k_ra8_tile_pan_down
Warm the row below the viewport.
@ k_ra8_tile_pan_left
Warm the column left of the viewport.
@ k_ra8_tile_pan_right
Warm the column right of the viewport.
The lead-edge tile run a pan prefetch walks (one row or one column).
uint16_t count
Tiles on the lead edge (pre-budget).
uint16_t step_y
Per-tile row delta (0 or 1).
uint16_t step_x
Per-tile column delta (0 or 1).
uint16_t y
First lead tile row.
uint16_t x
First lead tile column.
Caller-supplied storage + policy + renderer for ra8_keycache_init.
uint32_t bucket_count
Number of hash buckets (>= 1).
uint32_t user_bytes
Bytes per user descriptor (may be 0).
uint8_t * cell_mem
cell_count * cell_bytes of cell storage.
uint32_t cell_bytes
Bytes per cell (the rendered payload).
uint8_t * key_mem
cell_count * key_bytes of key storage.
int32_t * buckets
bucket_count hash-bucket heads.
uint32_t key_bytes
Bytes per key (>= 1).
ra8_keycache_cell_t * meta
cell_count link-metadata entries.
uint32_t cell_count
Number of cells.
void * render_ctx
Opaque context passed to render.
ra8_keycache_render_fn render
Render-on-miss callback.
uint8_t * user_mem
cell_count * user_bytes, or NULL if none.
ra8_keycache_cfg_t cfg
Configuration (copied at init).
A pinned view of a cached cell returned by ra8_keycache_get.
uint8_t * data
Cell payload (cell_bytes wide).
void * user
Per-cell user descriptor, or NULL.
Caller-supplied storage + decoder for ra8_tile_cache_init.
ra8_tile_dims_t * dims
cell_count dimension descriptors.
uint32_t cell_bytes
Bytes per cell (max decoded tile).
ra8_tile_decode_fn decode
Decode-on-miss callback.
uint8_t * cell_mem
cell_count * cell_bytes of tile storage.
uint32_t cell_count
Number of cells.
ra8_keycache_cell_t * meta
cell_count link-metadata entries.
uint32_t bucket_count
Number of hash buckets (>= 1).
ra8_tile_key_t * keys
cell_count key-storage entries.
void * decode_ctx
Opaque context passed to decode.
int32_t * buckets
bucket_count hash-bucket heads.
Tile-cache state (caller-owned; treat as private).
ra8_keycache_t kc
Underlying keyed-LRU cache.
void * decode_ctx
Caller's decoder context.
ra8_tile_decode_fn decode
Caller's tile decoder.
Per-cell user descriptor: the decoded tile dimensions.
uint16_t h
Decoded tile height in pixels.
uint16_t w
Decoded tile width in pixels.
Identifies one decoded image tile.
A predictive pan-prefetch request: what is visible + where it heads.
uint16_t max_tiles
Residency budget: warm at most this many.
ra8_tile_rect_t view
The tiles the viewport currently straddles.
uint16_t tile_rows
Image tile rows (lead-edge clamp bound).
uint16_t zoom
Zoom / mip level for the key (0 = native).
ra8_tile_pan_dir_t dir
Direction of viewport travel.
uint32_t image_id
Tile-cache key image id (the image panned).
uint16_t tile_cols
Image tile columns (lead-edge clamp bound).
An inclusive rectangle of tile grid coordinates (the visible tiles).
uint16_t ty0
Topmost visible tile row (inclusive).
uint16_t tx1
Rightmost visible tile column (inclusive).
uint16_t ty1
Bottommost visible tile row (inclusive).
uint16_t tx0
Leftmost visible tile column (inclusive).
A pinned view of a cached tile returned by ra8_tile_cache_get.