[gpu] Support 3 nested glyph clips per layer

Replace the single-slot pending_clip / pending_clip_glyph /
pending_clip_font / pending_clip_transform fields with a stack of
up to HB_GPU_PAINT_MAX_CLIP_DEPTH (3) clips.  push_clip_glyph
appends; pop_clip pops; depth > 3 sets `unsupported`.

LAYER_SOLID and LAYER_GRADIENT ops grow from 2 to 3 texels:

  texel 0: (op_type, flags, clip1_hi, clip1_lo)
  texel 1: (clip2_hi, clip2_lo, clip3_hi, clip3_lo)
  texel 2: color (SOLID) or grad meta (GRADIENT)

The existing flags slot (i16) gains:
  bit 0   IS_FOREGROUND          (SOLID only -- was already there)
  bit 8   HAS_CLIP2              (new)
  bit 9   HAS_CLIP3              (new)
For GRADIENT the gradient subtype lives in bits 0..7.

Shader: nest the HAS_CLIP2 / HAS_CLIP3 checks (HAS_CLIP3 implies
HAS_CLIP2) so single-clip layers pay only one branch, two-clip
layers pay one extra slug call, three-clip layers pay two extra.
On Noto-COLRv1 the bench is unchanged (~320 fps with the emoji
text the user benches against), within noise of the depth-1
baseline -- the extra branches don't fire on most layers.

Ports across all four shader languages (GLSL, MSL, HLSL, WGSL).

NEWS: limitation entry updated to "up to 3 levels are intersected
exactly; deeper nests set unsupported".

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad Esfahbod committed 2026-04-14 19:25:58 -06:00
1 parent f6cd414c9f
commit 7c7b1756c1
11 files changed
+441 -191

No files matched your search

