mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 22:41:10 +01:00
[gpu] hb_gpu_paint: encode radial gradients as LAYER_GRADIENT
Same shape as linear: emit LAYER_GRADIENT with subtype=1 and a gradient-params sub-blob. Radial just uses two param texels (c0:x,y,r0 and c1:x,y,r1) before the stops instead of one. Shader side: add _hb_gpu_sample_radial in all four languages. Solves the COLRv1 two-circle radial quadratic |P - C0 - t*(C1-C0)|^2 = (r0 + t*(r1-r0))^2 for t, picking the larger root when the interpolated radius stays non-negative, falling through to the smaller root otherwise, and degenerating to a linear solve when the quadratic coefficient is near zero. Same matching of hb_raster_paint's radial formulation. Also extracted the color-stop walk (formerly inlined in _hb_gpu_sample_linear) into _hb_gpu_eval_stops so both subtypes share it; the per-subtype stops_base differs by one texel. Sweep still uses the first-stop solid placeholder. Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
6cf5e1a858
commit
5ce5be6bd2
9 files changed
+586
-115
No files matched your search
@@ -58,22 +58,10 @@ static const char *hb_gpu_paint_fragment_glsl =
|
||||
" return clamp (t, 0.0, 1.0); /* PAD (default) */\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"/* Sample a linear gradient whose param blob starts at @grad_base:\n"
|
||||
" * texel 0: (x0, y0, x1, y1) in font units (i16)\n"
|
||||
" * texels 1..: stops (2 texels each) */\n"
|
||||
"vec4 _hb_gpu_sample_linear (vec2 renderCoord, int grad_base,\n"
|
||||
" int stop_count, int extend, vec4 foreground)\n"
|
||||
"/* Walk stops starting at @stops_base and return the sampled color\n"
|
||||
" * at @t. Same logic reused by all gradient subtypes. */\n"
|
||||
"vec4 _hb_gpu_eval_stops (int stops_base, int stop_count, float t, vec4 foreground)\n"
|
||||
"{\n"
|
||||
" ivec4 axis = hb_gpu_fetch (grad_base);\n"
|
||||
" vec2 p0 = vec2 (float (axis.r), float (axis.g));\n"
|
||||
" vec2 p1 = vec2 (float (axis.b), float (axis.a));\n"
|
||||
" vec2 d = p1 - p0;\n"
|
||||
" float denom = dot (d, d);\n"
|
||||
" if (denom < 1e-6) return vec4 (0.0);\n"
|
||||
" float t = dot (renderCoord - p0, d) / denom;\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
"\n"
|
||||
" int stops_base = grad_base + 1;\n"
|
||||
" float off_prev;\n"
|
||||
" vec4 col_prev = _hb_gpu_stop_color (stops_base, 0, foreground, off_prev);\n"
|
||||
" if (t <= off_prev)\n"
|
||||
@@ -94,6 +82,70 @@ static const char *hb_gpu_paint_fragment_glsl =
|
||||
" return col_prev;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"/* Sample a linear gradient whose param blob starts at @grad_base:\n"
|
||||
" * texel 0: (x0, y0, x1, y1) in font units (i16)\n"
|
||||
" * texels 1..: stops (2 texels each) */\n"
|
||||
"vec4 _hb_gpu_sample_linear (vec2 renderCoord, int grad_base,\n"
|
||||
" int stop_count, int extend, vec4 foreground)\n"
|
||||
"{\n"
|
||||
" ivec4 axis = hb_gpu_fetch (grad_base);\n"
|
||||
" vec2 p0 = vec2 (float (axis.r), float (axis.g));\n"
|
||||
" vec2 p1 = vec2 (float (axis.b), float (axis.a));\n"
|
||||
" vec2 d = p1 - p0;\n"
|
||||
" float denom = dot (d, d);\n"
|
||||
" if (denom < 1e-6) return vec4 (0.0);\n"
|
||||
" float t = dot (renderCoord - p0, d) / denom;\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
"\n"
|
||||
" return _hb_gpu_eval_stops (grad_base + 1, stop_count, t, foreground);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"/* Sample a two-circle radial gradient whose param blob starts at\n"
|
||||
" * @grad_base:\n"
|
||||
" * texel 0: (x0, y0, r0, _)\n"
|
||||
" * texel 1: (x1, y1, r1, _)\n"
|
||||
" * texels 2..: stops (2 texels each)\n"
|
||||
" * Solves |P - C0 - t*(C1-C0)|^2 = (r0 + t*(r1-r0))^2 for t. */\n"
|
||||
"vec4 _hb_gpu_sample_radial (vec2 renderCoord, int grad_base,\n"
|
||||
" int stop_count, int extend, vec4 foreground)\n"
|
||||
"{\n"
|
||||
" ivec4 c0_ = hb_gpu_fetch (grad_base);\n"
|
||||
" ivec4 c1_ = hb_gpu_fetch (grad_base + 1);\n"
|
||||
" vec2 c0 = vec2 (float (c0_.r), float (c0_.g));\n"
|
||||
" float r0 = float (c0_.b);\n"
|
||||
" vec2 c1 = vec2 (float (c1_.r), float (c1_.g));\n"
|
||||
" float r1 = float (c1_.b);\n"
|
||||
"\n"
|
||||
" vec2 cd = c1 - c0;\n"
|
||||
" float dr = r1 - r0;\n"
|
||||
" vec2 p = renderCoord - c0;\n"
|
||||
"\n"
|
||||
" float A = dot (cd, cd) - dr * dr;\n"
|
||||
" float B = -2.0 * (dot (p, cd) + r0 * dr);\n"
|
||||
" float C = dot (p, p) - r0 * r0;\n"
|
||||
"\n"
|
||||
" float t;\n"
|
||||
" if (abs (A) > 1e-6)\n"
|
||||
" {\n"
|
||||
" float disc = B * B - 4.0 * A * C;\n"
|
||||
" if (disc < 0.0) return vec4 (0.0);\n"
|
||||
" float sq = sqrt (disc);\n"
|
||||
" /* Prefer the larger root; fall back to the smaller if the\n"
|
||||
" * larger gives a negative interpolated radius. */\n"
|
||||
" float t1 = (-B + sq) / (2.0 * A);\n"
|
||||
" float t2 = (-B - sq) / (2.0 * A);\n"
|
||||
" t = (r0 + t1 * dr >= 0.0) ? t1 : t2;\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" if (abs (B) < 1e-6) return vec4 (0.0);\n"
|
||||
" t = -C / B;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
" return _hb_gpu_eval_stops (grad_base + 2, stop_count, t, foreground);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"/* Walks the paint blob's flat op stream and returns a\n"
|
||||
" * premultiplied RGBA coverage value for the current fragment.\n"
|
||||
" *\n"
|
||||
@@ -147,11 +199,15 @@ static const char *hb_gpu_paint_fragment_glsl =
|
||||
" int stop_count = op2.a;\n"
|
||||
"\n"
|
||||
" vec4 col = vec4 (0.0);\n"
|
||||
" if (aux == 0) /* linear */\n"
|
||||
" if (aux == 0) /* linear */\n"
|
||||
" col = _hb_gpu_sample_linear (renderCoord,\n"
|
||||
" base + grad_payload,\n"
|
||||
" stop_count, extend, foreground);\n"
|
||||
" /* Radial / sweep fall through as transparent for now. */\n"
|
||||
" else if (aux == 1) /* radial */\n"
|
||||
" col = _hb_gpu_sample_radial (renderCoord,\n"
|
||||
" base + grad_payload,\n"
|
||||
" stop_count, extend, foreground);\n"
|
||||
" /* Sweep falls through as transparent for now. */\n"
|
||||
"\n"
|
||||
" float cov = _hb_gpu_draw_impl (renderCoord, pixelsPerEm,\n"
|
||||
" uint (base + payload));\n"
|
||||
|
||||
@@ -53,19 +53,8 @@ static const char *hb_gpu_paint_fragment_hlsl =
|
||||
" return clamp (t, 0.0, 1.0);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float4 _hb_gpu_sample_linear (float2 renderCoord, int grad_base,\n"
|
||||
" int stop_count, int extend, float4 foreground)\n"
|
||||
"float4 _hb_gpu_eval_stops (int stops_base, int stop_count, float t, float4 foreground)\n"
|
||||
"{\n"
|
||||
" int4 axis = hb_gpu_fetch (grad_base);\n"
|
||||
" float2 p0 = float2 ((float) axis.r, (float) axis.g);\n"
|
||||
" float2 p1 = float2 ((float) axis.b, (float) axis.a);\n"
|
||||
" float2 d = p1 - p0;\n"
|
||||
" float denom = dot (d, d);\n"
|
||||
" if (denom < 1e-6) return float4 (0.0, 0.0, 0.0, 0.0);\n"
|
||||
" float t = dot (renderCoord - p0, d) / denom;\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
"\n"
|
||||
" int stops_base = grad_base + 1;\n"
|
||||
" float off_prev;\n"
|
||||
" float4 col_prev = _hb_gpu_stop_color (stops_base, 0, foreground, off_prev);\n"
|
||||
" if (t <= off_prev) return col_prev;\n"
|
||||
@@ -85,6 +74,57 @@ static const char *hb_gpu_paint_fragment_hlsl =
|
||||
" return col_prev;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float4 _hb_gpu_sample_linear (float2 renderCoord, int grad_base,\n"
|
||||
" int stop_count, int extend, float4 foreground)\n"
|
||||
"{\n"
|
||||
" int4 axis = hb_gpu_fetch (grad_base);\n"
|
||||
" float2 p0 = float2 ((float) axis.r, (float) axis.g);\n"
|
||||
" float2 p1 = float2 ((float) axis.b, (float) axis.a);\n"
|
||||
" float2 d = p1 - p0;\n"
|
||||
" float denom = dot (d, d);\n"
|
||||
" if (denom < 1e-6) return float4 (0.0, 0.0, 0.0, 0.0);\n"
|
||||
" float t = dot (renderCoord - p0, d) / denom;\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
" return _hb_gpu_eval_stops (grad_base + 1, stop_count, t, foreground);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float4 _hb_gpu_sample_radial (float2 renderCoord, int grad_base,\n"
|
||||
" int stop_count, int extend, float4 foreground)\n"
|
||||
"{\n"
|
||||
" int4 c0_ = hb_gpu_fetch (grad_base);\n"
|
||||
" int4 c1_ = hb_gpu_fetch (grad_base + 1);\n"
|
||||
" float2 c0 = float2 ((float) c0_.r, (float) c0_.g);\n"
|
||||
" float r0 = (float) c0_.b;\n"
|
||||
" float2 c1 = float2 ((float) c1_.r, (float) c1_.g);\n"
|
||||
" float r1 = (float) c1_.b;\n"
|
||||
"\n"
|
||||
" float2 cd = c1 - c0;\n"
|
||||
" float dr = r1 - r0;\n"
|
||||
" float2 p = renderCoord - c0;\n"
|
||||
"\n"
|
||||
" float A = dot (cd, cd) - dr * dr;\n"
|
||||
" float B = -2.0 * (dot (p, cd) + r0 * dr);\n"
|
||||
" float C = dot (p, p) - r0 * r0;\n"
|
||||
"\n"
|
||||
" float t;\n"
|
||||
" if (abs (A) > 1e-6)\n"
|
||||
" {\n"
|
||||
" float disc = B * B - 4.0 * A * C;\n"
|
||||
" if (disc < 0.0) return float4 (0.0, 0.0, 0.0, 0.0);\n"
|
||||
" float sq = sqrt (disc);\n"
|
||||
" float t1 = (-B + sq) / (2.0 * A);\n"
|
||||
" float t2 = (-B - sq) / (2.0 * A);\n"
|
||||
" t = (r0 + t1 * dr >= 0.0) ? t1 : t2;\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" if (abs (B) < 1e-6) return float4 (0.0, 0.0, 0.0, 0.0);\n"
|
||||
" t = -C / B;\n"
|
||||
" }\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
" return _hb_gpu_eval_stops (grad_base + 2, stop_count, t, foreground);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground)\n"
|
||||
"{\n"
|
||||
" /* fwidth once, at uniform control flow. */\n"
|
||||
@@ -131,6 +171,10 @@ static const char *hb_gpu_paint_fragment_hlsl =
|
||||
" col = _hb_gpu_sample_linear (renderCoord,\n"
|
||||
" base + grad_payload,\n"
|
||||
" stop_count, extend, foreground);\n"
|
||||
" else if (aux == 1)\n"
|
||||
" col = _hb_gpu_sample_radial (renderCoord,\n"
|
||||
" base + grad_payload,\n"
|
||||
" stop_count, extend, foreground);\n"
|
||||
"\n"
|
||||
" float cov = _hb_gpu_draw_impl (renderCoord, pixelsPerEm,\n"
|
||||
" (uint) (base + payload));\n"
|
||||
|
||||
@@ -55,21 +55,10 @@ static const char *hb_gpu_paint_fragment_msl =
|
||||
" return clamp (t, 0.0, 1.0);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"static float4 _hb_gpu_sample_linear (float2 renderCoord, int grad_base,\n"
|
||||
" int stop_count, int extend,\n"
|
||||
" float4 foreground,\n"
|
||||
" device const short4* hb_gpu_atlas)\n"
|
||||
"static float4 _hb_gpu_eval_stops (device const short4* hb_gpu_atlas,\n"
|
||||
" int stops_base, int stop_count,\n"
|
||||
" float t, float4 foreground)\n"
|
||||
"{\n"
|
||||
" int4 axis = int4 (hb_gpu_atlas[grad_base]);\n"
|
||||
" float2 p0 = float2 (float (axis.r), float (axis.g));\n"
|
||||
" float2 p1 = float2 (float (axis.b), float (axis.a));\n"
|
||||
" float2 d = p1 - p0;\n"
|
||||
" float denom = dot (d, d);\n"
|
||||
" if (denom < 1e-6) return float4 (0.0);\n"
|
||||
" float t = dot (renderCoord - p0, d) / denom;\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
"\n"
|
||||
" int stops_base = grad_base + 1;\n"
|
||||
" float off_prev;\n"
|
||||
" float4 col_prev = _hb_gpu_stop_color (hb_gpu_atlas, stops_base, 0, foreground, off_prev);\n"
|
||||
" if (t <= off_prev) return col_prev;\n"
|
||||
@@ -89,6 +78,61 @@ static const char *hb_gpu_paint_fragment_msl =
|
||||
" return col_prev;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"static float4 _hb_gpu_sample_linear (float2 renderCoord, int grad_base,\n"
|
||||
" int stop_count, int extend,\n"
|
||||
" float4 foreground,\n"
|
||||
" device const short4* hb_gpu_atlas)\n"
|
||||
"{\n"
|
||||
" int4 axis = int4 (hb_gpu_atlas[grad_base]);\n"
|
||||
" float2 p0 = float2 (float (axis.r), float (axis.g));\n"
|
||||
" float2 p1 = float2 (float (axis.b), float (axis.a));\n"
|
||||
" float2 d = p1 - p0;\n"
|
||||
" float denom = dot (d, d);\n"
|
||||
" if (denom < 1e-6) return float4 (0.0);\n"
|
||||
" float t = dot (renderCoord - p0, d) / denom;\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
" return _hb_gpu_eval_stops (hb_gpu_atlas, grad_base + 1, stop_count, t, foreground);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"static float4 _hb_gpu_sample_radial (float2 renderCoord, int grad_base,\n"
|
||||
" int stop_count, int extend,\n"
|
||||
" float4 foreground,\n"
|
||||
" device const short4* hb_gpu_atlas)\n"
|
||||
"{\n"
|
||||
" int4 c0_ = int4 (hb_gpu_atlas[grad_base]);\n"
|
||||
" int4 c1_ = int4 (hb_gpu_atlas[grad_base + 1]);\n"
|
||||
" float2 c0 = float2 (float (c0_.r), float (c0_.g));\n"
|
||||
" float r0 = float (c0_.b);\n"
|
||||
" float2 c1 = float2 (float (c1_.r), float (c1_.g));\n"
|
||||
" float r1 = float (c1_.b);\n"
|
||||
"\n"
|
||||
" float2 cd = c1 - c0;\n"
|
||||
" float dr = r1 - r0;\n"
|
||||
" float2 p = renderCoord - c0;\n"
|
||||
"\n"
|
||||
" float A = dot (cd, cd) - dr * dr;\n"
|
||||
" float B = -2.0 * (dot (p, cd) + r0 * dr);\n"
|
||||
" float C = dot (p, p) - r0 * r0;\n"
|
||||
"\n"
|
||||
" float t;\n"
|
||||
" if (abs (A) > 1e-6)\n"
|
||||
" {\n"
|
||||
" float disc = B * B - 4.0 * A * C;\n"
|
||||
" if (disc < 0.0) return float4 (0.0);\n"
|
||||
" float sq = sqrt (disc);\n"
|
||||
" float t1 = (-B + sq) / (2.0 * A);\n"
|
||||
" float t2 = (-B - sq) / (2.0 * A);\n"
|
||||
" t = (r0 + t1 * dr >= 0.0) ? t1 : t2;\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" if (abs (B) < 1e-6) return float4 (0.0);\n"
|
||||
" t = -C / B;\n"
|
||||
" }\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
" return _hb_gpu_eval_stops (hb_gpu_atlas, grad_base + 2, stop_count, t, foreground);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground,\n"
|
||||
" device const short4* hb_gpu_atlas)\n"
|
||||
"{\n"
|
||||
@@ -137,6 +181,11 @@ static const char *hb_gpu_paint_fragment_msl =
|
||||
" base + grad_payload,\n"
|
||||
" stop_count, extend, foreground,\n"
|
||||
" hb_gpu_atlas);\n"
|
||||
" else if (aux == 1)\n"
|
||||
" col = _hb_gpu_sample_radial (renderCoord,\n"
|
||||
" base + grad_payload,\n"
|
||||
" stop_count, extend, foreground,\n"
|
||||
" hb_gpu_atlas);\n"
|
||||
"\n"
|
||||
" float cov = _hb_gpu_draw_impl (renderCoord, pixelsPerEm,\n"
|
||||
" uint (base + payload), hb_gpu_atlas);\n"
|
||||
|
||||
@@ -59,20 +59,10 @@ static const char *hb_gpu_paint_fragment_wgsl =
|
||||
" return clamp (t, 0.0, 1.0);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"fn _hb_gpu_sample_linear (renderCoord: vec2f, grad_base: i32,\n"
|
||||
" stop_count: i32, extend: i32, foreground: vec4f,\n"
|
||||
" hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>) -> vec4f\n"
|
||||
"fn _hb_gpu_eval_stops (hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>,\n"
|
||||
" stops_base: i32, stop_count: i32,\n"
|
||||
" t: f32, foreground: vec4f) -> vec4f\n"
|
||||
"{\n"
|
||||
" let axis = hb_gpu_fetch (hb_gpu_atlas, grad_base);\n"
|
||||
" let p0 = vec2f (f32 (axis.r), f32 (axis.g));\n"
|
||||
" let p1 = vec2f (f32 (axis.b), f32 (axis.a));\n"
|
||||
" let d = p1 - p0;\n"
|
||||
" let denom = dot (d, d);\n"
|
||||
" if (denom < 1e-6) { return vec4f (0.0); }\n"
|
||||
" var t = dot (renderCoord - p0, d) / denom;\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
"\n"
|
||||
" let stops_base = grad_base + 1;\n"
|
||||
" var off_prev: f32;\n"
|
||||
" var col_prev = _hb_gpu_stop_color (hb_gpu_atlas, stops_base, 0, foreground, &off_prev);\n"
|
||||
" if (t <= off_prev) { return col_prev; }\n"
|
||||
@@ -93,6 +83,59 @@ static const char *hb_gpu_paint_fragment_wgsl =
|
||||
" return col_prev;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"fn _hb_gpu_sample_linear (renderCoord: vec2f, grad_base: i32,\n"
|
||||
" stop_count: i32, extend: i32, foreground: vec4f,\n"
|
||||
" hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>) -> vec4f\n"
|
||||
"{\n"
|
||||
" let axis = hb_gpu_fetch (hb_gpu_atlas, grad_base);\n"
|
||||
" let p0 = vec2f (f32 (axis.r), f32 (axis.g));\n"
|
||||
" let p1 = vec2f (f32 (axis.b), f32 (axis.a));\n"
|
||||
" let d = p1 - p0;\n"
|
||||
" let denom = dot (d, d);\n"
|
||||
" if (denom < 1e-6) { return vec4f (0.0); }\n"
|
||||
" var t = dot (renderCoord - p0, d) / denom;\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
" return _hb_gpu_eval_stops (hb_gpu_atlas, grad_base + 1, stop_count, t, foreground);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"fn _hb_gpu_sample_radial (renderCoord: vec2f, grad_base: i32,\n"
|
||||
" stop_count: i32, extend: i32, foreground: vec4f,\n"
|
||||
" hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>) -> vec4f\n"
|
||||
"{\n"
|
||||
" let c0_ = hb_gpu_fetch (hb_gpu_atlas, grad_base);\n"
|
||||
" let c1_ = hb_gpu_fetch (hb_gpu_atlas, grad_base + 1);\n"
|
||||
" let c0 = vec2f (f32 (c0_.r), f32 (c0_.g));\n"
|
||||
" let r0 = f32 (c0_.b);\n"
|
||||
" let c1 = vec2f (f32 (c1_.r), f32 (c1_.g));\n"
|
||||
" let r1 = f32 (c1_.b);\n"
|
||||
"\n"
|
||||
" let cd = c1 - c0;\n"
|
||||
" let dr = r1 - r0;\n"
|
||||
" let p = renderCoord - c0;\n"
|
||||
"\n"
|
||||
" let A = dot (cd, cd) - dr * dr;\n"
|
||||
" let B = -2.0 * (dot (p, cd) + r0 * dr);\n"
|
||||
" let C = dot (p, p) - r0 * r0;\n"
|
||||
"\n"
|
||||
" var t: f32;\n"
|
||||
" if (abs (A) > 1e-6)\n"
|
||||
" {\n"
|
||||
" let disc = B * B - 4.0 * A * C;\n"
|
||||
" if (disc < 0.0) { return vec4f (0.0); }\n"
|
||||
" let sq = sqrt (disc);\n"
|
||||
" let t1 = (-B + sq) / (2.0 * A);\n"
|
||||
" let t2 = (-B - sq) / (2.0 * A);\n"
|
||||
" if (r0 + t1 * dr >= 0.0) { t = t1; } else { t = t2; }\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" if (abs (B) < 1e-6) { return vec4f (0.0); }\n"
|
||||
" t = -C / B;\n"
|
||||
" }\n"
|
||||
" t = _hb_gpu_extend_t (t, extend);\n"
|
||||
" return _hb_gpu_eval_stops (hb_gpu_atlas, grad_base + 2, stop_count, t, foreground);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"fn hb_gpu_paint (renderCoord: vec2f, glyphLoc_: u32, foreground: vec4f,\n"
|
||||
" hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>) -> vec4f\n"
|
||||
"{\n"
|
||||
@@ -147,6 +190,11 @@ static const char *hb_gpu_paint_fragment_wgsl =
|
||||
" base + grad_payload,\n"
|
||||
" stop_count, extend, foreground,\n"
|
||||
" hb_gpu_atlas);\n"
|
||||
" } else if (aux == 1) {\n"
|
||||
" col = _hb_gpu_sample_radial (renderCoord,\n"
|
||||
" base + grad_payload,\n"
|
||||
" stop_count, extend, foreground,\n"
|
||||
" hb_gpu_atlas);\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" let cov = _hb_gpu_draw_impl (renderCoord, pixelsPerEm,\n"
|
||||
|
||||
@@ -57,22 +57,10 @@ float _hb_gpu_extend_t (float t, int extend)
|
||||
return clamp (t, 0.0, 1.0); /* PAD (default) */
|
||||
}
|
||||
|
||||
/* Sample a linear gradient whose param blob starts at @grad_base:
|
||||
* texel 0: (x0, y0, x1, y1) in font units (i16)
|
||||
* texels 1..: stops (2 texels each) */
|
||||
vec4 _hb_gpu_sample_linear (vec2 renderCoord, int grad_base,
|
||||
int stop_count, int extend, vec4 foreground)
|
||||
/* Walk stops starting at @stops_base and return the sampled color
|
||||
* at @t. Same logic reused by all gradient subtypes. */
|
||||
vec4 _hb_gpu_eval_stops (int stops_base, int stop_count, float t, vec4 foreground)
|
||||
{
|
||||
ivec4 axis = hb_gpu_fetch (grad_base);
|
||||
vec2 p0 = vec2 (float (axis.r), float (axis.g));
|
||||
vec2 p1 = vec2 (float (axis.b), float (axis.a));
|
||||
vec2 d = p1 - p0;
|
||||
float denom = dot (d, d);
|
||||
if (denom < 1e-6) return vec4 (0.0);
|
||||
float t = dot (renderCoord - p0, d) / denom;
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
|
||||
int stops_base = grad_base + 1;
|
||||
float off_prev;
|
||||
vec4 col_prev = _hb_gpu_stop_color (stops_base, 0, foreground, off_prev);
|
||||
if (t <= off_prev)
|
||||
@@ -93,6 +81,70 @@ vec4 _hb_gpu_sample_linear (vec2 renderCoord, int grad_base,
|
||||
return col_prev;
|
||||
}
|
||||
|
||||
/* Sample a linear gradient whose param blob starts at @grad_base:
|
||||
* texel 0: (x0, y0, x1, y1) in font units (i16)
|
||||
* texels 1..: stops (2 texels each) */
|
||||
vec4 _hb_gpu_sample_linear (vec2 renderCoord, int grad_base,
|
||||
int stop_count, int extend, vec4 foreground)
|
||||
{
|
||||
ivec4 axis = hb_gpu_fetch (grad_base);
|
||||
vec2 p0 = vec2 (float (axis.r), float (axis.g));
|
||||
vec2 p1 = vec2 (float (axis.b), float (axis.a));
|
||||
vec2 d = p1 - p0;
|
||||
float denom = dot (d, d);
|
||||
if (denom < 1e-6) return vec4 (0.0);
|
||||
float t = dot (renderCoord - p0, d) / denom;
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
|
||||
return _hb_gpu_eval_stops (grad_base + 1, stop_count, t, foreground);
|
||||
}
|
||||
|
||||
/* Sample a two-circle radial gradient whose param blob starts at
|
||||
* @grad_base:
|
||||
* texel 0: (x0, y0, r0, _)
|
||||
* texel 1: (x1, y1, r1, _)
|
||||
* texels 2..: stops (2 texels each)
|
||||
* Solves |P - C0 - t*(C1-C0)|^2 = (r0 + t*(r1-r0))^2 for t. */
|
||||
vec4 _hb_gpu_sample_radial (vec2 renderCoord, int grad_base,
|
||||
int stop_count, int extend, vec4 foreground)
|
||||
{
|
||||
ivec4 c0_ = hb_gpu_fetch (grad_base);
|
||||
ivec4 c1_ = hb_gpu_fetch (grad_base + 1);
|
||||
vec2 c0 = vec2 (float (c0_.r), float (c0_.g));
|
||||
float r0 = float (c0_.b);
|
||||
vec2 c1 = vec2 (float (c1_.r), float (c1_.g));
|
||||
float r1 = float (c1_.b);
|
||||
|
||||
vec2 cd = c1 - c0;
|
||||
float dr = r1 - r0;
|
||||
vec2 p = renderCoord - c0;
|
||||
|
||||
float A = dot (cd, cd) - dr * dr;
|
||||
float B = -2.0 * (dot (p, cd) + r0 * dr);
|
||||
float C = dot (p, p) - r0 * r0;
|
||||
|
||||
float t;
|
||||
if (abs (A) > 1e-6)
|
||||
{
|
||||
float disc = B * B - 4.0 * A * C;
|
||||
if (disc < 0.0) return vec4 (0.0);
|
||||
float sq = sqrt (disc);
|
||||
/* Prefer the larger root; fall back to the smaller if the
|
||||
* larger gives a negative interpolated radius. */
|
||||
float t1 = (-B + sq) / (2.0 * A);
|
||||
float t2 = (-B - sq) / (2.0 * A);
|
||||
t = (r0 + t1 * dr >= 0.0) ? t1 : t2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (abs (B) < 1e-6) return vec4 (0.0);
|
||||
t = -C / B;
|
||||
}
|
||||
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
return _hb_gpu_eval_stops (grad_base + 2, stop_count, t, foreground);
|
||||
}
|
||||
|
||||
/* Walks the paint blob's flat op stream and returns a
|
||||
* premultiplied RGBA coverage value for the current fragment.
|
||||
*
|
||||
@@ -146,11 +198,15 @@ vec4 hb_gpu_paint (vec2 renderCoord, uint glyphLoc, vec4 foreground)
|
||||
int stop_count = op2.a;
|
||||
|
||||
vec4 col = vec4 (0.0);
|
||||
if (aux == 0) /* linear */
|
||||
if (aux == 0) /* linear */
|
||||
col = _hb_gpu_sample_linear (renderCoord,
|
||||
base + grad_payload,
|
||||
stop_count, extend, foreground);
|
||||
/* Radial / sweep fall through as transparent for now. */
|
||||
else if (aux == 1) /* radial */
|
||||
col = _hb_gpu_sample_radial (renderCoord,
|
||||
base + grad_payload,
|
||||
stop_count, extend, foreground);
|
||||
/* Sweep falls through as transparent for now. */
|
||||
|
||||
float cov = _hb_gpu_draw_impl (renderCoord, pixelsPerEm,
|
||||
uint (base + payload));
|
||||
|
||||
@@ -52,19 +52,8 @@ float _hb_gpu_extend_t (float t, int extend)
|
||||
return clamp (t, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float4 _hb_gpu_sample_linear (float2 renderCoord, int grad_base,
|
||||
int stop_count, int extend, float4 foreground)
|
||||
float4 _hb_gpu_eval_stops (int stops_base, int stop_count, float t, float4 foreground)
|
||||
{
|
||||
int4 axis = hb_gpu_fetch (grad_base);
|
||||
float2 p0 = float2 ((float) axis.r, (float) axis.g);
|
||||
float2 p1 = float2 ((float) axis.b, (float) axis.a);
|
||||
float2 d = p1 - p0;
|
||||
float denom = dot (d, d);
|
||||
if (denom < 1e-6) return float4 (0.0, 0.0, 0.0, 0.0);
|
||||
float t = dot (renderCoord - p0, d) / denom;
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
|
||||
int stops_base = grad_base + 1;
|
||||
float off_prev;
|
||||
float4 col_prev = _hb_gpu_stop_color (stops_base, 0, foreground, off_prev);
|
||||
if (t <= off_prev) return col_prev;
|
||||
@@ -84,6 +73,57 @@ float4 _hb_gpu_sample_linear (float2 renderCoord, int grad_base,
|
||||
return col_prev;
|
||||
}
|
||||
|
||||
float4 _hb_gpu_sample_linear (float2 renderCoord, int grad_base,
|
||||
int stop_count, int extend, float4 foreground)
|
||||
{
|
||||
int4 axis = hb_gpu_fetch (grad_base);
|
||||
float2 p0 = float2 ((float) axis.r, (float) axis.g);
|
||||
float2 p1 = float2 ((float) axis.b, (float) axis.a);
|
||||
float2 d = p1 - p0;
|
||||
float denom = dot (d, d);
|
||||
if (denom < 1e-6) return float4 (0.0, 0.0, 0.0, 0.0);
|
||||
float t = dot (renderCoord - p0, d) / denom;
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
return _hb_gpu_eval_stops (grad_base + 1, stop_count, t, foreground);
|
||||
}
|
||||
|
||||
float4 _hb_gpu_sample_radial (float2 renderCoord, int grad_base,
|
||||
int stop_count, int extend, float4 foreground)
|
||||
{
|
||||
int4 c0_ = hb_gpu_fetch (grad_base);
|
||||
int4 c1_ = hb_gpu_fetch (grad_base + 1);
|
||||
float2 c0 = float2 ((float) c0_.r, (float) c0_.g);
|
||||
float r0 = (float) c0_.b;
|
||||
float2 c1 = float2 ((float) c1_.r, (float) c1_.g);
|
||||
float r1 = (float) c1_.b;
|
||||
|
||||
float2 cd = c1 - c0;
|
||||
float dr = r1 - r0;
|
||||
float2 p = renderCoord - c0;
|
||||
|
||||
float A = dot (cd, cd) - dr * dr;
|
||||
float B = -2.0 * (dot (p, cd) + r0 * dr);
|
||||
float C = dot (p, p) - r0 * r0;
|
||||
|
||||
float t;
|
||||
if (abs (A) > 1e-6)
|
||||
{
|
||||
float disc = B * B - 4.0 * A * C;
|
||||
if (disc < 0.0) return float4 (0.0, 0.0, 0.0, 0.0);
|
||||
float sq = sqrt (disc);
|
||||
float t1 = (-B + sq) / (2.0 * A);
|
||||
float t2 = (-B - sq) / (2.0 * A);
|
||||
t = (r0 + t1 * dr >= 0.0) ? t1 : t2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (abs (B) < 1e-6) return float4 (0.0, 0.0, 0.0, 0.0);
|
||||
t = -C / B;
|
||||
}
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
return _hb_gpu_eval_stops (grad_base + 2, stop_count, t, foreground);
|
||||
}
|
||||
|
||||
float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground)
|
||||
{
|
||||
/* fwidth once, at uniform control flow. */
|
||||
@@ -130,6 +170,10 @@ float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground)
|
||||
col = _hb_gpu_sample_linear (renderCoord,
|
||||
base + grad_payload,
|
||||
stop_count, extend, foreground);
|
||||
else if (aux == 1)
|
||||
col = _hb_gpu_sample_radial (renderCoord,
|
||||
base + grad_payload,
|
||||
stop_count, extend, foreground);
|
||||
|
||||
float cov = _hb_gpu_draw_impl (renderCoord, pixelsPerEm,
|
||||
(uint) (base + payload));
|
||||
|
||||
@@ -54,21 +54,10 @@ static float _hb_gpu_extend_t (float t, int extend)
|
||||
return clamp (t, 0.0, 1.0);
|
||||
}
|
||||
|
||||
static float4 _hb_gpu_sample_linear (float2 renderCoord, int grad_base,
|
||||
int stop_count, int extend,
|
||||
float4 foreground,
|
||||
device const short4* hb_gpu_atlas)
|
||||
static float4 _hb_gpu_eval_stops (device const short4* hb_gpu_atlas,
|
||||
int stops_base, int stop_count,
|
||||
float t, float4 foreground)
|
||||
{
|
||||
int4 axis = int4 (hb_gpu_atlas[grad_base]);
|
||||
float2 p0 = float2 (float (axis.r), float (axis.g));
|
||||
float2 p1 = float2 (float (axis.b), float (axis.a));
|
||||
float2 d = p1 - p0;
|
||||
float denom = dot (d, d);
|
||||
if (denom < 1e-6) return float4 (0.0);
|
||||
float t = dot (renderCoord - p0, d) / denom;
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
|
||||
int stops_base = grad_base + 1;
|
||||
float off_prev;
|
||||
float4 col_prev = _hb_gpu_stop_color (hb_gpu_atlas, stops_base, 0, foreground, off_prev);
|
||||
if (t <= off_prev) return col_prev;
|
||||
@@ -88,6 +77,61 @@ static float4 _hb_gpu_sample_linear (float2 renderCoord, int grad_base,
|
||||
return col_prev;
|
||||
}
|
||||
|
||||
static float4 _hb_gpu_sample_linear (float2 renderCoord, int grad_base,
|
||||
int stop_count, int extend,
|
||||
float4 foreground,
|
||||
device const short4* hb_gpu_atlas)
|
||||
{
|
||||
int4 axis = int4 (hb_gpu_atlas[grad_base]);
|
||||
float2 p0 = float2 (float (axis.r), float (axis.g));
|
||||
float2 p1 = float2 (float (axis.b), float (axis.a));
|
||||
float2 d = p1 - p0;
|
||||
float denom = dot (d, d);
|
||||
if (denom < 1e-6) return float4 (0.0);
|
||||
float t = dot (renderCoord - p0, d) / denom;
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
return _hb_gpu_eval_stops (hb_gpu_atlas, grad_base + 1, stop_count, t, foreground);
|
||||
}
|
||||
|
||||
static float4 _hb_gpu_sample_radial (float2 renderCoord, int grad_base,
|
||||
int stop_count, int extend,
|
||||
float4 foreground,
|
||||
device const short4* hb_gpu_atlas)
|
||||
{
|
||||
int4 c0_ = int4 (hb_gpu_atlas[grad_base]);
|
||||
int4 c1_ = int4 (hb_gpu_atlas[grad_base + 1]);
|
||||
float2 c0 = float2 (float (c0_.r), float (c0_.g));
|
||||
float r0 = float (c0_.b);
|
||||
float2 c1 = float2 (float (c1_.r), float (c1_.g));
|
||||
float r1 = float (c1_.b);
|
||||
|
||||
float2 cd = c1 - c0;
|
||||
float dr = r1 - r0;
|
||||
float2 p = renderCoord - c0;
|
||||
|
||||
float A = dot (cd, cd) - dr * dr;
|
||||
float B = -2.0 * (dot (p, cd) + r0 * dr);
|
||||
float C = dot (p, p) - r0 * r0;
|
||||
|
||||
float t;
|
||||
if (abs (A) > 1e-6)
|
||||
{
|
||||
float disc = B * B - 4.0 * A * C;
|
||||
if (disc < 0.0) return float4 (0.0);
|
||||
float sq = sqrt (disc);
|
||||
float t1 = (-B + sq) / (2.0 * A);
|
||||
float t2 = (-B - sq) / (2.0 * A);
|
||||
t = (r0 + t1 * dr >= 0.0) ? t1 : t2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (abs (B) < 1e-6) return float4 (0.0);
|
||||
t = -C / B;
|
||||
}
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
return _hb_gpu_eval_stops (hb_gpu_atlas, grad_base + 2, stop_count, t, foreground);
|
||||
}
|
||||
|
||||
float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground,
|
||||
device const short4* hb_gpu_atlas)
|
||||
{
|
||||
@@ -136,6 +180,11 @@ float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc_, float4 foreground,
|
||||
base + grad_payload,
|
||||
stop_count, extend, foreground,
|
||||
hb_gpu_atlas);
|
||||
else if (aux == 1)
|
||||
col = _hb_gpu_sample_radial (renderCoord,
|
||||
base + grad_payload,
|
||||
stop_count, extend, foreground,
|
||||
hb_gpu_atlas);
|
||||
|
||||
float cov = _hb_gpu_draw_impl (renderCoord, pixelsPerEm,
|
||||
uint (base + payload), hb_gpu_atlas);
|
||||
|
||||
@@ -58,20 +58,10 @@ fn _hb_gpu_extend_t (t: f32, extend: i32) -> f32
|
||||
return clamp (t, 0.0, 1.0);
|
||||
}
|
||||
|
||||
fn _hb_gpu_sample_linear (renderCoord: vec2f, grad_base: i32,
|
||||
stop_count: i32, extend: i32, foreground: vec4f,
|
||||
hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>) -> vec4f
|
||||
fn _hb_gpu_eval_stops (hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>,
|
||||
stops_base: i32, stop_count: i32,
|
||||
t: f32, foreground: vec4f) -> vec4f
|
||||
{
|
||||
let axis = hb_gpu_fetch (hb_gpu_atlas, grad_base);
|
||||
let p0 = vec2f (f32 (axis.r), f32 (axis.g));
|
||||
let p1 = vec2f (f32 (axis.b), f32 (axis.a));
|
||||
let d = p1 - p0;
|
||||
let denom = dot (d, d);
|
||||
if (denom < 1e-6) { return vec4f (0.0); }
|
||||
var t = dot (renderCoord - p0, d) / denom;
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
|
||||
let stops_base = grad_base + 1;
|
||||
var off_prev: f32;
|
||||
var col_prev = _hb_gpu_stop_color (hb_gpu_atlas, stops_base, 0, foreground, &off_prev);
|
||||
if (t <= off_prev) { return col_prev; }
|
||||
@@ -92,6 +82,59 @@ fn _hb_gpu_sample_linear (renderCoord: vec2f, grad_base: i32,
|
||||
return col_prev;
|
||||
}
|
||||
|
||||
fn _hb_gpu_sample_linear (renderCoord: vec2f, grad_base: i32,
|
||||
stop_count: i32, extend: i32, foreground: vec4f,
|
||||
hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>) -> vec4f
|
||||
{
|
||||
let axis = hb_gpu_fetch (hb_gpu_atlas, grad_base);
|
||||
let p0 = vec2f (f32 (axis.r), f32 (axis.g));
|
||||
let p1 = vec2f (f32 (axis.b), f32 (axis.a));
|
||||
let d = p1 - p0;
|
||||
let denom = dot (d, d);
|
||||
if (denom < 1e-6) { return vec4f (0.0); }
|
||||
var t = dot (renderCoord - p0, d) / denom;
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
return _hb_gpu_eval_stops (hb_gpu_atlas, grad_base + 1, stop_count, t, foreground);
|
||||
}
|
||||
|
||||
fn _hb_gpu_sample_radial (renderCoord: vec2f, grad_base: i32,
|
||||
stop_count: i32, extend: i32, foreground: vec4f,
|
||||
hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>) -> vec4f
|
||||
{
|
||||
let c0_ = hb_gpu_fetch (hb_gpu_atlas, grad_base);
|
||||
let c1_ = hb_gpu_fetch (hb_gpu_atlas, grad_base + 1);
|
||||
let c0 = vec2f (f32 (c0_.r), f32 (c0_.g));
|
||||
let r0 = f32 (c0_.b);
|
||||
let c1 = vec2f (f32 (c1_.r), f32 (c1_.g));
|
||||
let r1 = f32 (c1_.b);
|
||||
|
||||
let cd = c1 - c0;
|
||||
let dr = r1 - r0;
|
||||
let p = renderCoord - c0;
|
||||
|
||||
let A = dot (cd, cd) - dr * dr;
|
||||
let B = -2.0 * (dot (p, cd) + r0 * dr);
|
||||
let C = dot (p, p) - r0 * r0;
|
||||
|
||||
var t: f32;
|
||||
if (abs (A) > 1e-6)
|
||||
{
|
||||
let disc = B * B - 4.0 * A * C;
|
||||
if (disc < 0.0) { return vec4f (0.0); }
|
||||
let sq = sqrt (disc);
|
||||
let t1 = (-B + sq) / (2.0 * A);
|
||||
let t2 = (-B - sq) / (2.0 * A);
|
||||
if (r0 + t1 * dr >= 0.0) { t = t1; } else { t = t2; }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (abs (B) < 1e-6) { return vec4f (0.0); }
|
||||
t = -C / B;
|
||||
}
|
||||
t = _hb_gpu_extend_t (t, extend);
|
||||
return _hb_gpu_eval_stops (hb_gpu_atlas, grad_base + 2, stop_count, t, foreground);
|
||||
}
|
||||
|
||||
fn hb_gpu_paint (renderCoord: vec2f, glyphLoc_: u32, foreground: vec4f,
|
||||
hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>) -> vec4f
|
||||
{
|
||||
@@ -146,6 +189,11 @@ fn hb_gpu_paint (renderCoord: vec2f, glyphLoc_: u32, foreground: vec4f,
|
||||
base + grad_payload,
|
||||
stop_count, extend, foreground,
|
||||
hb_gpu_atlas);
|
||||
} else if (aux == 1) {
|
||||
col = _hb_gpu_sample_radial (renderCoord,
|
||||
base + grad_payload,
|
||||
stop_count, extend, foreground,
|
||||
hb_gpu_atlas);
|
||||
}
|
||||
|
||||
let cov = _hb_gpu_draw_impl (renderCoord, pixelsPerEm,
|
||||
|
||||
+80
-3
@@ -317,6 +317,82 @@ hb_gpu_paint_emit_linear (hb_gpu_paint_t *c,
|
||||
c->num_ops++;
|
||||
}
|
||||
|
||||
static void
|
||||
hb_gpu_paint_emit_radial (hb_gpu_paint_t *c,
|
||||
hb_color_line_t *color_line,
|
||||
float x0, float y0, float r0,
|
||||
float x1, float y1, float r1)
|
||||
{
|
||||
if (unlikely (!c->pending_clip))
|
||||
return;
|
||||
|
||||
unsigned count = hb_color_line_get_color_stops (color_line, 0, nullptr, nullptr);
|
||||
if (unlikely (!count))
|
||||
return;
|
||||
hb_color_stop_t stack_stops[16];
|
||||
hb_color_stop_t *stops = stack_stops;
|
||||
hb_color_stop_t *heap_stops = nullptr;
|
||||
if (count > 16)
|
||||
{
|
||||
heap_stops = (hb_color_stop_t *) hb_malloc (count * sizeof (hb_color_stop_t));
|
||||
if (unlikely (!heap_stops)) { c->unsupported = true; return; }
|
||||
stops = heap_stops;
|
||||
}
|
||||
unsigned got = count;
|
||||
hb_color_line_get_color_stops (color_line, 0, &got, stops);
|
||||
|
||||
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; }
|
||||
|
||||
/* Build gradient params sub-blob.
|
||||
* texel 0: (x0, y0, r0, _) in font units (i16)
|
||||
* texel 1: (x1, y1, r1, _) in font units (i16)
|
||||
* texels 2..N: color stops (2 texels each)
|
||||
*/
|
||||
hb_vector_t<int16_t> grad_data;
|
||||
if (unlikely (!grad_data.resize (8)))
|
||||
{ c->unsupported = true; hb_free (heap_stops); return; }
|
||||
grad_data[0] = clamp_i16 (x0);
|
||||
grad_data[1] = clamp_i16 (y0);
|
||||
grad_data[2] = clamp_i16 (r0);
|
||||
grad_data[3] = 0;
|
||||
grad_data[4] = clamp_i16 (x1);
|
||||
grad_data[5] = clamp_i16 (y1);
|
||||
grad_data[6] = clamp_i16 (r1);
|
||||
grad_data[7] = 0;
|
||||
|
||||
if (unlikely (!append_color_stops (grad_data, stops, got)))
|
||||
{ c->unsupported = true; hb_free (heap_stops); return; }
|
||||
hb_free (heap_stops);
|
||||
|
||||
unsigned grad_bytes = grad_data.length * sizeof (int16_t);
|
||||
hb_blob_t *grad_blob = hb_blob_create ((const char *) grad_data.arrayZ,
|
||||
grad_bytes, HB_MEMORY_MODE_DUPLICATE,
|
||||
nullptr, nullptr);
|
||||
if (unlikely (!grad_blob || !c->sub_blobs.push (grad_blob)))
|
||||
{
|
||||
hb_blob_destroy (grad_blob);
|
||||
c->unsupported = true;
|
||||
return;
|
||||
}
|
||||
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;
|
||||
c->num_ops++;
|
||||
}
|
||||
|
||||
static void
|
||||
hb_gpu_paint_color (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
void *paint_data,
|
||||
@@ -362,11 +438,12 @@ static void
|
||||
hb_gpu_paint_radial_gradient (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
void *paint_data,
|
||||
hb_color_line_t *color_line,
|
||||
float x0 HB_UNUSED, float y0 HB_UNUSED, float r0 HB_UNUSED,
|
||||
float x1 HB_UNUSED, float y1 HB_UNUSED, float r1 HB_UNUSED,
|
||||
float x0, float y0, float r0,
|
||||
float x1, float y1, float r1,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_gpu_paint_gradient_first_stop ((hb_gpu_paint_t *) paint_data, color_line);
|
||||
hb_gpu_paint_emit_radial ((hb_gpu_paint_t *) paint_data, color_line,
|
||||
x0, y0, r0, x1, y1, r1);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in new issue
Block a user