Skip to content

feat(stlxgfx): added a straight alpha surface flag - #606

Merged
FlareCoding merged 1 commit into
masterfrom
pr/comp-straight-alpha
Nov 7, 2026
Merged

FlareCoding merged 1 commit into
masterfrom
pr/comp-straight-alpha

Conversation

@FlareCoding

Copy link
Copy Markdown
Owner

Summary

Every blend in libstlxgfx, userland's 2D drawing library, makes its pixel opaque, so a picture drawn onto a
transparent surface loses its coverage (the share of each pixel it covers), which it needs to be blended onto the
screen later, and a surface flag keeps that coverage.

Changes

  • Keep a picture's coverage: on a surface whose flags field holds STLXGFX_SURFACE_STRAIGHT_ALPHA, the
    blending calls (stlxgfx_blend_coverage, stlxgfx_fill_rect_blend, stlxgfx_blit_alpha,
    stlxgfx_blit_rounded_alpha, stlxgfx_blit_arc_corner and stlxgfx_draw_text) store straight alpha (a color not
    multiplied by its alpha), so a draw onto a transparent pixel stores its color and alpha. A draw onto a partly
    covered pixel stores the coverage of both draws together, rounded up, with the mean of both colors weighted by the
    coverage each shows, while opaque pixels, like every surface without the flag, blend exactly as before.
  • Test library code in CI: make host-test builds libstlxgfx's tests in userland/lib/libstlxgfx/tests/ with the
    build machine's clang and runs them there, outside Stellux, and a "Host tests" workflow runs the target on every
    pull request.
  • Avoid undefined behavior in arc corners: stlxgfx_blit_arc_corner casts its 8-bit coverage to uint32_t
    before shifting it 24 bits left, since C promotes it to a signed int, which the shift overflows for coverage
    above 127.
  • Tests: straight_alpha.test.c checks each blending call on flagged surfaces: a draw onto alpha 0 stores its color
    and alpha, that picture blended once onto an opaque surface matches the same draw made there, a draw onto alpha 1 to
    254 follows the rule that stlxgfx_blend_straight states, with each channel between both colors, and one onto alpha
    255 matches an unflagged surface. In QEMU on x86_64 and aarch64, with a terminal, the demo app windemo and the
    settings app open, the desktop below the top bar is byte-identical to the base commit's, b36caf7 (the landing
    record's reviews/gpu-compositor/14a2-desktop-x86_64.png and -aarch64.png show both desktops, the base on the left,
    and 14a2-buttons-x86_64.png and -aarch64.png the settings app's buttons zoomed 4 times, the base above).

Every blend makes its pixel opaque, so a picture drawn onto a transparent
surface loses the coverage it needs to be blended again. A flagged surface
keeps each pixel's coverage in its alpha, as a host test in CI checks.
@FlareCoding
FlareCoding merged commit 3a50a01 into master Nov 7, 2026
11 checks passed
@FlareCoding
FlareCoding deleted the pr/comp-straight-alpha branch November 7, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant