Commit Graph
14 Commits
Author SHA1 Message Date
Behdad Esfahbod 3fa9ba2473 [api] Add _clear() companions to _reset() across render contexts
Introduce a public _clear() entry point on each render-context type
that discards accumulated output state while preserving user
configuration.  _reset() is redefined as _clear() plus resetting user
configuration to defaults — same observable effect as before, but
now there is one code path for the output-state teardown.

New public API:
  hb_vector_draw_clear()
  hb_vector_paint_clear()
  hb_raster_draw_clear()
  hb_raster_paint_clear()
  hb_gpu_draw_clear()

Contract:
  _clear(): preserves transform, scale factors, precision, flat,
            foreground, palette, custom palette colors.
  _reset(): equivalent to _clear() + resetting all user config.

The render/encode entry points now auto-clear on every exit path, so
the context is ready for the next glyph out of the box:

  hb_vector_draw_render (SVG + PDF) — ends with _clear().
  hb_vector_paint_render (SVG + PDF) — ends with _clear().
  hb_raster_draw_render — wraps body in HB_SCOPE_GUARD (_clear()).
  hb_raster_paint_render — wraps body in HB_SCOPE_GUARD (_clear()).

hb_gpu_draw_encode is intentionally NOT auto-clearing: its
hb_gpu_draw_get_extents() reads computed extents from the draw after
encode, so callers need that state preserved until they explicitly
clear.

Side fix: hb_vector_paint_clear() (and therefore _reset() and the
render paths) now correctly free the PDF backend's heap-allocated
hb_pdf_resources_t that had been leaking through clear_render_state.
hb_vector_paint_destroy() also free it now.  Expose
hb_vector_paint_pdf_free_resources() as HB_INTERNAL from
hb-vector-paint-pdf.cc for that.

All 240 tests still pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 21:27:00 -06:00
Behdad Esfahbod e7c5b839eb [gpu] Store font scale in blob header; auto-MSAA in hb_gpu_render
Add hb_gpu_draw_set_scale() API and store x/y scale in the
glyph blob header (buf[1].b/a).  hb_gpu_draw_glyph() sets it
automatically from the font.

hb_gpu_render() now reads the scale, computes ppem via fwidth,
and automatically blends 4 corner samples at ±1/3 pixel when
ppem < 16 to reduce moiré at small sizes.  Define
HB_GPU_NO_MSAA to disable.

Add hb_gpu_ppem() public shader helper so clients can get
ppem without touching internal functions (e.g. for
hb_gpu_darken).

Remove hb_gpu_render_aaa(), u_upem uniform, and set_upem
plumbing from the demo — no longer needed.

GLSL only for now.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 00:59:39 -06:00
Khaled Hosny da69b6585c 14.0.0 2026-04-01 14:54:05 +02:00
Behdad EsfahbodandClaude Opus 4.6 9ad26d9823 [gpu] Add HLSL shader sources for Direct3D
Port fragment and vertex shaders to HLSL (Shader Model 5.0+).
Uses asuint for bit reinterpretation, StructuredBuffer<int4> for
atlas, and mul() for matrix multiply. Verified with DXC on Linux.

Adds HB_GPU_SHADER_LANG_HLSL to the enum. Reorders enum to:
GLSL, WGSL, MSL, HLSL. Updates doc strings for consistency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 18:15:33 -06:00
Behdad EsfahbodandClaude Opus 4.6 09f6ef66e8 [gpu] Add WGSL shader sources for WebGPU
Port fragment and vertex shaders to WGSL. Key differences from
GLSL/MSL: no preprocessor (constants instead of #define), bitcast
instead of floatBitsToUint, storage buffer pointer parameter for
atlas, and emsPerPixel passed explicitly since fwidth() is only
available in the caller's fragment entry point.

Adds HB_GPU_SHADER_LANG_WGSL to the shader language enum.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 14:22:41 -06:00
Behdad EsfahbodandClaude Opus 4.6 6910b9a3ed [gpu] Add Metal backend for macOS demo
Add MSL shader translations of the Slug GPU text rasterizer, and a
Metal rendering backend for hb-gpu-demo selectable via --metal flag.

Library changes:
- Add HB_GPU_SHADER_LANG_MSL enum value
- Add hb-gpu-vertex.msl and hb-gpu-fragment.msl
- Extend gen-gpu-shader-artifacts.py for MSL

Demo changes:
- Add demo-metal.h/mm with CAMetalLayer rendering
- Add external atlas backend for non-GL paths
- Add demo_buffer_get_vertices for Metal draw path
- Skip GL init when using Metal (GLFW_NO_API)
- Add --metal command-line flag

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 13:36:28 -06:00
Behdad EsfahbodandClaude Opus 4.6 d46f8e3444 [gpu] Rename HB_GPU_SHADER_GLSL_330 to HB_GPU_SHADER_LANG_GLSL
The shader source is compatible with both GLSL 3.30 and
GLSL ES 3.00.  Rename the enum value to reflect this and
match the type name convention.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 00:40:11 -06:00
Behdad EsfahbodandClaude Opus 4.6 0582846c08 [gpu] Simplify shader API: return single string per language
Change hb_gpu_shader_{fragment,vertex}_sources() (array + count)
to hb_gpu_shader_{fragment,vertex}_source() returning a single
const char *.  Each language variant is one complete string.

Simplifies the demo shader compilation and documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 17:10:04 -06:00
Behdad EsfahbodandClaude Opus 4.6 583b13d95c [gpu] Fix stale parameter names in header; add section doc
Three declarations in hb-gpu.h still had *glyph instead of *draw.
Add SECTION doc block in new hb-gpu.cc for gtk-doc.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 22:33:29 -06:00
Behdad EsfahbodandClaude Opus 4.6 83fe2fa4fa [gpu] Fix doc comments: "GPU shape encoder", "GPU rasterization library"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:37:52 -06:00
Behdad EsfahbodandClaude Opus 4.6 2e24eccfd3 [gpu] Use XSince: REPLACEME in doc comments
Per AGENTS.md, new API uses XSince not Since.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:34:51 -06:00
Behdad EsfahbodandClaude Opus 4.6 39811d2933 [gpu] Rename parameter 'glyph' to 'draw'; inline encode_impl
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:20:10 -06:00
Behdad EsfahbodandClaude Opus 4.6 65d357f808 [gpu] Rename hb_gpu_glyph_t to hb_gpu_draw_t
The object is a draw_funcs_t closure, same role as hb_raster_draw_t.
Rename for consistency with the other modules.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 19:09:40 -06:00
Behdad Esfahbod 93aab15340 [gpu] Add new hb-gpu module for GPU glyph encoding
Port the glyphy library into harfbuzz as a new hb-gpu module,
following the hb-raster / hb-vector library pattern.  The module
encodes glyph outlines into compact RGBA16I blobs for GPU rendering
using the Slug algorithm.

Fixes https://github.com/harfbuzz/harfbuzz/issues/5877
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 18:16:19 -06:00