mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 06:51:01 +01:00
[raster-paint] Implement arbitrary-path clip
Wire push_clip_path_start / push_clip_path_end into the
raster backend. Factor the existing emitter-based clip
helper in two so both paths share the mask-render +
clip-intersect tail:
* hb_raster_paint_finalize_path_clip does the render,
alpha-buffer allocate, and intersect-with-old-clip
work.
* The emitter-based helper now preps clip_rdr with the
current effective transform, calls emit() to populate
edges, then calls the finalize helper.
* push_clip_path_start preps clip_rdr exactly the same
way and hands the caller the raster-draw funcs +
clip_rdr as draw-data; the caller drives the path in.
_end just runs the finalize pass.
Since clip_rdr is shared across all clip pushes, this
reuses the object's recycled mask-image and edge buffers
without extra allocations per clip.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
afb6a5411e
commit
100c992dc5
1 file changed
+78
-17
+78
-17
@@ -186,25 +186,17 @@ hb_raster_paint_push_empty_clip (hb_raster_paint_t *c, unsigned w, unsigned h)
|
||||
(void) c->clip_stack.push (std::move (new_clip));
|
||||
}
|
||||
|
||||
/* Render whatever edges have been accumulated into @rdr and
|
||||
* push the result as a new clip on the stack, intersecting
|
||||
* with the existing clip. Used by the emitter-based clip
|
||||
* helpers (push_clip_glyph) and by push_clip_path_end once
|
||||
* the caller has drawn the path into @rdr. */
|
||||
static void
|
||||
hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c,
|
||||
hb_raster_paint_clip_mask_emit_t emit,
|
||||
void *emit_data)
|
||||
hb_raster_paint_finalize_path_clip (hb_raster_paint_t *c,
|
||||
hb_raster_draw_t *rdr,
|
||||
hb_raster_image_t *surf,
|
||||
unsigned w, unsigned h)
|
||||
{
|
||||
ensure_initialized (c);
|
||||
|
||||
hb_raster_image_t *surf = c->current_surface ();
|
||||
if (unlikely (!surf)) return;
|
||||
|
||||
unsigned w = surf->extents.width;
|
||||
unsigned h = surf->extents.height;
|
||||
|
||||
hb_raster_clip_t new_clip = c->acquire_clip (w, h);
|
||||
|
||||
hb_raster_draw_t *rdr = c->clip_rdr;
|
||||
hb_transform_t<> t = c->current_effective_transform ();
|
||||
hb_raster_draw_set_transform (rdr, t.xx, t.yx, t.xy, t.yy, t.x0, t.y0);
|
||||
emit (rdr, emit_data);
|
||||
hb_raster_image_t *mask_img = hb_raster_draw_render (rdr);
|
||||
|
||||
if (unlikely (!mask_img))
|
||||
@@ -213,6 +205,8 @@ hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c,
|
||||
return;
|
||||
}
|
||||
|
||||
hb_raster_clip_t new_clip = c->acquire_clip (w, h);
|
||||
|
||||
/* Allocate alpha buffer and intersect with previous clip */
|
||||
size_t clip_size = (size_t) new_clip.stride * h;
|
||||
if (unlikely (clip_size > HB_RASTER_MAX_BUFFER_SIZE ||
|
||||
@@ -326,6 +320,27 @@ hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c,
|
||||
hb_raster_paint_push_empty_clip (c, w, h);
|
||||
}
|
||||
|
||||
static void
|
||||
hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c,
|
||||
hb_raster_paint_clip_mask_emit_t emit,
|
||||
void *emit_data)
|
||||
{
|
||||
ensure_initialized (c);
|
||||
|
||||
hb_raster_image_t *surf = c->current_surface ();
|
||||
if (unlikely (!surf)) return;
|
||||
|
||||
unsigned w = surf->extents.width;
|
||||
unsigned h = surf->extents.height;
|
||||
|
||||
hb_raster_draw_t *rdr = c->clip_rdr;
|
||||
hb_transform_t<> t = c->current_effective_transform ();
|
||||
hb_raster_draw_set_transform (rdr, t.xx, t.yx, t.xy, t.yy, t.x0, t.y0);
|
||||
emit (rdr, emit_data);
|
||||
|
||||
hb_raster_paint_finalize_path_clip (c, rdr, surf, w, h);
|
||||
}
|
||||
|
||||
struct hb_raster_paint_glyph_clip_data_t
|
||||
{
|
||||
hb_codepoint_t glyph;
|
||||
@@ -583,6 +598,50 @@ hb_raster_paint_push_clip_rectangle (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
hb_raster_paint_push_empty_clip (c, surf->extents.width, surf->extents.height);
|
||||
}
|
||||
|
||||
static hb_draw_funcs_t *
|
||||
hb_raster_paint_push_clip_path_start (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
void *paint_data,
|
||||
void **draw_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data;
|
||||
|
||||
ensure_initialized (c);
|
||||
|
||||
/* Prime clip_rdr with the current effective transform; the
|
||||
* caller then drives hb_draw_*() into it, and _end renders
|
||||
* the accumulated edges into a mask and intersects with the
|
||||
* current clip. */
|
||||
if (unlikely (!c->surface_stack.length || !c->clip_rdr))
|
||||
{
|
||||
*draw_data = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
hb_raster_draw_t *rdr = c->clip_rdr;
|
||||
hb_transform_t<> t = c->current_effective_transform ();
|
||||
hb_raster_draw_set_transform (rdr, t.xx, t.yx, t.xy, t.yy, t.x0, t.y0);
|
||||
|
||||
*draw_data = rdr;
|
||||
return hb_raster_draw_get_funcs ();
|
||||
}
|
||||
|
||||
static void
|
||||
hb_raster_paint_push_clip_path_end (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
void *paint_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data;
|
||||
|
||||
hb_raster_image_t *surf = c->current_surface ();
|
||||
if (unlikely (!surf || !c->clip_rdr)) return;
|
||||
|
||||
unsigned w = surf->extents.width;
|
||||
unsigned h = surf->extents.height;
|
||||
|
||||
hb_raster_paint_finalize_path_clip (c, c->clip_rdr, surf, w, h);
|
||||
}
|
||||
|
||||
static void
|
||||
hb_raster_paint_pop_clip (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||
void *paint_data,
|
||||
@@ -1626,6 +1685,8 @@ static struct hb_raster_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t
|
||||
hb_paint_funcs_set_color_glyph_func (funcs, hb_raster_paint_color_glyph, nullptr, nullptr);
|
||||
hb_paint_funcs_set_push_clip_glyph_func (funcs, hb_raster_paint_push_clip_glyph, nullptr, nullptr);
|
||||
hb_paint_funcs_set_push_clip_rectangle_func (funcs, hb_raster_paint_push_clip_rectangle, nullptr, nullptr);
|
||||
hb_paint_funcs_set_push_clip_path_start_func (funcs, hb_raster_paint_push_clip_path_start, nullptr, nullptr);
|
||||
hb_paint_funcs_set_push_clip_path_end_func (funcs, hb_raster_paint_push_clip_path_end, nullptr, nullptr);
|
||||
hb_paint_funcs_set_pop_clip_func (funcs, hb_raster_paint_pop_clip, nullptr, nullptr);
|
||||
hb_paint_funcs_set_push_group_func (funcs, hb_raster_paint_push_group, nullptr, nullptr);
|
||||
hb_paint_funcs_set_pop_group_func (funcs, hb_raster_paint_pop_group, nullptr, nullptr);
|
||||
|
||||
Reference in new issue
Block a user