+2 -2
View File
@@ -24,8 +24,8 @@ Overview of changes leading to NEXT (REPLACEME)
* a paint tree calls back through `image` (PaintImage isn't
representable by the slug+gradient encoder).
Other partial-coverage features:
* Nested glyph clips: only the innermost clip is faithfully
stored; deeper pushes silently override the outer clip.
* Nested glyph clips: up to 3 levels are intersected exactly;
deeper nests set `unsupported`.
* Composite modes OVERLAY / COLOR_BURN / HARD_LIGHT are
approximated as MULTIPLY; COLOR_DODGE / SOFT_LIGHT as SCREEN;
DIFFERENCE / EXCLUSION / HSL_HUE..HSL_LUMINOSITY fall through
+36 -11
View File
@@ -294,47 +294,72 @@ static const char *hb_gpu_paint_fragment_glsl =
"\n"
" if (op_type == 0) /* LAYER_SOLID */\n"
" {\n"
" /* texel 1 holds RGBA as signed Q15. */\n"
" ivec4 ct = hb_gpu_fetch (cursor + 1);\n"
" /* texel 1: (clip2_hi, clip2_lo, 0, 0) -- valid only if HAS_CLIP2.\n"
" * texel 2: RGBA as signed Q15. */\n"
" ivec4 op2 = hb_gpu_fetch (cursor + 1);\n"
" int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
" ivec4 ct = hb_gpu_fetch (cursor + 2);\n"
" vec4 col = ((aux & 1) != 0)\n"
" ? foreground\n"
" : vec4 (ct) / 32767.0;\n"
"\n"
" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + payload));\n"
" if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */\n"
" {\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + clip2_payload));\n"
" if ((aux & 0x200) != 0) /* HAS_CLIP3 */\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + clip3_payload));\n"
" }\n"
" vec4 src = vec4 (col.rgb * col.a, col.a) * cov;\n"
" acc = src + acc * (1.0 - src.a);\n"
"\n"
" cursor += 2;\n"
" cursor += 3;\n"
" }\n"
" else if (op_type == 1) /* LAYER_GRADIENT */\n"
" {\n"
" /* texel 1: (grad_payload_hi, grad_payload_lo, extend, stop_count) */\n"
" /* texel 1: (clip2_hi, clip2_lo, 0, 0) -- valid only if HAS_CLIP2.\n"
" * texel 2: (grad_payload_hi, grad_payload_lo, extend, stop_count) */\n"
" ivec4 op2 = hb_gpu_fetch (cursor + 1);\n"
" int grad_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" int extend = op2.b;\n"
" int stop_count = op2.a;\n"
" int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
" ivec4 op3 = hb_gpu_fetch (cursor + 2);\n"
" int grad_payload = (op3.r << 16) | (op3.g & 0xffff);\n"
" int extend = op3.b;\n"
" int stop_count = op3.a;\n"
" int subtype = aux & 0xff;\n"
"\n"
" vec4 col = vec4 (0.0);\n"
" if (aux == 0) /* linear */\n"
" if (subtype == 0) /* linear */\n"
" col = _hb_gpu_sample_linear (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground);\n"
" else if (aux == 1) /* radial */\n"
" else if (subtype == 1) /* radial */\n"
" col = _hb_gpu_sample_radial (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground);\n"
" else if (aux == 2) /* sweep */\n"
" else if (subtype == 2) /* sweep */\n"
" col = _hb_gpu_sample_sweep (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground);\n"
"\n"
" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + payload));\n"
" if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */\n"
" {\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + clip2_payload));\n"
" if ((aux & 0x200) != 0) /* HAS_CLIP3 */\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + clip3_payload));\n"
" }\n"
" vec4 src = vec4 (col.rgb * col.a, col.a) * cov;\n"
" acc = src + acc * (1.0 - src.a);\n"
"\n"
" cursor += 2;\n"
" cursor += 3;\n"
" }\n"
" else if (op_type == 2) /* PUSH_GROUP */\n"
" {\n"
+35 -9
View File
@@ -242,45 +242,71 @@ static const char *hb_gpu_paint_fragment_hlsl =
"\n"
" if (op_type == 0) /* LAYER_SOLID */\n"
" {\n"
" int4 ct = hb_gpu_fetch (cursor + 1);\n"
" /* texel 1: (clip2_hi, clip2_lo, clip3_hi, clip3_lo) -- valid\n"
" * per HAS_CLIP2 / HAS_CLIP3 flag bits.\n"
" * texel 2: RGBA as signed Q15. */\n"
" int4 op2 = hb_gpu_fetch (cursor + 1);\n"
" int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
" int4 ct = hb_gpu_fetch (cursor + 2);\n"
" float4 col = ((aux & 1) != 0)\n"
" ? foreground\n"
" : (float4) ct / 32767.0;\n"
"\n"
" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" (uint) (base + payload));\n"
" if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */\n"
" {\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" (uint) (base + clip2_payload));\n"
" if ((aux & 0x200) != 0) /* HAS_CLIP3 */\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" (uint) (base + clip3_payload));\n"
" }\n"
" float4 src = float4 (col.rgb * col.a, col.a) * cov;\n"
" acc = src + acc * (1.0 - src.a);\n"
"\n"
" cursor += 2;\n"
" cursor += 3;\n"
" }\n"
" else if (op_type == 1) /* LAYER_GRADIENT */\n"
" {\n"
" int4 op2 = hb_gpu_fetch (cursor + 1);\n"
" int grad_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" int extend = op2.b;\n"
" int stop_count = op2.a;\n"
" int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
" int4 op3 = hb_gpu_fetch (cursor + 2);\n"
" int grad_payload = (op3.r << 16) | (op3.g & 0xffff);\n"
" int extend = op3.b;\n"
" int stop_count = op3.a;\n"
" int subtype = aux & 0xff;\n"
"\n"
" float4 col = float4 (0.0, 0.0, 0.0, 0.0);\n"
" if (aux == 0)\n"
" if (subtype == 0)\n"
" col = _hb_gpu_sample_linear (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground);\n"
" else if (aux == 1)\n"
" else if (subtype == 1)\n"
" col = _hb_gpu_sample_radial (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground);\n"
" else if (aux == 2)\n"
" else if (subtype == 2)\n"
" col = _hb_gpu_sample_sweep (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground);\n"
"\n"
" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" (uint) (base + payload));\n"
" if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */\n"
" {\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" (uint) (base + clip2_payload));\n"
" if ((aux & 0x200) != 0) /* HAS_CLIP3 */\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" (uint) (base + clip3_payload));\n"
" }\n"
" float4 src = float4 (col.rgb * col.a, col.a) * cov;\n"
" acc = src + acc * (1.0 - src.a);\n"
"\n"
" cursor += 2;\n"
" cursor += 3;\n"
" }\n"
" else if (op_type == 2)\n"
" {\n"
+35 -9
View File
@@ -261,37 +261,55 @@ static const char *hb_gpu_paint_fragment_msl =
"\n"
" if (op_type == 0) /* LAYER_SOLID */\n"
" {\n"
" int4 ct = int4 (hb_gpu_atlas[cursor + 1]);\n"
" /* texel 1: (clip2_hi, clip2_lo, clip3_hi, clip3_lo) -- valid\n"
" * per HAS_CLIP2 / HAS_CLIP3 flag bits.\n"
" * texel 2: RGBA as signed Q15. */\n"
" int4 op2 = int4 (hb_gpu_atlas[cursor + 1]);\n"
" int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
" int4 ct = int4 (hb_gpu_atlas[cursor + 2]);\n"
" float4 col = ((aux & 1) != 0)\n"
" ? foreground\n"
" : float4 (ct) / 32767.0;\n"
"\n"
" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + payload), hb_gpu_atlas);\n"
" if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */\n"
" {\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + clip2_payload), hb_gpu_atlas);\n"
" if ((aux & 0x200) != 0) /* HAS_CLIP3 */\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + clip3_payload), hb_gpu_atlas);\n"
" }\n"
" float4 src = float4 (col.rgb * col.a, col.a) * cov;\n"
" acc = src + acc * (1.0 - src.a);\n"
"\n"
" cursor += 2;\n"
" cursor += 3;\n"
" }\n"
" else if (op_type == 1) /* LAYER_GRADIENT */\n"
" {\n"
" int4 op2 = int4 (hb_gpu_atlas[cursor + 1]);\n"
" int grad_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" int extend = op2.b;\n"
" int stop_count = op2.a;\n"
" int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
" int4 op3 = int4 (hb_gpu_atlas[cursor + 2]);\n"
" int grad_payload = (op3.r << 16) | (op3.g & 0xffff);\n"
" int extend = op3.b;\n"
" int stop_count = op3.a;\n"
" int subtype = aux & 0xff;\n"
"\n"
" float4 col = float4 (0.0);\n"
" if (aux == 0)\n"
" if (subtype == 0)\n"
" col = _hb_gpu_sample_linear (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground,\n"
" hb_gpu_atlas);\n"
" else if (aux == 1)\n"
" else if (subtype == 1)\n"
" col = _hb_gpu_sample_radial (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground,\n"
" hb_gpu_atlas);\n"
" else if (aux == 2)\n"
" else if (subtype == 2)\n"
" col = _hb_gpu_sample_sweep (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground,\n"
@@ -299,10 +317,18 @@ static const char *hb_gpu_paint_fragment_msl =
"\n"
" float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + payload), hb_gpu_atlas);\n"
" if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */\n"
" {\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + clip2_payload), hb_gpu_atlas);\n"
" if ((aux & 0x200) != 0) /* HAS_CLIP3 */\n"
" cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" uint (base + clip3_payload), hb_gpu_atlas);\n"
" }\n"
" float4 src = float4 (col.rgb * col.a, col.a) * cov;\n"
" acc = src + acc * (1.0 - src.a);\n"
"\n"
" cursor += 2;\n"
" cursor += 3;\n"
" }\n"
" else if (op_type == 2) /* PUSH_GROUP */\n"
" {\n"
+37 -12
View File
@@ -262,8 +262,13 @@ static const char *hb_gpu_paint_fragment_wgsl =
" let payload = (op.b << 16) | (op.a & 0xffff);\n"
"\n"
" if (op_type == 0) { // LAYER_SOLID\n"
" // texel 1 holds RGBA as signed Q15.\n"
" let ct = hb_gpu_fetch (hb_gpu_atlas, cursor + 1);\n"
" // texel 1: (clip2_hi, clip2_lo, clip3_hi, clip3_lo) -- valid\n"
" // per HAS_CLIP2 / HAS_CLIP3 flag bits.\n"
" // texel 2: RGBA as signed Q15.\n"
" let op2 = hb_gpu_fetch (hb_gpu_atlas, cursor + 1);\n"
" let clip2_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" let clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
" let ct = hb_gpu_fetch (hb_gpu_atlas, cursor + 2);\n"
" var col: vec4f;\n"
" if ((aux & 1) != 0) {\n"
" col = foreground;\n"
@@ -271,42 +276,62 @@ static const char *hb_gpu_paint_fragment_wgsl =
" col = vec4f (ct) / 32767.0;\n"
" }\n"
"\n"
" let cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" var cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" u32 (base + payload), hb_gpu_atlas);\n"
" if ((aux & 0x100) != 0) { // HAS_CLIP2 (HAS_CLIP3 implies it)\n"
" cov = cov * _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" u32 (base + clip2_payload), hb_gpu_atlas);\n"
" if ((aux & 0x200) != 0) { // HAS_CLIP3\n"
" cov = cov * _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" u32 (base + clip3_payload), hb_gpu_atlas);\n"
" }\n"
" }\n"
" let src = vec4f (col.rgb * col.a, col.a) * cov;\n"
" acc = src + acc * (1.0 - src.a);\n"
"\n"
" cursor = cursor + 2;\n"
" cursor = cursor + 3;\n"
" } else if (op_type == 1) { // LAYER_GRADIENT\n"
" let op2 = hb_gpu_fetch (hb_gpu_atlas, cursor + 1);\n"
" let grad_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" let extend = op2.b;\n"
" let stop_count = op2.a;\n"
" let clip2_payload = (op2.r << 16) | (op2.g & 0xffff);\n"
" let clip3_payload = (op2.b << 16) | (op2.a & 0xffff);\n"
" let op3 = hb_gpu_fetch (hb_gpu_atlas, cursor + 2);\n"
" let grad_payload = (op3.r << 16) | (op3.g & 0xffff);\n"
" let extend = op3.b;\n"
" let stop_count = op3.a;\n"
" let subtype = aux & 0xff;\n"
"\n"
" var col = vec4f (0.0);\n"
" if (aux == 0) {\n"
" if (subtype == 0) {\n"
" col = _hb_gpu_sample_linear (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground,\n"
" hb_gpu_atlas);\n"
" } else if (aux == 1) {\n"
" } else if (subtype == 1) {\n"
" col = _hb_gpu_sample_radial (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground,\n"
" hb_gpu_atlas);\n"
" } else if (aux == 2) {\n"
" } else if (subtype == 2) {\n"
" col = _hb_gpu_sample_sweep (renderCoord,\n"
" base + grad_payload,\n"
" stop_count, extend, foreground,\n"
" hb_gpu_atlas);\n"
" }\n"
"\n"
" let cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" var cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" u32 (base + payload), hb_gpu_atlas);\n"
" if ((aux & 0x100) != 0) { // HAS_CLIP2 (HAS_CLIP3 implies it)\n"
" cov = cov * _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" u32 (base + clip2_payload), hb_gpu_atlas);\n"
" if ((aux & 0x200) != 0) { // HAS_CLIP3\n"
" cov = cov * _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,\n"
" u32 (base + clip3_payload), hb_gpu_atlas);\n"
" }\n"
" }\n"
" let src = vec4f (col.rgb * col.a, col.a) * cov;\n"
" acc = src + acc * (1.0 - src.a);\n"
"\n"
" cursor = cursor + 2;\n"
" cursor = cursor + 3;\n"
" } else if (op_type == 2) { // PUSH_GROUP\n"
" if (sp < HB_GPU_PAINT_GROUP_DEPTH) {\n"
" group_stack[sp] = acc;\n"
+36 -11
View File
@@ -293,47 +293,72 @@ vec4 hb_gpu_paint (vec2 renderCoord, uint glyphLoc, vec4 foreground)
if (op_type == 0) /* LAYER_SOLID */
{
/* texel 1 holds RGBA as signed Q15. */
ivec4 ct = hb_gpu_fetch (cursor + 1);
/* texel 1: (clip2_hi, clip2_lo, 0, 0) -- valid only if HAS_CLIP2.
* texel 2: RGBA as signed Q15. */
ivec4 op2 = hb_gpu_fetch (cursor + 1);
int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);
int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
ivec4 ct = hb_gpu_fetch (cursor + 2);
vec4 col = ((aux & 1) != 0)
? foreground
: vec4 (ct) / 32767.0;
float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + payload));
if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */
{
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + clip2_payload));
if ((aux & 0x200) != 0) /* HAS_CLIP3 */
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + clip3_payload));
}
vec4 src = vec4 (col.rgb * col.a, col.a) * cov;
acc = src + acc * (1.0 - src.a);
cursor += 2;
cursor += 3;
}
else if (op_type == 1) /* LAYER_GRADIENT */
{
/* texel 1: (grad_payload_hi, grad_payload_lo, extend, stop_count) */
/* texel 1: (clip2_hi, clip2_lo, 0, 0) -- valid only if HAS_CLIP2.
* texel 2: (grad_payload_hi, grad_payload_lo, extend, stop_count) */
ivec4 op2 = hb_gpu_fetch (cursor + 1);
int grad_payload = (op2.r << 16) | (op2.g & 0xffff);
int extend = op2.b;
int stop_count = op2.a;
int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);
int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
ivec4 op3 = hb_gpu_fetch (cursor + 2);
int grad_payload = (op3.r << 16) | (op3.g & 0xffff);
int extend = op3.b;
int stop_count = op3.a;
int subtype = aux & 0xff;
vec4 col = vec4 (0.0);
if (aux == 0) /* linear */
if (subtype == 0) /* linear */
col = _hb_gpu_sample_linear (renderCoord,
base + grad_payload,
stop_count, extend, foreground);
else if (aux == 1) /* radial */
else if (subtype == 1) /* radial */
col = _hb_gpu_sample_radial (renderCoord,
base + grad_payload,
stop_count, extend, foreground);
else if (aux == 2) /* sweep */
else if (subtype == 2) /* sweep */
col = _hb_gpu_sample_sweep (renderCoord,
base + grad_payload,
stop_count, extend, foreground);
float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + payload));
if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */
{
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + clip2_payload));
if ((aux & 0x200) != 0) /* HAS_CLIP3 */
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + clip3_payload));
}
vec4 src = vec4 (col.rgb * col.a, col.a) * cov;
acc = src + acc * (1.0 - src.a);
cursor += 2;
cursor += 3;
}
else if (op_type == 2) /* PUSH_GROUP */
{
+35 -9
View File
@@ -241,45 +241,71 @@ float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground)
if (op_type == 0) /* LAYER_SOLID */
{
int4 ct = hb_gpu_fetch (cursor + 1);
/* texel 1: (clip2_hi, clip2_lo, clip3_hi, clip3_lo) -- valid
* per HAS_CLIP2 / HAS_CLIP3 flag bits.
* texel 2: RGBA as signed Q15. */
int4 op2 = hb_gpu_fetch (cursor + 1);
int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);
int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
int4 ct = hb_gpu_fetch (cursor + 2);
float4 col = ((aux & 1) != 0)
? foreground
: (float4) ct / 32767.0;
float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
(uint) (base + payload));
if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */
{
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
(uint) (base + clip2_payload));
if ((aux & 0x200) != 0) /* HAS_CLIP3 */
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
(uint) (base + clip3_payload));
}
float4 src = float4 (col.rgb * col.a, col.a) * cov;
acc = src + acc * (1.0 - src.a);
cursor += 2;
cursor += 3;
}
else if (op_type == 1) /* LAYER_GRADIENT */
{
int4 op2 = hb_gpu_fetch (cursor + 1);
int grad_payload = (op2.r << 16) | (op2.g & 0xffff);
int extend = op2.b;
int stop_count = op2.a;
int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);
int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
int4 op3 = hb_gpu_fetch (cursor + 2);
int grad_payload = (op3.r << 16) | (op3.g & 0xffff);
int extend = op3.b;
int stop_count = op3.a;
int subtype = aux & 0xff;
float4 col = float4 (0.0, 0.0, 0.0, 0.0);
if (aux == 0)
if (subtype == 0)
col = _hb_gpu_sample_linear (renderCoord,
base + grad_payload,
stop_count, extend, foreground);
else if (aux == 1)
else if (subtype == 1)
col = _hb_gpu_sample_radial (renderCoord,
base + grad_payload,
stop_count, extend, foreground);
else if (aux == 2)
else if (subtype == 2)
col = _hb_gpu_sample_sweep (renderCoord,
base + grad_payload,
stop_count, extend, foreground);
float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
(uint) (base + payload));
if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */
{
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
(uint) (base + clip2_payload));
if ((aux & 0x200) != 0) /* HAS_CLIP3 */
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
(uint) (base + clip3_payload));
}
float4 src = float4 (col.rgb * col.a, col.a) * cov;
acc = src + acc * (1.0 - src.a);
cursor += 2;
cursor += 3;
}
else if (op_type == 2)
{
+35 -9
View File
@@ -260,37 +260,55 @@ float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground,
if (op_type == 0) /* LAYER_SOLID */
{
int4 ct = int4 (hb_gpu_atlas[cursor + 1]);
/* texel 1: (clip2_hi, clip2_lo, clip3_hi, clip3_lo) -- valid
* per HAS_CLIP2 / HAS_CLIP3 flag bits.
* texel 2: RGBA as signed Q15. */
int4 op2 = int4 (hb_gpu_atlas[cursor + 1]);
int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);
int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
int4 ct = int4 (hb_gpu_atlas[cursor + 2]);
float4 col = ((aux & 1) != 0)
? foreground
: float4 (ct) / 32767.0;
float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + payload), hb_gpu_atlas);
if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */
{
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + clip2_payload), hb_gpu_atlas);
if ((aux & 0x200) != 0) /* HAS_CLIP3 */
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + clip3_payload), hb_gpu_atlas);
}
float4 src = float4 (col.rgb * col.a, col.a) * cov;
acc = src + acc * (1.0 - src.a);
cursor += 2;
cursor += 3;
}
else if (op_type == 1) /* LAYER_GRADIENT */
{
int4 op2 = int4 (hb_gpu_atlas[cursor + 1]);
int grad_payload = (op2.r << 16) | (op2.g & 0xffff);
int extend = op2.b;
int stop_count = op2.a;
int clip2_payload = (op2.r << 16) | (op2.g & 0xffff);
int clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
int4 op3 = int4 (hb_gpu_atlas[cursor + 2]);
int grad_payload = (op3.r << 16) | (op3.g & 0xffff);
int extend = op3.b;
int stop_count = op3.a;
int subtype = aux & 0xff;
float4 col = float4 (0.0);
if (aux == 0)
if (subtype == 0)
col = _hb_gpu_sample_linear (renderCoord,
base + grad_payload,
stop_count, extend, foreground,
hb_gpu_atlas);
else if (aux == 1)
else if (subtype == 1)
col = _hb_gpu_sample_radial (renderCoord,
base + grad_payload,
stop_count, extend, foreground,
hb_gpu_atlas);
else if (aux == 2)
else if (subtype == 2)
col = _hb_gpu_sample_sweep (renderCoord,
base + grad_payload,
stop_count, extend, foreground,
@@ -298,10 +316,18 @@ float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground,
float cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + payload), hb_gpu_atlas);
if ((aux & 0x100) != 0) /* HAS_CLIP2 (HAS_CLIP3 implies it) */
{
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + clip2_payload), hb_gpu_atlas);
if ((aux & 0x200) != 0) /* HAS_CLIP3 */
cov *= _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
uint (base + clip3_payload), hb_gpu_atlas);
}
float4 src = float4 (col.rgb * col.a, col.a) * cov;
acc = src + acc * (1.0 - src.a);
cursor += 2;
cursor += 3;
}
else if (op_type == 2) /* PUSH_GROUP */
{
+37 -12
View File
@@ -261,8 +261,13 @@ fn hb_gpu_paint (renderCoord: vec2f, glyphLoc_: u32, foreground: vec4f,
let payload = (op.b << 16) | (op.a & 0xffff);
if (op_type == 0) { // LAYER_SOLID
// texel 1 holds RGBA as signed Q15.
let ct = hb_gpu_fetch (hb_gpu_atlas, cursor + 1);
// texel 1: (clip2_hi, clip2_lo, clip3_hi, clip3_lo) -- valid
// per HAS_CLIP2 / HAS_CLIP3 flag bits.
// texel 2: RGBA as signed Q15.
let op2 = hb_gpu_fetch (hb_gpu_atlas, cursor + 1);
let clip2_payload = (op2.r << 16) | (op2.g & 0xffff);
let clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
let ct = hb_gpu_fetch (hb_gpu_atlas, cursor + 2);
var col: vec4f;
if ((aux & 1) != 0) {
col = foreground;
@@ -270,42 +275,62 @@ fn hb_gpu_paint (renderCoord: vec2f, glyphLoc_: u32, foreground: vec4f,
col = vec4f (ct) / 32767.0;
}
let cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
var cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
u32 (base + payload), hb_gpu_atlas);
if ((aux & 0x100) != 0) { // HAS_CLIP2 (HAS_CLIP3 implies it)
cov = cov * _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
u32 (base + clip2_payload), hb_gpu_atlas);
if ((aux & 0x200) != 0) { // HAS_CLIP3
cov = cov * _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
u32 (base + clip3_payload), hb_gpu_atlas);
}
}
let src = vec4f (col.rgb * col.a, col.a) * cov;
acc = src + acc * (1.0 - src.a);
cursor = cursor + 2;
cursor = cursor + 3;
} else if (op_type == 1) { // LAYER_GRADIENT
let op2 = hb_gpu_fetch (hb_gpu_atlas, cursor + 1);
let grad_payload = (op2.r << 16) | (op2.g & 0xffff);
let extend = op2.b;
let stop_count = op2.a;
let clip2_payload = (op2.r << 16) | (op2.g & 0xffff);
let clip3_payload = (op2.b << 16) | (op2.a & 0xffff);
let op3 = hb_gpu_fetch (hb_gpu_atlas, cursor + 2);
let grad_payload = (op3.r << 16) | (op3.g & 0xffff);
let extend = op3.b;
let stop_count = op3.a;
let subtype = aux & 0xff;
var col = vec4f (0.0);
if (aux == 0) {
if (subtype == 0) {
col = _hb_gpu_sample_linear (renderCoord,
base + grad_payload,
stop_count, extend, foreground,
hb_gpu_atlas);
} else if (aux == 1) {
} else if (subtype == 1) {
col = _hb_gpu_sample_radial (renderCoord,
base + grad_payload,
stop_count, extend, foreground,
hb_gpu_atlas);
} else if (aux == 2) {
} else if (subtype == 2) {
col = _hb_gpu_sample_sweep (renderCoord,
base + grad_payload,
stop_count, extend, foreground,
hb_gpu_atlas);
}
let cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
var cov = _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
u32 (base + payload), hb_gpu_atlas);
if ((aux & 0x100) != 0) { // HAS_CLIP2 (HAS_CLIP3 implies it)
cov = cov * _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
u32 (base + clip2_payload), hb_gpu_atlas);
if ((aux & 0x200) != 0) { // HAS_CLIP3
cov = cov * _hb_gpu_slug_clipped (renderCoord, pixelsPerEm,
u32 (base + clip3_payload), hb_gpu_atlas);
}
}
let src = vec4f (col.rgb * col.a, col.a) * cov;
acc = src + acc * (1.0 - src.a);
cursor = cursor + 2;
cursor = cursor + 3;
} else if (op_type == 2) { // PUSH_GROUP
if (sp < HB_GPU_PAINT_GROUP_DEPTH) {
group_stack[sp] = acc;
+137 -98
View File
@@ -49,6 +49,13 @@ enum {
* that would render incorrectly. */
#define HB_GPU_PAINT_MAX_OPS 0x7fff /* num_ops is i16 in the blob header */
#define HB_GPU_PAINT_MAX_GROUP_DEPTH 4 /* matches HB_GPU_PAINT_GROUP_DEPTH in fragment shader */
#define HB_GPU_PAINT_MAX_CLIP_DEPTH 3 /* shader can intersect up to 3 clip outlines per layer */
/* Layer-op flag bits (LAYER_SOLID texel 0 .g, LAYER_GRADIENT
* texel 0 .g where bits 0-7 hold the gradient subtype). */
#define HB_GPU_PAINT_FLAG_IS_FOREGROUND 0x0001
#define HB_GPU_PAINT_FLAG_HAS_CLIP2 0x0100
#define HB_GPU_PAINT_FLAG_HAS_CLIP3 0x0200
static hb_bool_t
hb_gpu_paint_custom_palette_color (hb_paint_funcs_t *funcs HB_UNUSED,
@@ -75,12 +82,14 @@ hb_gpu_paint_push_clip_glyph (hb_paint_funcs_t *funcs HB_UNUSED,
{
hb_gpu_paint_t *c = (hb_gpu_paint_t *) paint_data;
/* Nested glyph clips: only depth 1 is faithfully stored; deeper
* pushes overwrite the outer clip. TODO: extend to depth 2. */
c->pending_clip = true;
c->pending_clip_glyph = glyph;
c->pending_clip_font = font;
c->pending_clip_transform = c->cur_transform;
if (unlikely (c->clip_depth >= HB_GPU_PAINT_MAX_CLIP_DEPTH))
{
c->unsupported = true;
c->clip_depth++;
return;
}
c->clip_stack[c->clip_depth] = { glyph, font, c->cur_transform };
c->clip_depth++;
}
static void
@@ -89,7 +98,7 @@ hb_gpu_paint_pop_clip (hb_paint_funcs_t *funcs HB_UNUSED,
void *user_data HB_UNUSED)
{
hb_gpu_paint_t *c = (hb_gpu_paint_t *) paint_data;
c->pending_clip = false;
if (likely (c->clip_depth > 0)) c->clip_depth--;
}
static void
@@ -314,12 +323,13 @@ free_static_gpu_paint_pen_funcs ()
static_gpu_paint_pen_funcs.free_instance ();
}
/* Rasterize the pending clip glyph's outline into a new sub-blob
* and accumulate its extents. Returns the sub_blob index (>= 0)
* on success, or -1 if the outline is empty / the layer should be
/* Rasterize @clip's glyph outline into a new sub-blob and
* accumulate its extents. Returns the sub_blob index (>= 0) on
* success, or -1 if the outline is empty / the layer should be
* skipped. Sets c->unsupported on hard failure. */
static int
emit_clip_sub_blob (hb_gpu_paint_t *c)
emit_clip_sub_blob (hb_gpu_paint_t *c,
const hb_gpu_paint_t::pending_clip_t &clip)
{
if (unlikely (!c->scratch_draw))
{
@@ -333,12 +343,11 @@ emit_clip_sub_blob (hb_gpu_paint_t *c)
hb_gpu_draw_clear (c->scratch_draw);
bool ok;
if (c->pending_clip_transform.is_identity ())
if (clip.transform.is_identity ())
{
/* Fast path: feed the glyph outline straight into the draw
* encoder with no adapter. */
ok = hb_gpu_draw_glyph (c->scratch_draw, c->pending_clip_font,
c->pending_clip_glyph);
ok = hb_gpu_draw_glyph (c->scratch_draw, clip.font, clip.glyph);
}
else
{
@@ -347,16 +356,15 @@ emit_clip_sub_blob (hb_gpu_paint_t *c)
* cur_transform, which may have additional PaintTransform
* wrappers from the paint child underneath. */
int x_scale, y_scale;
hb_font_get_scale (c->pending_clip_font, &x_scale, &y_scale);
hb_font_get_scale (clip.font, &x_scale, &y_scale);
hb_gpu_draw_set_scale (c->scratch_draw, x_scale, y_scale);
hb_gpu_paint_pen_t pen = {};
pen.transform = c->pending_clip_transform;
pen.transform = clip.transform;
pen.dfuncs = hb_gpu_draw_get_funcs ();
pen.data = c->scratch_draw;
pen.down_st = HB_DRAW_STATE_DEFAULT;
ok = hb_font_draw_glyph_or_fail (c->pending_clip_font,
c->pending_clip_glyph,
ok = hb_font_draw_glyph_or_fail (clip.font, clip.glyph,
static_gpu_paint_pen_funcs.get_unconst (),
&pen);
/* Close any trailing open path on the downstream state, since
@@ -389,12 +397,54 @@ emit_clip_sub_blob (hb_gpu_paint_t *c)
return (int) (c->sub_blobs.length - 1);
}
/* Emit a sub-blob for every clip currently on the stack and return
* their indices in @out (set to -1 for unused slots). Returns
* false if any clip's outline is empty (caller should skip the
* layer entirely) or hb_gpu_draw_encode failed. */
static bool
emit_all_clip_sub_blobs (hb_gpu_paint_t *c, int out[HB_GPU_PAINT_MAX_CLIP_DEPTH])
{
for (unsigned i = 0; i < HB_GPU_PAINT_MAX_CLIP_DEPTH; i++)
out[i] = -1;
for (unsigned i = 0; i < c->clip_depth; i++)
{
out[i] = emit_clip_sub_blob (c, c->clip_stack[i]);
if (out[i] < 0)
return false;
}
return true;
}
/* Emit a 3-texel LAYER_GRADIENT op header (excluding the
* gradient-meta texel which the caller fills in). @subtype is
* 0 = linear, 1 = radial, 2 = sweep. */
static int16_t *
emit_gradient_op_header (hb_gpu_paint_t *c, unsigned subtype,
const int clip_idx[HB_GPU_PAINT_MAX_CLIP_DEPTH])
{
if (unlikely (!c->ops.resize (c->ops.length + 12)))
{ c->unsupported = true; return nullptr; }
int16_t *o = &c->ops.arrayZ[c->ops.length - 12];
int16_t flags = (int16_t) subtype;
if (clip_idx[1] >= 0) flags |= HB_GPU_PAINT_FLAG_HAS_CLIP2;
if (clip_idx[2] >= 0) flags |= HB_GPU_PAINT_FLAG_HAS_CLIP3;
o[0] = HB_GPU_PAINT_OP_LAYER_GRADIENT;
o[1] = flags;
o[2] = (int16_t) ((clip_idx[0] >> 16) & 0xffff);
o[3] = (int16_t) (clip_idx[0] & 0xffff);
o[4] = clip_idx[1] >= 0 ? (int16_t) ((clip_idx[1] >> 16) & 0xffff) : 0;
o[5] = clip_idx[1] >= 0 ? (int16_t) (clip_idx[1] & 0xffff) : 0;
o[6] = clip_idx[2] >= 0 ? (int16_t) ((clip_idx[2] >> 16) & 0xffff) : 0;
o[7] = clip_idx[2] >= 0 ? (int16_t) (clip_idx[2] & 0xffff) : 0;
return o + 8; /* texel 2: gradient meta -- caller fills */
}
static void
hb_gpu_paint_emit_solid (hb_gpu_paint_t *c,
hb_bool_t is_foreground,
hb_color_t color)
{
if (unlikely (!c->pending_clip))
if (unlikely (c->clip_depth == 0))
return;
if (unlikely (c->num_ops >= HB_GPU_PAINT_MAX_OPS))
{
@@ -402,28 +452,37 @@ hb_gpu_paint_emit_solid (hb_gpu_paint_t *c,
return;
}
int clip_idx = emit_clip_sub_blob (c);
if (clip_idx < 0)
int clip_idx[HB_GPU_PAINT_MAX_CLIP_DEPTH];
if (!emit_all_clip_sub_blobs (c, clip_idx))
return;
/* Emit LAYER_SOLID op: 2 texels (8 int16s).
* texel 0: op_type, flags, payload_hi, payload_lo
* texel 1: r_q15, g_q15, b_q15, a_q15
* Payload holds the sub_blob index; hb_gpu_paint_encode()
* patches it into a texel offset at serialize time.
/* Emit LAYER_SOLID op: 3 texels (12 int16s).
* texel 0: op_type, flags, clip1_hi, clip1_lo
* texel 1: clip2_hi, clip2_lo, 0, 0 (only meaningful if HAS_CLIP2)
* texel 2: r_q15, g_q15, b_q15, a_q15
* Payloads hold sub_blob indices; hb_gpu_paint_encode() patches
* them into texel offsets at serialize time.
* flags bit 0: use shader foreground uniform instead of the
* baked color (so runtime foreground-color changes still work). */
if (unlikely (!c->ops.resize (c->ops.length + 8)))
* baked color (so runtime foreground-color changes still work).
* flags bit 8: a second clip outline is present in texel 1. */
if (unlikely (!c->ops.resize (c->ops.length + 12)))
{
c->unsupported = true;
return;
}
int16_t *o = &c->ops.arrayZ[c->ops.length - 8];
int16_t *o = &c->ops.arrayZ[c->ops.length - 12];
int16_t flags = (int16_t) (is_foreground ? HB_GPU_PAINT_FLAG_IS_FOREGROUND : 0);
if (clip_idx[1] >= 0) flags |= HB_GPU_PAINT_FLAG_HAS_CLIP2;
if (clip_idx[2] >= 0) flags |= HB_GPU_PAINT_FLAG_HAS_CLIP3;
o[0] = HB_GPU_PAINT_OP_LAYER_SOLID;
o[1] = (int16_t) (is_foreground ? 1 : 0);
o[2] = (int16_t) ((clip_idx >> 16) & 0xffff);
o[3] = (int16_t) (clip_idx & 0xffff);
color_to_q15_rgba (color, o + 4);
o[1] = flags;
o[2] = (int16_t) ((clip_idx[0] >> 16) & 0xffff);
o[3] = (int16_t) (clip_idx[0] & 0xffff);
o[4] = clip_idx[1] >= 0 ? (int16_t) ((clip_idx[1] >> 16) & 0xffff) : 0;
o[5] = clip_idx[1] >= 0 ? (int16_t) (clip_idx[1] & 0xffff) : 0;
o[6] = clip_idx[2] >= 0 ? (int16_t) ((clip_idx[2] >> 16) & 0xffff) : 0;
o[7] = clip_idx[2] >= 0 ? (int16_t) (clip_idx[2] & 0xffff) : 0;
color_to_q15_rgba (color, o + 8);
c->num_ops++;
}
@@ -522,7 +581,7 @@ hb_gpu_paint_emit_linear (hb_gpu_paint_t *c,
float x1, float y1,
float x2, float y2)
{
if (unlikely (!c->pending_clip))
if (unlikely (c->clip_depth == 0))
return;
if (unlikely (c->num_ops >= HB_GPU_PAINT_MAX_OPS))
{
@@ -548,9 +607,9 @@ hb_gpu_paint_emit_linear (hb_gpu_paint_t *c,
hb_paint_extend_t extend = hb_color_line_get_extend (color_line);
/* Emit clip sub-blob first. */
int clip_idx = emit_clip_sub_blob (c);
if (clip_idx < 0) { hb_free (heap_stops); return; }
/* Emit clip sub-blob(s) first. */
int clip_idx[HB_GPU_PAINT_MAX_CLIP_DEPTH];
if (!emit_all_clip_sub_blobs (c, clip_idx)) { hb_free (heap_stops); return; }
/* Build gradient params sub-blob.
* texel 0: (p0_rendered_x, p0_rendered_y, d_canonical_x, d_canonical_y)
@@ -603,21 +662,12 @@ hb_gpu_paint_emit_linear (hb_gpu_paint_t *c,
}
unsigned grad_idx = c->sub_blobs.length - 1;
/* Emit LAYER_GRADIENT op: 2 texels.
* texel 0: (op_type, subtype, clip_payload_hi, clip_payload_lo)
* texel 1: (grad_payload_hi, grad_payload_lo, extend_mode, stop_count)
*/
if (unlikely (!c->ops.resize (c->ops.length + 8)))
{ c->unsupported = true; return; }
int16_t *o = &c->ops.arrayZ[c->ops.length - 8];
o[0] = HB_GPU_PAINT_OP_LAYER_GRADIENT;
o[1] = 0; /* subtype: 0 = linear */
o[2] = (int16_t) ((clip_idx >> 16) & 0xffff);
o[3] = (int16_t) (clip_idx & 0xffff);
o[4] = (int16_t) ((grad_idx >> 16) & 0xffff);
o[5] = (int16_t) (grad_idx & 0xffff);
o[6] = (int16_t) extend;
o[7] = (int16_t) got;
int16_t *meta = emit_gradient_op_header (c, 0 /* linear */, clip_idx);
if (unlikely (!meta)) return;
meta[0] = (int16_t) ((grad_idx >> 16) & 0xffff);
meta[1] = (int16_t) (grad_idx & 0xffff);
meta[2] = (int16_t) extend;
meta[3] = (int16_t) got;
c->num_ops++;
}
@@ -627,7 +677,7 @@ hb_gpu_paint_emit_radial (hb_gpu_paint_t *c,
float x0, float y0, float r0,
float x1, float y1, float r1)
{
if (unlikely (!c->pending_clip))
if (unlikely (c->clip_depth == 0))
return;
if (unlikely (c->num_ops >= HB_GPU_PAINT_MAX_OPS))
{
@@ -652,8 +702,8 @@ hb_gpu_paint_emit_radial (hb_gpu_paint_t *c,
hb_paint_extend_t extend = hb_color_line_get_extend (color_line);
int clip_idx = emit_clip_sub_blob (c);
if (clip_idx < 0) { hb_free (heap_stops); return; }
int clip_idx[HB_GPU_PAINT_MAX_CLIP_DEPTH];
if (!emit_all_clip_sub_blobs (c, clip_idx)) { hb_free (heap_stops); return; }
/* Build gradient params sub-blob.
* texel 0: (c0_rendered_x, c0_rendered_y, d_canonical_x, d_canonical_y)
@@ -709,17 +759,12 @@ hb_gpu_paint_emit_radial (hb_gpu_paint_t *c,
}
unsigned grad_idx = c->sub_blobs.length - 1;
if (unlikely (!c->ops.resize (c->ops.length + 8)))
{ c->unsupported = true; return; }
int16_t *o = &c->ops.arrayZ[c->ops.length - 8];
o[0] = HB_GPU_PAINT_OP_LAYER_GRADIENT;
o[1] = 1; /* subtype: 1 = radial */
o[2] = (int16_t) ((clip_idx >> 16) & 0xffff);
o[3] = (int16_t) (clip_idx & 0xffff);
o[4] = (int16_t) ((grad_idx >> 16) & 0xffff);
o[5] = (int16_t) (grad_idx & 0xffff);
o[6] = (int16_t) extend;
o[7] = (int16_t) got;
int16_t *meta = emit_gradient_op_header (c, 1 /* radial */, clip_idx);
if (unlikely (!meta)) return;
meta[0] = (int16_t) ((grad_idx >> 16) & 0xffff);
meta[1] = (int16_t) (grad_idx & 0xffff);
meta[2] = (int16_t) extend;
meta[3] = (int16_t) got;
c->num_ops++;
}
@@ -764,7 +809,7 @@ hb_gpu_paint_emit_sweep (hb_gpu_paint_t *c,
float cx, float cy,
float start_angle, float end_angle)
{
if (unlikely (!c->pending_clip))
if (unlikely (c->clip_depth == 0))
return;
if (unlikely (c->num_ops >= HB_GPU_PAINT_MAX_OPS))
{
@@ -789,8 +834,8 @@ hb_gpu_paint_emit_sweep (hb_gpu_paint_t *c,
hb_paint_extend_t extend = hb_color_line_get_extend (color_line);
int clip_idx = emit_clip_sub_blob (c);
if (clip_idx < 0) { hb_free (heap_stops); return; }
int clip_idx[HB_GPU_PAINT_MAX_CLIP_DEPTH];
if (!emit_all_clip_sub_blobs (c, clip_idx)) { hb_free (heap_stops); return; }
/* Build gradient params sub-blob.
* texel 0: (center_rendered_x, center_rendered_y,
@@ -848,17 +893,12 @@ hb_gpu_paint_emit_sweep (hb_gpu_paint_t *c,
}
unsigned grad_idx = c->sub_blobs.length - 1;
if (unlikely (!c->ops.resize (c->ops.length + 8)))
{ c->unsupported = true; return; }
int16_t *o = &c->ops.arrayZ[c->ops.length - 8];
o[0] = HB_GPU_PAINT_OP_LAYER_GRADIENT;
o[1] = 2; /* subtype: 2 = sweep */
o[2] = (int16_t) ((clip_idx >> 16) & 0xffff);
o[3] = (int16_t) (clip_idx & 0xffff);
o[4] = (int16_t) ((grad_idx >> 16) & 0xffff);
o[5] = (int16_t) (grad_idx & 0xffff);
o[6] = (int16_t) extend;
o[7] = (int16_t) got;
int16_t *meta = emit_gradient_op_header (c, 2 /* sweep */, clip_idx);
if (unlikely (!meta)) return;
meta[0] = (int16_t) ((grad_idx >> 16) & 0xffff);
meta[1] = (int16_t) (grad_idx & 0xffff);
meta[2] = (int16_t) extend;
meta[3] = (int16_t) got;
c->num_ops++;
}
@@ -1325,25 +1365,24 @@ hb_gpu_paint_encode (hb_gpu_paint_t *paint,
switch (op_type)
{
case HB_GPU_PAINT_OP_LAYER_SOLID:
{
unsigned idx = ((uint16_t) ops_out[i + 2] << 16)
| (uint16_t) ops_out[i + 3];
if (idx < sub_offsets_count)
{
unsigned off = sub_offsets[idx];
ops_out[i + 2] = (int16_t) ((off >> 16) & 0xffff);
ops_out[i + 3] = (int16_t) (off & 0xffff);
}
i += 8; /* 2 texels */
break;
}
case HB_GPU_PAINT_OP_LAYER_GRADIENT:
{
/* Two sub-blob references: clip at [i+2,i+3], gradient
* params at [i+4,i+5]. */
for (unsigned slot = 0; slot < 2; slot++)
int16_t flags = ops_out[i + 1];
/* Sub-blob slots in i16 offsets within the op:
* clip1: [i+2, i+3] -- always present
* clip2: [i+4, i+5] -- only if HAS_CLIP2
* clip3: [i+6, i+7] -- only if HAS_CLIP3
* grad : [i+8, i+9] (LAYER_GRADIENT only) */
unsigned slots[4] = {
2,
(flags & HB_GPU_PAINT_FLAG_HAS_CLIP2) ? 4u : 0u,
(flags & HB_GPU_PAINT_FLAG_HAS_CLIP3) ? 6u : 0u,
op_type == HB_GPU_PAINT_OP_LAYER_GRADIENT ? 8u : 0u
};
for (unsigned k = 0; k < 4; k++)
{
unsigned p = i + 2 + slot * 2;
if (!slots[k]) continue;
unsigned p = i + slots[k];
unsigned idx = ((uint16_t) ops_out[p] << 16)
| (uint16_t) ops_out[p + 1];
if (idx < sub_offsets_count)
@@ -1353,7 +1392,7 @@ hb_gpu_paint_encode (hb_gpu_paint_t *paint,
ops_out[p + 1] = (int16_t) (off & 0xffff);
}
}
i += 8; /* 2 texels */
i += 12; /* 3 texels */
break;
}
case HB_GPU_PAINT_OP_PUSH_GROUP:
@@ -1407,7 +1446,7 @@ hb_gpu_paint_clear (hb_gpu_paint_t *paint)
for (hb_blob_t *b : paint->sub_blobs)
hb_blob_destroy (b);
paint->sub_blobs.resize (0);
paint->pending_clip = false;
paint->clip_depth = 0;
paint->unsupported = false;
paint->cur_transform = {1, 0, 0, 1, 0, 0};
paint->transform_stack.resize (0);
+16 -9
View File
@@ -273,15 +273,22 @@ struct hb_gpu_paint_t
* which matches HB_GPU_PAINT_GROUP_DEPTH in the fragment shader. */
unsigned group_depth = 0;
/* Paint-callback scratch: next color/gradient op consumes these. */
bool pending_clip = false;
hb_codepoint_t pending_clip_glyph = 0;
hb_font_t *pending_clip_font = nullptr; /* borrowed */
/* Transform at the time push_clip_glyph was called. The clip
* outline is defined in this (outer) coord space; a subsequent
* gradient params callback may run under deeper transforms,
* which we use for the gradient but not the clip outline. */
hb_transform_t<float> pending_clip_transform = {1, 0, 0, 1, 0, 0};
/* Stack of pending clips. Each color/gradient op consumes the
* current state of this stack: the layer is rendered where ALL
* stacked clips are opaque (intersection). Capped at depth
* HB_GPU_PAINT_MAX_CLIP_DEPTH; deeper pushes set `unsupported`.
* The transform is the one current at push_clip_glyph time --
* the clip outline is defined in that coord space, a subsequent
* gradient params callback may run under deeper transforms which
* we use for the gradient but not the clip outline. */
struct pending_clip_t
{
hb_codepoint_t glyph;
hb_font_t *font; /* borrowed */
hb_transform_t<float> transform;
};
pending_clip_t clip_stack[3];
unsigned clip_depth = 0;
/* Set when the paint walk emits v1-only callbacks we do not yet
* support. hb_gpu_paint_encode() returns NULL in that case. */