mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 06:51:01 +01:00
* [raster] Clip the edge sweep's column walk to the surface edge_sweep_row() walked every fixed-point pixel column an edge spans, even though columns right of the surface contribute nothing and columns left of it only contribute a cover delta that telescopes into column 0. A near-horizontal edge with extreme coordinates could span ~2^24 columns per row, making sweep cost proportional to coordinate range instead of surface width: the ClusterFuzz testcase took 114s in a plain release build. Fold the left-of-surface portion of the walk into a single column-0 cover update, skip the right-of-surface portion, and enter/exit the per-column loop at the visible window. Jumping the incremental fy accumulator by k*delta_fy is exact, since the increment is constant and the running sums are bounded, so output is bit-identical; verified by comparing 178 hb-raster renders (draw and paint paths, several fonts, sizes, and negative-margin crops that clip edges off-surface) byte-for-byte against the previous code. The testcase now runs in 0.17s. Also add it as a fuzz seed. Fixes https://oss-fuzz.com/testcase-detail/5267980968329216 Assisted-by: Claude Fable 5 <noreply@anthropic.com> * [raster] Keep an unclipped fast path in the edge sweep The window clipping added in the previous commit made every multi-column edge-row pay for the clip setup, measurable as ~1% more instructions rasterizing all glyphs of NotoSansCJKsc/SourceHanSans-VF at 256px with hb-raster-all. Guard it with a two-compare fully-inside-the-surface check and walk such edges with the original unclipped code, which is also the everyday case: auto-sized surfaces always contain their edges. Interleaved perf-stat A/B (5 rounds, all glyphs at 256px): instruction overhead drops to +0.24% (CJK) / +0.9% (AwamiNastaliq, tiny workload); cycles flat to -1.3%, within noise. Output remains bit-identical on the 178-render comparison matrix, and the oss-fuzz 5267980968329216 testcase stays at 0.19s. Assisted-by: Claude Fable 5 <noreply@anthropic.com> * [raster] Charge column spans in the pixel-work estimate hb_raster_draw_get_pixel_work() charged each edge only its scanline span, so a nearly-horizontal edge crossing one pixel row but sweeping the full surface width cost up to `width` cells while being charged 2 units — the paint path's pixel-budget precharge could undercharge the sweep by a factor of the surface width. This is the same blind spot that let the previous commits' column-walk timeout through the paint path's precharge. Charge each edge its column span too, clipped to the surface width the same way the row span is clipped to its height. Since an edge is a straight segment, row span plus clipped column span is a true upper bound on the post-clipping sweep work. Normal outlines are barely affected: flattening yields short segments whose column spans are commensurate with their row spans, far below the 2^26 budget. No rendering change: the 178-render comparison matrix remains bit-identical and the full test suite passes. Assisted-by: Claude Fable 5 <noreply@anthropic.com>