Repository navigation
Commit ecae8de
[avio] cherry-pick: shade linear and radial gradients inside UberSDF (flutter#192124, flutter#192962)
UberSDF in this fork cannot shade a color source, so every antialiased
gradient rect, rrect, oval or circle (Avio's Shell and greeter run with
use_sdfs) was blended through a white SDF mask: two snapshots and a blend
target per draw, plus a deferred coverage pass in externalLinearBackdrop
mode. Upstream fixed this in the owning layer: fdb1d09 (flutter#192124) shades
linear and radial gradients inside UberSDF and 419f9dd (flutter#192962) adds the
storage-buffer variant used on Vulkan, so no ramp texture is made per draw.
Both upstream commits sit on intermediate UberSDF changes this fork does not
carry (uniform reordering, rect-path derivatives, stroke pixel size, which
would change other SDF output), and Avio's UberSDF carries patch 45's
coverage fields, so this is an adapted backport in one commit, not literal
cherry-picks:
- uber_sdf.frag is split into uber_sdf_common.glsl (shape SDFs, getColor,
main) plus uber_sdf.frag (ramp texture) and uber_sdf_ssbo.frag (gradient
stops in a storage buffer, the same math as the SSBO gradient shaders).
Wherever the backend supports SSBOs (Vulkan), every UberSDF draw uses the
SSBO variant, as upstream does.
- UberSDFParameters gains GradientParameters; UberSDFContents renders both
variants from one FragInfo setup; color filters wrap on the GPU for a
gradient, and a gradient is never a background color.
- Canvas::AddRenderSDFEntityToCurrentPass shades a linear or radial gradient
whose local matrix (with the inverse shape transform) is a similarity.
Conical and sweep gradients, images and runtime effects keep the masked
kSrcIn path patch 52 slims. Patch 52's no-mask rect still comes first.
- A gradient shaded in UberSDF takes the coverage transfer in the shader;
defer_coverage no longer includes the color source in that case.
Avio deltas against upstream (decision D3, accepted on the condition that
Avio's crisp look stays):
- Edges keep the old response: a gradient's SDF alpha uses the
light-foreground gamma correction of the white mask it was blended through
before, not the gradient's luma; the SSBO variant dithers like the SSBO
gradient shaders, and like the masked composite it dithers the gradient
color before coverage scales it, so a pixel the shape does not cover (the
AA band's outside, the quad corners around a rounded shape) stays exactly
transparent and srcOver adds nothing to what lies underneath. Upstream
does not dither in UberSDF.
- Linear gradients also require a similarity matrix (upstream checks only
affinity); mapping end points through a shear or non-uniform scale does not
map the gradient's field.
- flutter#191925 and flutter#191980 are not brought in: the ramp-texture variant uses the
fork's current GradientData, and Avio's SDF users take the SSBO variant.
- malioc.json is not updated.
Nothing else on the branch depends on this commit; its tests use patch
52's Playground::EnsureContextUsesSDFs. Reverting it alone restores the
masked path exactly.
Tests:
- UberSDFContentsTest.ApplyColorFilterWithGradient and
AsBackgroundColorGradientReturnsNullopt (from upstream; red as compile
failures on the base: GradientParameters did not exist).
- On every playground that renders with SDFs (Playground::
EnsureContextUsesSDFs: Vulkan with SDFs enabled, which runs the
storage-buffer variant Avio ships, and the OpenGL ES and Metal SDF
backends, which run the ramp-texture variant; plain backends skip):
AiksTest.SdfLinearGradientRectAllocatesNoOffscreen (expected red on the
base: three offscreens), SdfRadialGradientCircleUnderNonUniformScale-
AllocatesNoOffscreen, UnsupportedColorSourceStillBlends (a sweep gradient
keeps exactly three offscreens), and SdfGradientEdgesMatchMaskedComposite:
the pixel guard the user asked for. It renders rect, rounded rect, oval
and circle with an opaque dark-to-light gradient and a translucent glass
sheen, in platformDefault and externalLinearBackdrop, once shaded in
UberSDF and once through the old masked composite (the same horizontal
gradient with a y-scale local matrix, which leaves its field unchanged but
routes it through the masked path). Every pixel, corners and antialiased
edges included, must hold alpha within 2/255 and color within 2/255
(ramp texture, no dither) or 5/255 (storage buffer: the composite dithered
in its snapshot's grid, then quantized once more); every pixel the
composite leaves fully transparent must stay exactly zero. Green by
construction on the base (both renders take the masked path there); after
this patch it fails if edges, corners, glass coverage or uncovered pixels
drift.
- SdfGradientLeavesUncoveredQuadPixelsTransparent: the quad corners around a
gradient circle are exactly zero in both coverage modes, opaque and glass.
Red on the storage-buffer variant if the dither runs after coverage.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent e8af02e commit ecae8de
16 files changed
Lines changed: 1264 additions & 326 deletions
File tree
- engine/src/flutter/impeller
- display_list
- entity
- contents
- shaders
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
830 | 831 | | |
831 | 832 | | |
832 | 833 | | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
833 | 888 | | |
834 | 889 | | |
835 | 890 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
459 | 475 | | |
460 | 476 | | |
461 | 477 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
0 commit comments