mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-25 08:51:07 +01:00
[gpu] Share the work budget through the public draw API
hb_gpu_paint reached into the scratch encoder by writing its external_budget pointer directly, so a whole paint session could share one work counter. Drive that sharing through the public draw-budget API instead: seed the scratch encoder with hb_draw_set_budget() before each clip glyph (and before a client-drawn clip path) and read the remainder back with hb_draw_get_budget_remaining(), so the COLR walk aggregates its work without touching encoder internals. The transforming pen now exposes the scratch encoder's own live counter rather than the paint session's. Unlike the rasterizer, the GPU backend never rasterizes -- it emits slug curves for the GPU to fill later -- so all of its work is outline-derived (traversal plus the curves generated from it) and one budget suffices; no separate pixel budget applies here. Remove the now-unused external_budget field and its write-through in hb_gpu_draw_set_budget(). Tests: meson test -C build (275/275 passed); the CFF/COLR gpu-fuzzer regression seed completes in 0.46s. The existing budget test already covers both the identity and transforming-pen clip paths. Assisted-by: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
dfee0d4380
commit
76eccd5f27
4 files changed
+27
-13
No files matched your search
@@ -246,8 +246,6 @@ hb_gpu_draw_set_budget (hb_draw_funcs_t *, void *draw_data,
|
||||
auto *draw = (hb_gpu_draw_t *) draw_data;
|
||||
draw->budget = budget;
|
||||
draw->recharge_budget ();
|
||||
if (draw->external_budget)
|
||||
*draw->external_budget = draw->budget_remaining;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1130,7 +1128,6 @@ hb_gpu_draw_clear (hb_gpu_draw_t *draw)
|
||||
draw->ext_max_x = -HUGE_VAL;
|
||||
draw->ext_max_y = -HUGE_VAL;
|
||||
|
||||
draw->external_budget = nullptr;
|
||||
draw->recharge_budget ();
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -110,11 +110,12 @@ struct hb_gpu_draw_t
|
||||
int x_scale = 0;
|
||||
int y_scale = 0;
|
||||
|
||||
/* Cumulative work budget for the current draw session. Paint-owned
|
||||
* scratch draws borrow the paint session's live counter. */
|
||||
/* Work budget for outline traversal and generated curves. A paint
|
||||
* backend seeds this through the public draw-budget API before drawing
|
||||
* and reads the remainder back afterwards, so a whole paint session
|
||||
* shares one budget without reaching into this object. */
|
||||
int64_t budget = HB_BUDGET_DEFAULT;
|
||||
int64_t budget_remaining = HB_BUDGET_GLYPH;
|
||||
int64_t *external_budget = nullptr;
|
||||
|
||||
void recharge_budget ()
|
||||
{
|
||||
@@ -123,7 +124,7 @@ struct hb_gpu_draw_t
|
||||
}
|
||||
|
||||
int64_t *get_budget_remaining ()
|
||||
{ return external_budget ? external_budget : &budget_remaining; }
|
||||
{ return &budget_remaining; }
|
||||
|
||||
/* Encode scratch (reused across calls) */
|
||||
hb_gpu_encode_scratch_t scratch;
|
||||
|
||||
+16
-3
@@ -136,7 +136,10 @@ hb_gpu_paint_push_clip_path_start (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
}
|
||||
|
||||
hb_gpu_draw_clear (c->scratch_draw);
|
||||
c->scratch_draw->external_budget = &c->budget_remaining;
|
||||
/* Seed the scratch encoder's budget from the session's remainder; it is
|
||||
* read back in push_clip_path_end after the caller has drawn the path. */
|
||||
hb_draw_set_budget (hb_gpu_draw_get_funcs (c->scratch_draw), c->scratch_draw,
|
||||
c->budget_remaining);
|
||||
hb_gpu_draw_set_scale (c->scratch_draw, c->x_scale, c->y_scale);
|
||||
|
||||
c->pending_clip_path_transform = c->cur_transform;
|
||||
@@ -157,6 +160,10 @@ hb_gpu_paint_push_clip_path_end (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
return;
|
||||
c->pending_clip_path = false;
|
||||
|
||||
/* Pull back the outline budget the caller's path draw consumed. */
|
||||
c->budget_remaining = hb_draw_get_budget_remaining (hb_gpu_draw_get_funcs (c->scratch_draw),
|
||||
c->scratch_draw);
|
||||
|
||||
hb_glyph_extents_t ext;
|
||||
hb_blob_t *blob = hb_gpu_draw_encode (c->scratch_draw, &ext);
|
||||
if (unlikely (!blob || !c->sub_blobs.push_or_fail (blob)))
|
||||
@@ -474,7 +481,11 @@ emit_clip_sub_blob (hb_gpu_paint_t *c,
|
||||
}
|
||||
}
|
||||
hb_gpu_draw_clear (c->scratch_draw);
|
||||
c->scratch_draw->external_budget = &c->budget_remaining;
|
||||
/* Seed the scratch encoder's budget from the session's remainder and
|
||||
* read it back after the glyph is drawn, so the whole paint walk shares
|
||||
* one budget through the public draw-budget API. */
|
||||
hb_draw_set_budget (hb_gpu_draw_get_funcs (c->scratch_draw), c->scratch_draw,
|
||||
c->budget_remaining);
|
||||
|
||||
bool ok;
|
||||
if (clip.transform.is_identity ())
|
||||
@@ -498,7 +509,7 @@ emit_clip_sub_blob (hb_gpu_paint_t *c,
|
||||
pen.dfuncs = hb_gpu_draw_get_funcs (c->scratch_draw);
|
||||
pen.data = c->scratch_draw;
|
||||
pen.down_st = HB_DRAW_STATE_DEFAULT;
|
||||
pen.budget_remaining = &c->budget_remaining;
|
||||
pen.budget_remaining = &c->scratch_draw->budget_remaining;
|
||||
ok = hb_font_draw_glyph_or_fail (clip.font, clip.glyph,
|
||||
static_gpu_paint_pen_funcs.get_unconst (),
|
||||
&pen);
|
||||
@@ -506,6 +517,8 @@ emit_clip_sub_blob (hb_gpu_paint_t *c,
|
||||
* hb_font_draw_glyph_or_fail only closes via our pen's state. */
|
||||
pen.dfuncs->close_path (pen.data, pen.down_st);
|
||||
}
|
||||
c->budget_remaining = hb_draw_get_budget_remaining (hb_gpu_draw_get_funcs (c->scratch_draw),
|
||||
c->scratch_draw);
|
||||
if (!ok)
|
||||
return -1; /* Clip glyph has no outline -- skip. */
|
||||
|
||||
|
||||
+6
-3
@@ -273,9 +273,12 @@ struct hb_gpu_paint_t
|
||||
* which matches HB_GPU_PAINT_GROUP_DEPTH in the fragment shader. */
|
||||
unsigned group_depth = 0;
|
||||
|
||||
/* Cumulative work budget for the current paint session; reset by
|
||||
* hb_gpu_paint_clear(). Outline traversal and generated curves
|
||||
* charge the same live counter. */
|
||||
/* Work budget for the current paint session; reset by
|
||||
* hb_gpu_paint_clear(). All the session's work is outline-derived
|
||||
* (outline traversal and the curves generated from it -- the GPU
|
||||
* backend never rasterizes), so a single counter suffices. It is the
|
||||
* public draw/paint budget: seeded into the scratch encoder through the
|
||||
* public draw-budget API before each glyph and read back afterwards. */
|
||||
int64_t budget = HB_BUDGET_DEFAULT;
|
||||
int64_t budget_remaining = HB_BUDGET_GLYPH;
|
||||
|
||||
|
||||
Reference in new issue
Block a user