|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Caller-bound bump arena with refcount auto-reset for stb_image. More...
Go to the source code of this file.
Enumerations | |
| enum | ra8_img_arena_consts_t : uint32_t { k_ra8_img_align = 16U , k_ra8_img_align_mask = 15U } |
| Arena alignment knobs (no magic numbers). More... | |
Functions | |
| void | ra8_img_arena_bind (ra8_img_arena_t *arena) |
Bind arena as the active scratch for subsequent decode allocations. | |
| void | ra8_img_arena_unbind (void) |
| Unbind the active arena; subsequent allocation hooks fail with nullptr. | |
| void * | ra8_img_arena_malloc (size_t n) |
stb_image STBI_MALLOC hook: bump n bytes from the bound arena. | |
| void | ra8_img_arena_free (void *p) |
| stb_image STBI_FREE hook: release a block; auto-reset when none live. | |
| void * | ra8_img_arena_realloc_sized (void *p, size_t oldsz, size_t newsz) |
| stb_image STBI_REALLOC_SIZED hook: fresh-allocate, copy, free old. | |
Variables | |
| static ra8_img_arena_t * | s_arena = nullptr |
| Currently-bound arena, or nullptr when no decode is in flight. | |
Caller-bound bump arena with refcount auto-reset for stb_image.
See ra8_img_arena.h for the rationale. Unlike the stb_truetype arena, the backing store is not a file-scope array: the consumer binds a buffer sized for the image at hand (SRAM for thumbnails, SDRAM for full covers) via ra8_img_arena_bind(), and these hooks bump-allocate out of it. The reference count drives an auto-reset so the arena fully drains after each decode.
[Ring 4 / Reflow] {World: NS}
Definition in file ra8_img_arena.c.
| enum ra8_img_arena_consts_t : uint32_t |
Arena alignment knobs (no magic numbers).
| Enumerator | |
|---|---|
| k_ra8_img_align | Allocation alignment, bytes. |
| k_ra8_img_align_mask | k_ra8_img_align - 1 (round-up mask). |
Definition at line 30 of file ra8_img_arena.c.
| void ra8_img_arena_bind | ( | ra8_img_arena_t * | arena | ) |
Bind arena as the active scratch for subsequent decode allocations.
Records arena in a file-static slot and resets it to empty (offset = 0, live = 0). Every ra8_img_arena_malloc() / _free() / _realloc until the next ra8_img_arena_bind() or ra8_img_arena_unbind() operates on it.
| [in,out] | arena | Arena to make active; reset to empty on entry. NULL unbinds (equivalent to ra8_img_arena_unbind()). |
arena, if non-NULL, has base pointing at cap writable bytes. arena and, if non-NULL, it is empty. arena. Definition at line 38 of file ra8_img_arena.c.
References ra8_img_arena_t::live, ra8_img_arena_t::offset, and s_arena.
Referenced by internal_decode_stb(), internal_probe_page(), internal_transcode_image(), and ra8_img_decode_blit().
| void ra8_img_arena_free | ( | void * | p | ) |
stb_image STBI_FREE hook: release a block; auto-reset when none live.
Decrements the bound arena's live-block count; the bump offset is not tracked per block. When the count reaches zero the arena has fully drained, so the offset rewinds to the base. A nullptr argument, or no bound arena, is ignored.
| [in] | p | Pointer to release; nullptr is ignored. |
p was returned by ra8_img_arena_malloc()/_realloc_sized(), or is nullptr. Definition at line 73 of file ra8_img_arena.c.
References ra8_img_arena_t::live, ra8_img_arena_t::offset, and s_arena.
Referenced by ra8_img_arena_realloc_sized().
| void * ra8_img_arena_malloc | ( | size_t | n | ) |
stb_image STBI_MALLOC hook: bump n bytes from the bound arena.
Rounds n up to the 16-byte alignment, bumps the bound arena's offset, and increments its live-block count. Fails with nullptr when no arena is bound, when n exceeds the capacity, or when the request does not fit the remaining capacity.
| [in] | n | Byte count requested by stb_image. |
| nullptr | No arena bound, or the request does not fit. |
Definition at line 52 of file ra8_img_arena.c.
References ra8_img_arena_t::base, ra8_img_arena_t::cap, k_ra8_img_align_mask, ra8_img_arena_t::live, ra8_img_arena_t::offset, and s_arena.
Referenced by ra8_img_arena_realloc_sized().
| void * ra8_img_arena_realloc_sized | ( | void * | p, |
| size_t | oldsz, | ||
| size_t | newsz ) |
stb_image STBI_REALLOC_SIZED hook: fresh-allocate, copy, free old.
A bump arena cannot grow a block in place, so this allocates newsz fresh, copies min(oldsz, newsz) bytes from p, and releases p. The old block's space is not reclaimed until the arena next drains – which is why the caller sizes the arena for the decode's peak, not its net, footprint.
| [in] | p | Existing block (may be nullptr -> behaves as malloc). |
| [in] | oldsz | Current size of p in bytes (0 if p is nullptr). |
| [in] | newsz | Requested new size in bytes. |
newsz bytes with the old contents copied, or nullptr. | nullptr | No arena bound, or the new request does not fit. |
p was returned by a prior hook call, or is nullptr. p's old contents. p remains valid and the arena state is unchanged. Definition at line 87 of file ra8_img_arena.c.
References memcpy(), ra8_img_arena_free(), and ra8_img_arena_malloc().
| void ra8_img_arena_unbind | ( | void | ) |
Unbind the active arena; subsequent allocation hooks fail with nullptr.
Clears the file-static active-arena slot. Used to fence the stb hooks outside a decode so a stray allocation cannot scribble on a stale buffer.
Definition at line 47 of file ra8_img_arena.c.
References s_arena.
Referenced by internal_arena_release(), internal_decode_stb(), internal_encode_source(), internal_probe_page(), and internal_transcode_image().
|
static |
Currently-bound arena, or nullptr when no decode is in flight.
Definition at line 36 of file ra8_img_arena.c.