mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-24 08:21:32 +01:00
Bring hb_gpu_draw_encode into line with the rest of the render APIs:
auto-clear on success, and return the computed glyph extents to the
caller via a new out-parameter (nullable).
HB_EXTERN hb_blob_t *
hb_gpu_draw_encode (hb_gpu_draw_t *draw,
hb_glyph_extents_t *extents);
Consumers typically need both the encoded blob and the glyph's
extents to size the quad they'll draw into in the vertex shader;
returning them together removes a redundant trip through the draw
state and lets encode() auto-clear like hb_vector_*_render() and
hb_raster_*_render() do.
Drop hb_gpu_draw_get_extents() from the public API — its only
role was reading extents out of the draw state post-encode, which
the new encode() signature makes redundant. The computation
stays (moved to a static _hb_gpu_draw_get_extents helper) so
encode() can call it before auto-clear wipes the state.
ABI break for anyone who had already wired up against the 14.0.0
hb_gpu_draw_encode signature or hb_gpu_draw_get_extents, but the
library is new/experimental and the two in-tree consumers
(test/api/test-gpu.cc, util/gpu/demo-font.cc, util/hb-gpu-encode-all.cc,
test/fuzzing/hb-gpu-fuzzer.cc) are updated here.
All 240 tests pass.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#include "hb-shape-input.hh"
|
|
|
|
#include <hb-gpu.h>
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
|
|
{
|
|
alloc_state = _fuzzing_alloc_state (data, size);
|
|
|
|
_fuzzing_shape_input_t input;
|
|
if (_fuzzing_prepare_shape_input (data, size, 30, 30, &input) == HB_FUZZING_SHAPE_INPUT_MALFORMED)
|
|
return 0;
|
|
|
|
hb_gpu_draw_t *draw = hb_gpu_draw_create_or_fail ();
|
|
if (!draw)
|
|
return 0;
|
|
|
|
unsigned glyph_count = hb_face_get_glyph_count (input.face);
|
|
unsigned limit = glyph_count > 16 ? 16 : glyph_count;
|
|
|
|
volatile unsigned counter = !glyph_count;
|
|
|
|
for (unsigned gid = 0; gid < limit; gid++)
|
|
{
|
|
hb_gpu_draw_reset (draw);
|
|
hb_gpu_draw_glyph (draw, input.font, gid);
|
|
|
|
hb_glyph_extents_t extents;
|
|
hb_blob_t *blob = hb_gpu_draw_encode (draw, &extents);
|
|
counter += extents.width;
|
|
if (blob)
|
|
{
|
|
unsigned length = 0;
|
|
const char *blob_data = hb_blob_get_data (blob, &length);
|
|
counter += length;
|
|
if (blob_data && length)
|
|
counter += (unsigned char) blob_data[0];
|
|
hb_gpu_draw_recycle_blob (draw, blob);
|
|
}
|
|
}
|
|
|
|
hb_gpu_draw_destroy (draw);
|
|
return counter ? 0 : 0;
|
|
}
|