Commit Graph
1214 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.6 f7ebd549ed [util/hb-view] --show-extents: foreground color, no per-color split
Drop the bespoke red pen dot + magenta extents rectangle in
favor of a single foreground-color overlay that matches the
look raster, vector, and gpu now produce after their port to
the shared helper: stroked rect around each glyph's ink box,
plus a filled dot at the pen origin.

Cairo's annotation pass stays native (post-glyph drawing
through cairo, not via hb_paint funcs); only the colors and
the dot rendering changed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:22:42 -06:00
Behdad EsfahbodandClaude Opus 4.6 c152eaceb3 [util] --show-extents: add a filled dot at the pen origin
Extend the shared overlay helper (and rename it from
util_emit_extents_rect_into_* to util_emit_extents_overlay_
into_*) to emit two pieces of geometry per glyph: the
existing stroked rect around the ink box, plus a filled
dot at the pen origin via hb_draw_circle.  Both go in the
foreground color through the same draw / paint flow.

The dot helps debug glyph positioning at a glance and gives
the previously-uncalled hb_draw_circle a real caller in the
suite.

Raster, vector, and gpu utils pick up the dot automatically
via the renamed helper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:22:42 -06:00
Behdad EsfahbodandClaude Opus 4.6 591748f1e1 [draw][paint] Make get_funcs instance-aware; add get_format
The six public draw / paint funcs getters across raster,
vector, and gpu used to be singletons:

  hb_raster_draw_get_funcs (void)
  hb_raster_paint_get_funcs (void)
  hb_vector_draw_get_funcs (void)
  hb_vector_paint_get_funcs (void)
  hb_gpu_draw_get_funcs (void)
  hb_gpu_paint_get_funcs (void)

That works fine for raster and gpu, where there's a single
backend per type, but breaks for the vector backend where
SVG and PDF have separate funcs sets — callers using the
public getter always got SVG funcs and silently produced
SVG markup inside PDF output streams when invoking the new
arbitrary-path clip API on a PDF context.

Make all six take a const-pointer to the relevant context
instance.  vector_paint dispatches on paint->format; the
other five just use the instance for symmetry today (room
for future format-style dispatch later).

Also expose hb_vector_draw_get_format / hb_vector_paint_
get_format public getters so callers (or third parties)
can ask a vector context for its format without poking at
internals.

Also: hb_vector_paint_push_clip_path_end now wraps the
emitted SVG clipPath's path in transform="scale(1,-1)" so
free-form arbitrary clips at base body level land in the
same coord system the per-glyph <use scale(_,-sy)>
wrappers establish.  Without this, free-form clip-path
arbitrary outlines emitted between paint_glyph calls came
out mirrored across the X axis.

Updates internal callers (hb_vector_paint_glyph,
hb_pdf_emit_glyph_path, hb_raster_paint_push_clip_path_
start, hb_gpu_paint_push_clip_path_start, the GPU pen
adapter), util sites (raster-output.hh, vector-output.hh,
gpu/demo-font.cc), API tests (test-raster.cc, test-gpu.cc),
and the docs section index.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:21:49 -06:00
Behdad EsfahbodandClaude Opus 4.6 fe77507f14 [util/gpu] Port --show-extents to the shared paint helper
Use util_emit_extents_rect_into_{draw,paint} from
helper-extents-overlay.hh so the GPU demo's extents
overlay matches the raster and vector ports — same
coordinate, padding, and stroke convention; same
foreground-color fill via the arbitrary-path clip API in
paint mode.

Adds --show-extents support for the paint (color-glyph)
path, which previously only the draw path implemented.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:19:17 -06:00
Behdad EsfahbodandClaude Opus 4.6 cf5325f4f5 [util/vector] Port --show-extents to the paint API
Bake the per-glyph extents rectangle into the same draw or
paint context that rendered the glyph, via the shared
helper from helper-extents-overlay.hh.  Matches the raster
util's port: in paint mode, the rect goes through
push_clip_path_start/end + paint_color (foreground); in
draw mode, hb_draw_rectangle on hb_vector_draw_get_funcs
appends to the scratch which the next glyph's entry-flush
(or render) emits as its own <path>/fill.

Drops the standalone emit_extents_overlay function and
its FF0000-dot + FF00FF-stroke SVG markup — the new
overlay renders in the glyph's foreground color, same as
the raster port.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:19:17 -06:00
Behdad EsfahbodandClaude Opus 4.6 98470a3e02 [draw] Rename hb_draw_rect to hb_draw_rectangle
API rename for the not-yet-released stroked/filled
rectangle helper added to hb-draw — full names
(hb_draw_line, hb_draw_circle, hb_draw_rectangle) read
better than mixed full/abbreviated.

Updates the public header, impl, the gpu doc reference,
the GPU API test, the GPU demo's extents overlay, the
extents-overlay paint helper, and the docs section
listing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 77817c597e [util/raster] Port --show-extents draw mode; factor shared math
Add util_emit_extents_rect_into_draw in helper-extents-
overlay.hh — takes a draw funcs pair + glyph extents + pen
position + stroke_width and emits the padded stroked rect
in one place.  util_emit_extents_rect_into_paint (renamed
from _paint for clarity) now wraps it in the
push_clip_path_start/_end + paint_color + pop_clip dance.

Both raster draw loops (finish_draw_solid accumulated into
one rdr, finish_draw_palette per-glyph) now bake the extents
ring into the draw context with util_emit_extents_rect_into_
draw, alongside the glyph outline in foreground color.
finish_paint's call site collapses from an inline
coord-normalize-and-pad block to a single helper call.

Uses copysignf on the padding so the "outward" shift tracks
the y_bearing/height sign instead of needing a caller-side
normalize; pairs with the hb_draw_rect fix for negative
w/h in the same branch.

