Skip to content

Skip default WebGL background rectangles and keep their alpha - #6295

Open
shkomg wants to merge 1 commit into
xtermjs:masterfrom
userstoriesbot-showcase:fix/webgl-transparent-attr-bg
Open

shkomg wants to merge 1 commit into
xtermjs:masterfrom
userstoriesbot-showcase:fix/webgl-transparent-attr-bg

Conversation

@shkomg

@shkomg shkomg commented Nov 3, 2026

Copy link
Copy Markdown

Fixes #6116

With allowTransparency and a transparent theme background, the WebGL renderer painted an opaque rectangle behind italic and dim cells (and underlined and overlined ones). Those cells keep their attribute flags in bg, so updateBackgrounds() gives them a rectangle with the default background color, and _updateRectangle() then forced its alpha to 1.

This follows @azekyoo's analysis in the issue and does both things suggested there:

  • updateBackgrounds() only adds a rectangle when the background color mode is not default (or the cell is inverse), so attribute flags alone no longer produce one.
  • _updateRectangle() takes the alpha from the resolved color instead of forcing 1. The two 24-bit branches are packed without an alpha byte, so they now OR in 0xFF, the same way CellColorResolver does.

Opaque themes are unaffected: every color there has alpha 0xFF. In Chromium the demo after "SGR test" is pixel-identical before and after this change with the demo theme, also with 24-bit and inverse 24-bit backgrounds.

Tests:

  • Two Playwright tests under allowTransparency in SharedRendererTests.ts: with a fully transparent background, italic and dim cells show the page; with a semi-transparent one (#2850a080), they have the same pixels as a plain cell. Both fail on WebGL without the change and pass on the DOM and WebGL renderers with it. They repaint the viewport before each check, so pixels left by an earlier test cannot show through.
  • addon-webgl and Renderer.test.ts Playwright suites pass in Chromium; unit tests and lint pass.

Before and after in the demo (WebGL, allowTransparency ticked, "SGR test"), zoomed 4x:

Before:

before

After:

after

The video shows the demo with allowTransparency on and the SGR test output, before and after: the italic and dim rows lose their black boxes and sit on the checkerboard.

xterm.mp4

The demo's checkerboard is lightened in the recorded fork (not part of this PR) so the black boxes are easier to see.

Fix written with Claude Code; video is an automated browser run of this branch recorded by User Stories Bot.

RectangleRenderer forced the alpha of every cell background rectangle
to 1. Cells with the italic, dim, underline or overline attribute carry
flags in their bg value, so they get a rectangle even when they use the
default background. With allowTransparency and a transparent theme
background that rectangle was painted opaque, leaving a black box behind
the text.

Only add a rectangle when the background color mode is not default or
the cell is inverse, and take the alpha from the resolved color, setting
it to 0xFF for 24-bit colors, which are packed without an alpha byte.
Opaque themes render the same as before.
@Nanako0129

Copy link
Copy Markdown

I checked this PR (c99849e) against master (08829c7) with a few more styles than the tests cover. Headless Chrome with SwiftShader, magenta page, ten styled spaces per row sampled at the cell centre. The terminal starts with an opaque #1e1e1e theme and switches to rgba(30,30,30,0.5) at runtime, which is how an app's opacity setting usually changes it:

Row master this PR
plain (79, 32, 79) (79, 32, 79)
dim (30, 30, 30) (79, 32, 79)
italic (30, 30, 30) (79, 32, 79)
curly underline (4:3) (30, 30, 30) (79, 32, 79)
bold (79, 32, 79) (79, 32, 79)
overline (53) (30, 30, 30) (79, 32, 79)
protected (DECSCA 1"q) (30, 30, 30) (79, 32, 79)

With the translucent theme set from the start, plain, dim, italic, curly underline and bold read the same.

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.

WebGL: opaque background rectangle painted behind italic/dim cells when the theme background is transparent (alpha hard-coded in RectangleRenderer)

2 participants