Skip to content

NewPixelPainterBGRA: draw into a buffer that is not RGBA - #18

Merged
tannevaled merged 1 commit into
mainfrom
bgra-buffers
Aug 29, 2026
Merged

NewPixelPainterBGRA: draw into a buffer that is not RGBA#18
tannevaled merged 1 commit into
mainfrom
bgra-buffers

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

A screen capture, a video frame and several native surfaces hand over blue, green, red, alpha. A consumer drawing widgets over one had two bad choices: swap the capture, which is the largest thing in the frame and the one part that must not be copied twice; or hand every colour in the theme over pre-swapped, which is dozens of values and one forgotten one away from a wrong colour nobody traces back.

Swapping here costs two byte stores per pixel written, and a widget writes a small part of a frame.

Measured

go-xrkit/desk's canvas holds BGRA, because ScreenCaptureKit hands over BGRA and the frame is swapped once on the way to the window (swapRB). Every overlay the toolkit drew into it — the screen number, the gallery marks, the application tiles — came out with red and blue exchanged:

toolkit.RGB(0x11,0x22,0x33) lands as 11 22 33 FF   ← RGBA, into a BGRA canvas
SelectionInk = {255 140 26 255}                    ← orange…

…and the orange selection ring was blue on the glasses. Nobody had noticed because that picture is only ever seen through a headset.

All three paths that write a colour are covered: the fast opaque fill that builds one row and doubles it, an opaque pixel, and a translucent one that composites channel by channel. Coverage stays at 100%; -race clean; linux and windows vet clean.

A screen capture, a video frame and several native surfaces hand over BLUE,
green, red, alpha. A consumer drawing widgets over one had two bad choices:
swap the CAPTURE, which is the largest thing in the frame and the one part
that must not be copied twice, or hand every colour in the theme over
pre-swapped, which is dozens of values and one forgotten one away from a
wrong colour nobody traces back.

Swapping here costs two byte stores per pixel WRITTEN, and a widget writes a
small part of a frame.

Measured in go-xrkit/desk: its canvas holds BGRA because ScreenCaptureKit
hands over BGRA and the frame is swapped once on the way to the window. Every
overlay the toolkit drew into it -- the screen number, the gallery marks, the
application tiles -- came out with red and blue exchanged, so the orange
selection ring was BLUE on the glasses and nobody had noticed because the
picture is only ever seen through a headset.

All three paths that write a colour are covered: the fast opaque fill that
builds one row and doubles it, an opaque pixel, and a translucent one that
composites channel by channel.
@tannevaled
tannevaled merged commit 8d952e2 into main Aug 29, 2026
1 check passed
@tannevaled
tannevaled deleted the bgra-buffers branch August 29, 2026 09:11
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