Drop the now-unused collect_ink_extents_rects /
overlay_rects_bgra / overlay_rects_rgb / rect_i_t helpers
that implemented the old manual BGRA overlay pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad EsfahbodandClaude Opus 4.6 134066df57 [util/raster] Port --show-extents to the paint API (paint mode)
Replace the manual BGRA 1-pixel overlay with a per-glyph
hb_paint_push_clip_path_start/_end + hb_draw_rect + paint
foreground sequence, wrapped in the new shared helper
util_emit_extents_rect_paint in helper-extents-overlay.hh.
Each glyph now bakes its own extents ring into the glyph's
rendered mask via the raster-paint backend's arbitrary-
path clip, so compositing picks it up alongside the glyph
ink (same code path as the color layers).

Pads the nominal rect outward by stroke_width/2 so the
stroke's inner edge sits at the ink box — otherwise the
inner half would knock out against glyph ink under non-
zero-winding clipping.  Normalizes w/h to positive before
padding so the outward shift is unambiguous regardless of
y_bearing / height sign conventions.

Draw-mode loops (finish_draw_solid, finish_draw_palette)
still use the old collect+overlay path and will follow up.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad Esfahbod 18825a19a1 Address PR #5931 review feedback
- Reset Since tags to XSince: REPLACEME for new non-or_fail
  glyph functions (gpu, raster, vector paint).
- Remove duplicate doc comment on static
  hb_vector_paint_glyph_impl helper.
- Fix hb_gpu_paint_glyph doc: remove internal LAYER_SOLID
  reference.
- Drop hb_ot_color_has_svg() from color-detection in all utils
  (cairo, raster, vector, hb-raster-all); HarfBuzz does not
  render SVG table natively, so checking it caused fallback to
  monochrome drawing of the actual outlines.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:16:38 -06:00
Behdad Esfahbod 390ec06fa7 Merge pull request #5931 from harfbuzz/paint_or_fails
[vector/raster/gpu] Add *_glyph_or_fail() variants across all three
2026-04-16 16:13:05 -06:00
Behdad Esfahbod 5ce8f73bad [util/vector] Apply margin in pixel units
The other utils (hb-view, hb-raster) treat --margin as pixels, but
hb-vector was applying it directly to the upem-space extents.  For a
font with upem=1000 rendered at font-size=72, the default 16-pixel
margin came out as 16/1000*72 = ~1.15 pixels per side, much smaller
than expected.

Convert margin from pixels to upem before adding it to the extents,
matching the per-axis x_scale/y_scale used elsewhere in the file.

Now hb-vector and hb-raster produce matching surface dimensions for
the same input (e.g. NotoNastaliqUrdu "اردو" at 72px: 137x213 in both).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 14:35:58 -06:00
Behdad EsfahbodandClaude Opus 4.6 e933f71b0d [cairo][util/hb-view] Honor --draw / --paint via cairo color mode
hb-cairo's render_color_glyph drops _or_fail in favor of
the synthesizing hb_font_paint_glyph, so the paint callback
handles every glyph (color or mono) through the paint
pipeline instead of returning NOT_IMPLEMENTED on non-color
glyphs and forcing cairo to fall through to the outline
path.

Hb-view's helper-cairo then picks paint vs draw the same
way the other utils do — --paint wins over --draw,
otherwise auto-detect via the font's color tables — and
expresses "draw" by setting CAIRO_COLOR_MODE_NO_COLOR on
the font options (which makes cairo skip render_color_glyph
entirely, falling through to render_glyph for the cheaper
outline path).  No new public API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 14:07:38 -06:00
Behdad EsfahbodandClaude Opus 4.6 ffd4772e05 [util] Add --draw / --paint flags to raster, vector, gpu
Move the force_draw / force_paint flags from gpu-output.hh
into the shared view-options.hh so all rendering utils
expose --draw and --paint with the same semantics: --paint
wins over --draw, otherwise auto-detect via the font's
color tables.

raster and vector previously only ran the paint pipeline
when the font had a color table; they now also honor
--paint (renders mono fonts via paint synthesis) and
--draw (forces the outline path even on color fonts).

Vector's per-glyph try-paint-then-fall-back-to-draw is
replaced with a single mode decision up front.  Each
glyph then goes through hb_vector_{paint,draw}_glyph
(non-_or_fail), which handles the synthesis fallback
internally — color glyphs render in either mode (paint
synthesizes for non-color fonts; draw renders nothing for
color-only glyphs without an outline, which matches user
intent for --draw).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 13:56:32 -06:00
Behdad Esfahbod 98f3a42ee2 [vector/raster/gpu] Add *_glyph_or_fail() variants across all three
Consolidate the {vector,raster,gpu}_{draw,paint}_glyph APIs
to match the hb_font_{draw,paint}_glyph / _or_fail pattern:

  * Each existing *_glyph() public function now returns void.
    For the draw variants this is purely a return-value drop.
    For the paint variants the void entry additionally gains a
    synthesize fallback for non-color glyphs (calls
    hb_font_paint_glyph instead of _or_fail) so a mono glyph
    still produces output via a foreground-colored outline.

  * New *_glyph_or_fail() variants return hb_bool_t, reporting
    exactly what hb_font_{draw,paint}_glyph_or_fail() would.
    Callers that care about distinguishing color paint from
    synthesized outline now have a clean boolean signal.

Refactors the internal impls behind a shared static helper
parameterised by a `fallible` flag; the two public entries
delegate, passing true (for _or_fail) or false (for the void
alias).

For GPU specifically, paint_glyph_or_fail no longer folds the
encoder's unsupported flag into its return -- that state was
always better reported from hb_gpu_paint_encode() (which
returns NULL), and conflating the two prevented callers from
telling "font has no paint data" from "encoder hit a limit".

