diff --git a/src/hb-gpu-draw.cc b/src/hb-gpu-draw.cc index 246988786..9a998f949 100644 --- a/src/hb-gpu-draw.cc +++ b/src/hb-gpu-draw.cc @@ -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 (); } diff --git a/src/hb-gpu-draw.hh b/src/hb-gpu-draw.hh index b20f26803..f2d717019 100644 --- a/src/hb-gpu-draw.hh +++ b/src/hb-gpu-draw.hh @@ -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; diff --git a/src/hb-gpu-paint.cc b/src/hb-gpu-paint.cc index 78569dd88..eeeec1e55 100644 --- a/src/hb-gpu-paint.cc +++ b/src/hb-gpu-paint.cc @@ -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. */ diff --git a/src/hb-gpu-paint.hh b/src/hb-gpu-paint.hh index 0c05b3066..27148817a 100644 --- a/src/hb-gpu-paint.hh +++ b/src/hb-gpu-paint.hh @@ -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;