While in there, remove a dead branch at the end of
hb_vector_paint_glyph's SVG case (both inner blocks had
already returned; the tail was unreachable).

Updates docs/harfbuzz-sections.txt with the six new symbols
and the NEWS note with the Changed API callouts.  Updates
in-tree callers (hb-vector-svg-all, hb-raster-all, test-gpu,
util/vector-output.hh) to the _or_fail variants where they
previously read the return value.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/5926

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 00:36:37 -06:00
Behdad Esfahbod 152aa0fd8c [vector] Divide explicit set_extents by scale_factor
hb_vector_{paint,draw}_set_extents stored caller-supplied
extents as-is, while per-glyph extents accumulated via
hb_vector_set_glyph_extents_common were divided by
scale_factor on the way in.  When callers passed extents in
input-space (the natural unit alongside the glyph geometry
they're feeding) and a non-1 scale_factor, the resulting
viewBox didn't match what the glyphs drew.

Make set_extents divide by scale_factor too, matching the
accumulate path; callers can now pass input-space extents
uniformly.

Also:

* hb-vector-paint's global transform wrapper dropped the
  redundant /scale_factor division.  Each per-glyph
  <use transform="... scale(1/scale_factor, ...)"> already
  applies scale_factor; wrapping the body in another
  /scale_factor matrix double-scaled the output, shrinking
  color-glyph output to 1/scale_factor^2 of its intended
  size.  The wrapper now only fires when the user set a
  non-identity paint->transform, and emits that transform
  as-is.

* util/vector-output.hh simplification: now that set_extents
  handles the divide, drop the local pre-multiply of extents
  by upem_to_pixel -- pass the upem-space extents through.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 22:04:26 -06:00
Behdad Esfahbod d8980e94e0 [draw] Add line/rect/circle drawing helpers (#5925)
* [gpu] Add hb_gpu_draw_line / _rect / _circle shape helpers

The GPU draw encoder already consumes arbitrary curves via the
hb_draw_funcs_t machinery -- that's how glyph outlines feed in.
Expose three convenience helpers so callers can emit common
shapes (tapered line, rectangle, circle) without having to
hand-roll the curve math:

    hb_gpu_draw_line   (draw, x0,y0,w0, x1,y1,w1);
    hb_gpu_draw_rect   (draw, x,y,w,h, stroke_width);
    hb_gpu_draw_circle (draw, cx,cy,r, stroke_width);

stroke_width = NaN means "filled".  A finite positive value
produces a stroked outline by emitting an outer contour CCW
and an inner contour CW so the fill rule carves a hole.

For shapes beyond these three helpers, callers can feed any
outline through hb_draw_move_to / _line_to / _quadratic_to /
_cubic_to / _close_path with the funcs from
hb_gpu_draw_get_funcs() and the hb_gpu_draw_t as data -- the
helpers are thin wrappers over that path.

Useful for game UI: health bars, progress rings, custom
line-art decorations, rendered through the same slug shader
as text.

Assisted-by: Claude <noreply@anthropic.com>

* [util/gpu] Add --show-extents flag

Exercises hb_gpu_draw_rect: when the flag is set, each glyph
blob encodes its ink-extent frame as an extra stroked
rectangle alongside the glyph outline, so the frame is cached
with the glyph and renders with no extra draw call.

The frame is padded outward by stroke_width / 2 so the stroke
sits entirely outside the glyph ink (otherwise the inner half
would knock out against the glyph shape, since both fill in
the same blob).

Cmdline-only for now -- a runtime 'e' toggle would require a
buffer re-shape hook that native hb-gpu doesn't yet expose.

Assisted-by: Claude <noreply@anthropic.com>

* [util/gpu] Cmdline toggles mirroring interactive keybindings

Add --dark / --no-vsync / --fullscreen / --no-stem-darken /
--debug so scripts and CI can start hb-gpu in any of the
states previously reachable only by pressing a key
interactively.  Applied via the same keystroke path by
synthesizing the corresponding key characters through
demo_view_type() at startup -- single source of truth for
each toggle.

Assisted-by: Claude <noreply@anthropic.com>

* [draw] Promote shape helpers from hb-gpu-draw to hb-draw

Three shape-emitting helpers (line, rect, circle) operate on
any hb_draw_funcs_t, not specifically the GPU backend.  Move
them out of the GPU-only API surface into the core hb-draw
API so any pen (raster, vector, gpu, user-supplied) gets
them.

API rename / move:

  hb_gpu_draw_line   -> hb_draw_line   (in src/hb-draw.h)
  hb_gpu_draw_rect   -> hb_draw_rect
  hb_gpu_draw_circle -> hb_draw_circle

Signatures gain a (dfuncs, draw_data, st) prefix to match the
existing hb_draw_move_to / line_to / cubic_to / close_path
shape -- the helpers are thin wrappers over those.

Callers in test/api/test-gpu.cc and util/gpu/demo-font.cc
updated to call hb_draw_* with hb_gpu_draw_get_funcs() and a
local hb_draw_state_t.

Updated harfbuzz-sections.txt with the new entries; removed
hb_gpu_draw_line / _rect / _circle from hb-gpu.h.

Assisted-by: Claude <noreply@anthropic.com>

* [draw] hb_draw_line: NaN second width defaults to first

Common case is a uniform-width line.  Letting @w1 default to
@w0 when NaN is passed makes the call shorter:

  hb_draw_line (..., x0, y0, 4, x1, y1, NAN);  /* uniform 4 */

Mirrors the NaN-as-sentinel convention used in hb_draw_rect /
hb_draw_circle for the stroke_width parameter.

Assisted-by: Claude <noreply@anthropic.com>

* [draw] hb_draw_line: add cap parameter (butt / square)

Add hb_draw_line_cap_t enum with HB_DRAW_LINE_CAP_BUTT (the
existing default behavior) and HB_DRAW_LINE_CAP_SQUARE, which
extends each endpoint along the line direction by half its
local stroke width.

Square caps let four hb_draw_line() calls form a closed
rectangle without gaps at the corners -- a meaningfully
cheaper alternative to hb_draw_rect() for thin outlined
rectangles, since each line's bbox is just stroke_width tall
instead of covering the full rectangle interior.

Round caps not implemented yet; can be added as a third enum
value when a use case shows up.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 21:49:45 -06:00
Behdad Esfahbod d60ffa956f [util/vector] Emit SVG/PDF in pixel units, not upem
vector-output.hh fed upem-space coordinates to the draw/paint
context and then set scale_factor=1, so the resulting SVG's
viewBox / width / height were in upem (e.g. ~2500×1400 for a
48 px "Hello" in a 1000-upem font).  Browsers sized the
inline SVG at 1 upem-unit-per-CSS-pixel, rendering it ~20×
too large.

Fix: compute the upem→pixel ratio from x_scale / y_scale
(already available) and

  * scale the explicit extents by that ratio before calling
    set_extents (so viewBox and width/height come out in
    pixels), and
  * pass its inverse as set_scale_factor so upem-space input
    coordinates (pen position, glyph outline points) get
    divided to pixels internally.

No test expected-output changes -- the vector tests render
at FONT_SIZE_UPEM where upem_to_pixel = 1 and the patch is a
no-op.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 17:31:37 -06:00
Behdad Esfahbod 14259b79dc [util/gpu/web] Silence "empty character constant" warnings
EM_ASM stringifies its body, but the C tokenizer still parses
single-quoted '' as an empty char constant.  Use double-quoted
"" -- valid JS empty string, no warning.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:46:02 -06:00
Behdad Esfahbod 7f6d75cd9e [util/gpu/web] Export _web_set_palette in both build scripts
The previous palette commit added the C entry point and the
shell.html message handler but forgot to list _web_set_palette
in EXPORTED_FUNCTIONS, so emscripten dead-stripped it and the
'palette' postMessage was a silent no-op in the iframe.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:29:42 -06:00
Behdad Esfahbod 59d819f09c [util/gpu/web] Live palette via postMessage
Add web_set_palette() to both GL and WebGPU bindings (forwards
to demo_font_set_palette + buffer rebuild) and accept a
{ kind: 'palette', value: <int> } message in shell.html.  Lets
the harfbuzz-world.cc host page push the user's CPAL pick into
the embedded GPU iframe alongside text / font / variations.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:22:13 -06:00
Behdad EsfahbodandClaude Opus 4.6 ca75fd5ff9 [vector] Drop hb_vector_{draw,paint}_{set,get}_flat (#5927)
Flat mode disabled glyph reuse / caching to produce inline-
everything SVG output.  Its main use case was making
hb-vector SVGs safe to concatenate side-by-side in a single
document, but the recently-added svg_set_prefix API solves
that without giving up the cache.  No remaining callers in
tree (util/vector-output.hh's --flat option goes too).

Removes:
  - hb_vector_draw_set_flat / get_flat
  - hb_vector_paint_set_flat / get_flat
  - the `flat` field on both contexts
  - all `if (flat)` / `bool can_cache = !flat` branches
  - the --flat option in util/vector-output.hh
  - the four "flat*" expected files in test/vector/basic
  - the flat_draw / flat_paint params in the vector fuzzer
  - sections-list entries

meson test --no-rebuild green (241/241).

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 15:03:43 -06:00
Behdad EsfahbodandClaude Opus 4.6 d17ff1e8d6 [util/gpu/web] Live variations via postMessage
Add web_set_variations(const char *) to both the WebGL and
WebGPU hb-gpu-web wasm modules.  Parses a comma-separated
"wght=400,wdth=100" string via hb_variation_from_string,
applies via hb_font_set_variations on the current font, and
rebuilds the shaping buffer.  Cheap to call repeatedly --
suitable for live slider pushes once a slider UI lands.

Shell.html grows a matching applyVariations() helper and a
'variations' postMessage case.  config-override.h undefs
HB_NO_VAR so the new function actually links.  EXPORTED
_FUNCTIONS on both build scripts list _web_set_variations.

Also plumbed in a small cap (32 axes) on the stack so the
parser doesn't need hb's internal containers -- no font has
anywhere near that many.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 12:57:18 -06:00
Behdad EsfahbodandClaude Opus 4.6 d35cdadd2a [util/gpu/web] Ignore 0x0 resizeCanvas calls; keep default buffer
The iframe-hosted case ran resizeCanvas() at script parse
time, before the iframe had laid out its canvas, which
installed a 0x0 drawing buffer.  getContext('webgl2')
grabbed that 0x0 context and every subsequent setup (atlas,
viewport, swap chain) was frozen at 0x0 even when
ResizeObserver later re-ran resizeCanvas with real dims --
the existing context doesn't resize with the canvas
attribute.

Bail out of resizeCanvas when either dimension is 0, so the
canvas keeps its intrinsic default (300x150) until a real
layout arrives.  getContext then grabs a non-degenerate
context, and the first ResizeObserver callback bumps it up
to the actual iframe-sized buffer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 12:00:17 -06:00
Behdad EsfahbodandClaude Opus 4.6 b13da1a712 [util/gpu/web] Re-fire window resize from the canvas observer
Changing canvas.width/height directly doesn't reach
emscripten's GLFW port -- its framebuffer-size callback
fires on window 'resize' events, not canvas mutation
records.  When ResizeObserver picks up the iframe's first
real layout, also dispatch a synthetic 'resize' event so
the framebuffer_size callback runs in wasm and glViewport
gets re-set to the real size.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 11:58:57 -06:00
Behdad EsfahbodandClaude Opus 4.6 05cb6623f6 [util/gpu/web] ResizeObserver on canvas; pick up first real layout
Initial resizeCanvas() runs at script parse time -- when the
shell is inside a just-mounted iframe, the canvas's
clientWidth / clientHeight are 0 (iframe hasn't laid out
yet) and the GL drawing buffer installs at 0x0.  A plain
window 'resize' event never fires just because the iframe
has sized itself, so the buffer stays 0x0 and the tab looks
blank forever.

Watch the canvas with a ResizeObserver and re-run
resizeCanvas + requestRedraw on any observed size change,
which catches the first real size the moment the iframe
lays out.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 11:57:36 -06:00
Behdad EsfahbodandClaude Opus 4.6 8c99cf0a9a [util/gpu/web] Accept ?embed without a value, not just ?embed=1
Be permissive about the embed-mode URL form: ?embed,
?embed=1, ?embed=true all turn the mode on; only explicit
?embed=0 / ?embed=false leave it off.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 06:13:45 -06:00
Behdad EsfahbodandClaude Opus 4.6 bdea49603c [util/gpu/web] Add embed-mode + postMessage protocol to the web demo
Lets a host page embed hb-gpu-demo as an iframe and drive it
from outside.  harfbuzz-world.cc uses this to share its
text/font controls with the GPU tab without reinventing the
GPU stack.

Shell additions:
  - ?embed=1 URL param hides the demo's own chrome (font
    picker, text button, backend selector, FPS counter,
    keyboard-help overlay) by setting html.embed.
  - Message protocol:
      { kind: 'text', value: '…' }           -> applyText
      { kind: 'font', bytes: ArrayBuffer }    -> _web_load_font
    On runtime init the shell posts { kind: 'ready' } to its
    parent so the host can send font bytes (which can't ride
    on the URL for file-uploaded fonts).

Existing ?text= and ?font= URL params still work and are
useful for "link to a specific demo" sharing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 06:09:28 -06:00
Behdad Esfahbod e731c38975 [draw] Promote shape helpers from hb-gpu-draw to hb-draw
Three shape-emitting helpers (line, rect, circle) operate on
any hb_draw_funcs_t, not specifically the GPU backend.  Move
them out of the GPU-only API surface into the core hb-draw
API so any pen (raster, vector, gpu, user-supplied) gets
them.

API rename / move:

  hb_gpu_draw_line   -> hb_draw_line   (in src/hb-draw.h)
  hb_gpu_draw_rect   -> hb_draw_rect
  hb_gpu_draw_circle -> hb_draw_circle

Signatures gain a (dfuncs, draw_data, st) prefix to match the
existing hb_draw_move_to / line_to / cubic_to / close_path
shape -- the helpers are thin wrappers over those.

Callers in test/api/test-gpu.cc and util/gpu/demo-font.cc
updated to call hb_draw_* with hb_gpu_draw_get_funcs() and a
local hb_draw_state_t.

Updated harfbuzz-sections.txt with the new entries; removed
hb_gpu_draw_line / _rect / _circle from hb-gpu.h.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 02:27:43 -06:00
Behdad Esfahbod 8815cf5666 [util/gpu] Cmdline toggles mirroring interactive keybindings
Add --dark / --no-vsync / --fullscreen / --no-stem-darken /
--debug so scripts and CI can start hb-gpu in any of the
states previously reachable only by pressing a key
interactively.  Applied via the same keystroke path by
synthesizing the corresponding key characters through
demo_view_type() at startup -- single source of truth for
each toggle.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 02:20:44 -06:00
Behdad Esfahbod a150fc2218 [util/gpu] Add --show-extents flag
Exercises hb_gpu_draw_rect: when the flag is set, each glyph
blob encodes its ink-extent frame as an extra stroked
rectangle alongside the glyph outline, so the frame is cached
with the glyph and renders with no extra draw call.

The frame is padded outward by stroke_width / 2 so the stroke
sits entirely outside the glyph ink (otherwise the inner half
would knock out against the glyph shape, since both fill in
the same blob).

Cmdline-only for now -- a runtime 'e' toggle would require a
buffer re-shape hook that native hb-gpu doesn't yet expose.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 02:19:53 -06:00
Behdad Esfahbod bb64f2cb30 [util/gpu] Fold the handful of used view options into the GPU group
hb-gpu only honors four of view_options_t's eleven options
(--foreground, --background, --font-palette, --custom-palette).
Exposing the full set via --help-view misled users into trying
--stroke, --margin, --rainbow, etc., which silently did nothing.

Merge the four relevant entries into the GPU option group
(pointing at view_options_t's storage fields) and delegate
parsing to view.post_parse() via a new gpu_output_t::post_parse.
Drops the unused view entries from --help while keeping all
the color/palette parsing logic shared with hb-view / hb-raster.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-14 23:13:17 -06:00
Behdad Esfahbod ed9bdd1031 [util/gpu] Silence LOGI output when --output-file is set
Scripted / CI use of hb-gpu -o wants clean stderr.  Gate LOGI on
a hb_gpu_demo_quiet flag that hb-gpu flips to 1 when an output
file is specified, so font stats, help text, and toggle-vsync
chatter all stay out of the way.

LOGW / LOGE are intentionally unaffected -- warnings and fatal
errors should always surface regardless of quiet mode.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-14 23:01:41 -06:00
Behdad Esfahbod 18fa43ce29 [util/gpu] Fix regression: --output-file required an output file
Using output_options_t<false> (no stdout default) was the wrong
choice: post_parse() rejects any invocation without -o, so every
windowed hb-gpu run started failing with "No output file was
specified."

Roll a bespoke char* option instead: if set, render one frame
to PPM (opening the file or stdout inline); otherwise the usual
windowed mode.  Keeps both code paths trivial and doesn't
require the caller to specify an output file for interactive
use.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-14 22:59:05 -06:00
Behdad Esfahbod 9ebdd0019f [util/gpu] Add --output-file for headless PPM render
Gives hb-gpu a non-interactive output path:

  hb-gpu --demo -o /tmp/frame.ppm
  hb-gpu --demo -o -  | display  # stdout piping

When --output-file is set, the GL backend passes
GLFW_VISIBLE=false so no window pops up.  After the normal init
and one render pass, we glReadPixels the default framebuffer,
flip row order, and write a PPM (P6) to the selected sink.
No event loop, process exits after writing.

Supported format: ppm (only).  Other formats are rejected by the
shared output_options_t machinery.  Metal and D3D11 backends
currently still open a window; headless support there is a
straightforward follow-up.

This unlocks CI golden-image tests for shader changes and
reproducible benchmark timing without swapchain-present jitter.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-14 20:48:26 -06:00
Behdad Esfahbod 6828ad2865 [util/gpu] Route LOGI to stderr
LOGI is informational output (help text, toggle state, fps).  It
belongs on stderr: that keeps stdout available for program output
(e.g. --output-file=- piping a PPM through a pipeline), and it
matches LOGW/LOGE which already go to stderr.

No user-visible change in normal (windowed) runs; stderr shows up
in the same terminal as stdout by default.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-14 20:48:17 -06:00
Behdad Esfahbod 1f813cfb86 [util/gpu] Extract MSL/HLSL/WGSL demo shaders into own files
Matches the GLSL convention: demo-shader.{msl,hlsl,wgsl} live
alongside demo-fragment.glsl and get stringified by the same
gen-gpu-shader-artifacts.py helper into demo-shader-{msl,hlsl,
wgsl}.hh.  No more giant inline R"msl(...)" / R"hlsl(...)" /
R"wgsl(...)" blobs in the .mm / .cc files.

Each language combines vertex and fragment entry points in one
source, as is idiomatic for MSL / HLSL / WGSL compilers; GLSL's
split (demo-vertex.glsl + demo-fragment.glsl) is preserved
because glCompileShader takes separate stages.

No functional change.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 15:33:44 -06:00
Behdad Esfahbod c4da618566 [gpu] Stem-darken by per-fragment color, not by foreground uniform
The demo fragment shaders were passing u_foreground's brightness
to hb_gpu_stem_darken(), which was wrong for color glyphs: a red
cheek on an emoji should darken relative to its own red, not to
whatever the text-foreground uniform happens to be.

Switch all four demo fragment paths (GL, Metal, D3D11, WebGPU)
to compute brightness from the fragment's own straight color
(c.rgb / c.a).  For monochrome glyphs this is identical to the
old formula -- the synthesized single layer's color IS the
foreground uniform -- so non-color rendering is unchanged.

The public hb_gpu_stem_darken() helper is unchanged; only its
callers pass a different brightness.  Document the paint-path
usage in the hb-gpu section.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 15:24:32 -06:00
Behdad Esfahbod 819fce8352 [gpu] Document Paint renderer; drop encode-time foreground API
Integrates the paint renderer into the hb-gpu module docs:

- Intro notes two renderers (Draw for monochrome, Paint for
  COLRv0/COLRv1, with explicit note that Paint also handles
  monochrome outlines at some cost).
- New Paint section parallel to Draw covers encoding, shader
  composition, and fragment shader, referencing Draw for the
  shared atlas / vertex / dilation / stem-darkening pieces.
- Encoding examples drop hb_gpu_*_reset() in favour of
  hb_gpu_*_encode()'s auto-clear.

Drops hb_gpu_paint_set_foreground() / _get_foreground() and the
foreground field from hb_gpu_paint_t.  The encoded blob only
records an is_foreground flag per layer/stop; the actual
foreground color has always been a shader uniform passed to
hb_gpu_paint() at render time.  The encoder API was never
load-bearing -- the value was handed to hb_font_paint_glyph() but
the encoder callback ignores everything except the flag.

Also makes hb_gpu_paint_encode() auto-clear on return (matching
hb_gpu_draw_encode()), and removes the now-dead
demo_font_set_foreground() wrapper from the demo layer.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 15:15:53 -06:00
Behdad Esfahbod f840ae39a2 [util/gpu] Add --draw / --paint flags with auto-detect by font
Adds command-line flags --draw (force monochrome Slug path) and
--paint (force COLRv1 paint path) to hb-gpu, defaulting to
auto-detect based on hb_ot_color_has_paint(face).  Threads a
draw_only bool through the demo layer so each backend compiles
exactly one fragment program (draw or paint, not both).

The paint pipeline is ~10x slower than the draw pipeline on
monochrome content; auto-detect lets monochrome fonts keep the
fast path while still exercising both code paths from the same
binary.

Plumbing:

- demo_renderer_create_{gl,metal,d3d11} and demo_font_create
  take a draw_only argument.
- demo-fragment.{glsl,msl,hlsl} branch on HB_GPU_DEMO_DRAW,
  calling either hb_gpu_draw or hb_gpu_paint.
- demo-shader / glstate / d3d11 / metal include only the
  fragment helper for the chosen path and prepend
  HB_GPU_DEMO_DRAW to the source when draw_only.
- demo-font dispatches glyph upload to hb_gpu_draw_* or
  hb_gpu_paint_* and hides palette/foreground setters in
  draw mode.

Web demos pass false (paint-only) for now; a runtime
re-creation hook on font change would be needed there.

Tested on desktop GL, win64 D3D11, WebGL, WebGPU.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 00:04:27 -06:00
Behdad Esfahbod 6ca076f36b [util/gpu] Apply stem darkening in Metal and D3D11 fragment shaders
demo-fragment.glsl (desktop GL/WebGL) and the WGSL shader in
hb-gpu-web-webgpu.cc already invoked hb_gpu_stem_darken on the
painted result; the Metal (fragment_main) and D3D11 (ps_main)
entry points were missing that block, so stem darkening did
nothing on those backends.

Add the same call: compute ppem from fwidth(texcoord), derive
brightness from the foreground luminance, and scale the
premultiplied result by darkened/c.a.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 22:43:18 -06:00
Behdad Esfahbod ea88d25d07 [util/gpu] Web demos: drop stale gamma-toggle hints
The `g` key was removed when we hardcoded gamma 2.2; the shell's
help overlay still mentioned it.  Drop the lines.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 22:29:00 -06:00
Behdad Esfahbod 62a8a3a26c [util/gpu] Drop sRGB framebuffer mode; always gamma 2.2
The paint encoder bakes sRGB-encoded font palette values directly
(quantizing 0..255 to 0..32767 without decoding), so the shader
writes sRGB-ish values.  With GL_FRAMEBUFFER_SRGB enabled the
driver then applied linear->sRGB encoding on store, giving a
double-encoded, washed-out result -- most visible on mid-tone
gradients.

The cleanest fix is to stop pretending we're doing linear-space
compositing: drop the sRGB framebuffer mode entirely and always
apply the classic 2.2 gamma exponent for coverage correction
(flipped to 1/2.2 in dark mode to match the existing light/dark
logic).  Removed pieces:

 - demo_view_t::gamma_mode enum, demo_view_set_gamma_mode,
   demo_view_cycle_gamma, and the `g` keybinding + help line
 - demo_renderer_t::set_srgb virtual + every backend override
 - GLFW_SRGB_CAPABLE hint in gpu-output.hh
 - Metal swapchain MTLPixelFormatBGRA8Unorm_sRGB -> BGRA8Unorm

Replaced with demo_view_update_gamma, called on setup() and after
the dark-mode toggle.  Shader side stays the same (only alpha gets
the gamma curve, as before).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 19:30:45 -06:00
Behdad Esfahbod 087fd84a49 [util/gpu] Drop renderer palette plumbing, forward to hb_gpu_paint
Colors are now baked into encoded blobs (see prior commit), so
nothing needs to upload or bind a palette buffer.  Remove
demo_renderer_t::set_palette from all backends (GL, Metal, D3D11,
WebGPU), the hb_gpu_palette GL uniform plumbing in demo-glstate,
the Metal/D3D11 palette buffers, and the WebGPU storage buffer +
bind-group entry.  demo_font_get_palette is also gone.

Replace with new demo_font accessors that forward to the encoder:

  demo_font_set_palette
  demo_font_set_foreground
  demo_font_clear_custom_palette_colors
  demo_font_set_custom_palette_color

Each invalidates the glyph cache because colors are baked into
the atlas entries.  gpu-output.hh now forwards view-option
--font-palette / --custom-palette through these.

Web demos stop allocating / uploading the palette buffer; the
WGSL fragment shader drops its third bind-group slot.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 18:45:12 -06:00
Behdad Esfahbod 585154aa10 [util/gpu] Web demos: fix URL-param handling for ?font= and ?text=
rebuild_buffer did free(current_text); strdup(text); but was often
called with text == current_text (from web_load_font's
"custom_text ? current_text : default").  Strdup of freed memory
shaped garbage and made multi-char strings look like 1 char.  Fix:
strdup first, then free.

The WebGL rebuild_buffer also called demo_view_display itself,
which runs fine from a main loop tick but not from a fetch
promise's microtask (the canvas back-buffer doesn't swap).  Drop
it: demo_view_reset sets needs_redraw=true, and the next
main_loop_iter renders inside a proper rAF tick.

Emscripten allocates argv on the JS stack, which is unwound when
main returns.  WebGPU's init is async and reads arg_text/arg_font
after main returns, so those pointers were dangling -- early null
bytes in freed stack memory made the emoji URL shape to 1 glyph.
strdup them in main so they survive.

Finally, forward ?font= to argv as --font= (already done for
?text=) so the C side's "skip initial default-font glyph upload
when a font fetch is pending" path actually triggers.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 18:12:47 -06:00
Behdad Esfahbod 736d59bf72 [util/gpu] demo-font: tolerate NULL paint encode
hb_gpu_paint_encode returns NULL when the glyph uses unsupported
paint features (e.g. COLRv1 gradients/transforms) or emits zero
ops.  Treat that as an empty glyph instead of die()-ing the whole
app, so fonts mixing supported and unsupported paint still render
their supported parts.

Zero-init hb_ext so the empty-glyph extents are well-defined, and
skip recycle_blob when blob is NULL.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 18:12:23 -06:00
Behdad Esfahbod b616298d73 [util/gpu] Web demos: skip default-font upload when ?font= pending; preserve URL on backend switch; reflect custom text in URL
Three small UX improvements to the web demos.

### Skip default-font upload when ?font= is pending

When ?font= is set, the async fetch replaces the font later.  main
was still populating the atlas with the default font's glyphs for
the initial text, just to throw them away when _web_load_font ran
its own rebuild_buffer.  Gate demo_buffer_add_text() on !arg_font
so the buffer stays empty until the real font lands.

### WebGPU ready signal

WebGPU's init_demo is async (awaits adapter/device), so
onRuntimeInitialized fires before the demo is usable; calling
_web_load_font from the ?font= fetch at that point tripped a wasm
indirect-call signature mismatch.  init_demo now EM_ASMs a
window._webDemoReady() hook at its tail; the shell installs
_webDemoReady = startFontFetch when running the WebGPU build and
starts the fetch immediately for WebGL.

### URL ergonomics

* Backend-selector change now carries location.search across the
  navigation -- ?text= and ?font= survive the WebGL <-> WebGPU
  switch.
* The text-edit modal's Apply button updates history.replaceState
  with a ?text= param so the typed text is copy/pasteable.  Skips
  the update when the text is unchanged from what was open.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 17:10:31 -06:00
Behdad Esfahbod c85b453e90 [util/gpu] Web demos: URL ?text= and ?font=; wider default font
Two user-visible features plus a font swap.

### URL parameters

Forwards ?text= and ?font= from the query string into the C main
as --text=... and --font=... via Module.arguments, so the initial
text is applied before the first rendered frame (no flash of
default demo text).  ?font= is still fetched asynchronously on
the JS side; once loaded, the text is re-applied to the new font.

If neither parameter is present, behaviour is unchanged: the
baked-in default text renders in the baked-in default font.

Data URLs (?font=data:font/ttf;base64,...) work naturally via
fetch().  Remote URLs need CORS; raw.githubusercontent.com and
jsdelivr both work, github.com/.../raw/... does not.

### Wider default font

The baked-in default-font.hh was a narrow subset that didn't
include uppercase Latin, so `?text=Hello` shaped to .notdef for
H and W.  Re-subset Parastoo-Regular.ttf via hb-subset with:

    --unicodes='U+0020-007E,U+0600-06FF,U+FB50-FDFF,U+FE70-FEFF'

covering printable ASCII plus the Arabic block and the two
Arabic presentation-forms blocks.

Font size:
    source Parastoo-Regular.ttf     109152
    new subset                       49940

Wasm size impact (webgl build, Oz+lto):
    before  443628  181597 gz
    after   466657  196209 gz
    delta   +23029  +14612 gz

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 17:03:53 -06:00
Behdad Esfahbod 44a0fb1cd5 [util/gpu] Respect view-options: foreground, background, palette, custom-palette
Wires view_options_t into gpu_output_t so hb-gpu picks up the
same foreground/background/palette flags the rest of the tools
use:

  --foreground=#RRGGBB[AA]
  --background=#RRGGBB[AA]
  --font-palette=N
  --custom-palette=N=#RRGGBB[,N=#RRGGBB,...]

After demo_view_setup() the gpu main loop now:

1. Fetches the active palette from the face via
   demo_font_get_palette(font, view.palette, ...) -- palette index
   out of range falls back to 0.
2. Overlays each view.custom_palette_entries entry on top of that
   palette (clamped to 256 entries).
3. Uploads via renderer->set_palette().  Web demos and the
   headless WebGPU path do the same, with palette_index=0 (they
   don't yet plumb --font-palette).
4. Calls renderer->set_foreground / _background from the
   post-parsed view-options colours.  Defaults match the demo's
   prior LIGHT mode, so no-op when the user passes no flags; the
   dark-mode toggle (b key) still mutates renderer state
   independently.

Other view-options flags (--rainbow, --stroke, --line-space,
--margin, --logical/--ink, --show-extents, --font-extents)
appear in --help-view for familiarity but currently no-op in
hb-gpu; they're inherited wholesale from view_options_t and the
gpu path just doesn't wire them.

demo_font_get_palette() now takes a palette_index parameter so
callers can ask for non-zero palettes (e.g. dark-mode palettes in
fonts that ship them).  Web demos pass 0 for now.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 16:28:09 -06:00
Behdad Esfahbod cf3d69bc54 [util/gpu] Cross-backend palette upload via demo_renderer_t::set_palette
Reorganises the palette-upload plumbing so every backend handles
it uniformly and the hacky atlas-backend palette callback goes
away.

Before: demo_font_upload_palette in demo-font.cc mixed a GL
glUniform4fv direct call with a detour through an extra
demo_atlas_backend_t.upload_palette callback used by the Metal
renderer.  demo-font and demo-atlas both knew about palettes.

After:

* demo_font_get_palette (font, out, capacity) just reports the
  active palette as RGBA floats; demo-font no longer touches GL
  state or the atlas for palettes.

* demo_renderer_t gains a virtual set_palette (rgba, count).
  Default is a no-op.  Backends override:
   - demo-renderer-gl.cc -> demo_glstate_set_palette() ->
     glUniform4fv.
   - demo-metal.mm -> memcpy into the MTLBuffer's contents.
   - demo-renderer-d3d11.cc -> ID3D11DeviceContext::UpdateSubresource
     (palette buffer switched from IMMUTABLE to DEFAULT).
   - hb-gpu-web-webgpu.cc -> wgpuQueueWriteBuffer on the palette
     storage buffer.

* Callers invoke renderer->set_palette (palette, n) right after
  demo_font_create:
   - util/gpu-output.hh (desktop demo: GL / Metal / D3D11).
   - util/gpu/web/hb-gpu-web.cc (WebGL).
   - util/gpu/web/hb-gpu-web-webgpu.cc (WebGPU).

* The extra upload_palette field on demo_atlas_backend_t is
  removed along with demo_atlas_upload_palette / _is_external --
  atlas is back to being about glyph data only.

COLRv0 rendering now works with proper palette colours through
every backend that implements set_palette (WebGL, WebGPU, and
Metal/D3D11 once tested).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 16:19:13 -06:00
Behdad Esfahbod 9aec34108b [gpu] Fix Metal segfault: route palette upload through atlas backend
The Metal path creates a GLFW window with GLFW_NO_API (no GL
context), but demo_font_upload_palette() unconditionally called
glGetIntegerv(), causing a segfault on the first glyph lookup.

Split palette upload into GL and external-backend paths:

- Extract demo_font_get_palette() to read CPAL colors into a
  float array, shared by both paths.
- GL path (demo_font_upload_palette_gl) uploads via glUniform4fv
  as before.
- External-backend path uploads via a new upload_palette callback
  in demo_atlas_backend_t.
- Metal renderer implements the callback, writing palette data
  directly to its paletteBuffer.

This fixes the --metal crash and enables proper COLRv0 palette
color rendering on Metal.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:59:29 -06:00