Skip to content

feat(core): show app-drawn pixel buffers in images and canvases - #587

Merged
houko merged 2 commits into
mainfrom
feat/image-pixel-buffers
Nov 17, 2026
Merged

houko merged 2 commits into
mainfrom
feat/image-pixel-buffers

Conversation

@houko

@houko houko commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #107.

ImageSource gains Pixels, an *image.RGBA the app draws, and Version, which tells frames written into the same buffer apart. The core copies the pixels once per version when the commit that carries them runs, for image views and for the images a canvas draws, so the app may write the next frame into the same buffer from its next RequestAnimationFrame callback.

  • Pixels load and decode nothing: the view fires no load events, fades nothing in, takes no placeholder, keeps its alpha, and measures its pixels in points without a declared size. A buffer with no pixels shows, and a canvas draws, no image.
  • ImageSize answers a pixel source at once with its buffer's size; a shader's Images drop pixels, as the core copies none for them.
  • Apple (macOS, iOS, tvOS, watchOS), Windows and Linux draw the copy directly (a CGImage, a premultiplied Direct2D bitmap, a Cairo surface) and swap a new version in place with no blank frame. Their canvases keep the images of at most 8 copies and 8 Mi pixels.
  • The web puts the pixels into a canvas, which canvases draw and whose PNG image views show. Android image views show a PNG made once per copy, each view keeping only its latest. On Android and the web each version loads as a new image, blank until it decodes.
  • Not yet: Android canvases, HarmonyOS and mini programs do not show pixels (mini program canvases skip them rather than keep an image per version), and a hidden or minimized window still copies each version. The roadmap row records these gaps and the 60 fps cost measurement that is still open.
  • nsgotest reports the pixels an image shows; public docs (en/zh), architecture docs, the nsgo skill references and the changelog are updated.

Targets

  • macOS: compiled, vetted, and internal/platform/apple tests run on Mac Studio over SSH (no GUI session); no interactive run.
  • iOS, tvOS, watchOS: compiled and vetted only (shared Apple code covered by the macOS tests).
  • Linux: compiled, vetted, and the pixel/canvas render tests run headless on Ubuntu.
  • Windows: cross-compiled and vetted only; not run (no Windows machine), including TestPixelsReplaceThePictureInPlace and the pixel limit.
  • Android: compiled and vetted only; no device run. Canvases do not show pixels yet.
  • Web: compiled and vetted only; no browser run.
  • HarmonyOS: compiles; pixels are not shown yet (roadmap).
  • Mini programs: compiles; pixels are not shown yet (roadmap).

Screenshots

None could be captured. This Mac's disk dropped to about 1 GB free during the task, below the floor for running a GUI example locally, and neither build host has a GUI session over SSH. A meaningful "before" shot also does not exist: on main the same example does not compile, because ImageSource.Pixels is missing.

Verification

All run from the feature worktree with Go 1.27.3 via mise; rbuild is the Mac Studio, ubuild the Ubuntu host.

  • rbuild ... go tool nsgo check -target all .: exited 0 with every target vetted.
  • ubuild ... go tool nsgo check -target linux_x64,windows_x64,android_arm64,web,harmonyos,miniprogram .: exited 0 after fixing an image name clash in the web package.
  • ubuild ... go tool nsgo check -target windows_x64,windows_arm64 .: exited 0.
  • ubuild ... go tool nsgo test ./core: 667 passed, including the new TestPixelsAreCopiedOncePerVersion, TestPixelsMeasureTheirPixels, TestPixelsCopyASubImage, TestPixelsFireNoLoadEvents and TestCanvasCopiesThePixelsItDraws.
  • ubuild ... go tool nsgo test ./internal/driver: 133 passed.
  • ubuild ... go tool nsgo test ./internal/platform/imagedecode: 26 passed, including TestFromPixelsSwapsToBGRA and TestAsPNGEncodesEachCopyOnce (alpha survives the PNG round trip).
  • ubuild ... go tool nsgo test ./nsgotest: 71 passed, including TestImageReportsThePixelsItShows.
  • ubuild ... go tool nsgo test ./internal/moduletest: 9 passed (link restrictions and the skills name check).
  • ubuild ... go tool nsgo test ./tsx: 165 passed.
  • ubuild ... go tool nsgo test ./internal/platform/linux -- -run 'TestPixels|TestCanvasDrawsPixels|TestImageDrawsItsPixels|TestCanvasReplays': 4 passed, headless.
  • rbuild ... go tool nsgo test ./internal/platform/apple: 80 passed, 2 skipped (unrelated keychain and timezone tests), including TestImageViewShowsPixelsInPlace and TestCanvasFramesKeepTheLatest.

After review fixes:

  • ubuild ... go tool nsgo test -run 'Pixel|ImageSize|Shader|Image' ./core: 21 passed, including the 2 new tests; ./internal/platform/imagedecode and ./internal/driver passed.
  • ubuild ... go tool nsgo check -target for linux_x64, windows_x64, android_arm64 and web: clean.
  • Linux TestPixelsDrawWithTheirAlphaAndSwapInPlace and TestCanvasDrawsPixelsAtOnce: passed, headless.
  • rbuild ... go tool nsgo test -target macos -run 'TestImageViewShowsPixelsInPlace|TestCanvasFramesKeepTheLatest' ./internal/platform/apple: passed, including the new pixel-limit check.
  • rbuild ... go tool nsgo check -target macos_arm64 and ios: clean.
  • gofmt is clean on every touched file.

Second review (placeholder dropped for pixel sources, empty buffers sent as no image, mini program canvases skip pixels):

  • ubuild ... go tool nsgo check -target all: exited 0 (Apple targets skipped there); -target miniprogram,harmonyos: exited 0.
  • rbuild ... go tool nsgo check -target ios,tvos,watchos: exited 0.
  • ubuild ... go tool nsgo test ./core: 673 passed, including the new TestPixelsTakeNoPlaceholderAndEmptyBuffersNoCopy and TestCanvasDrawsNoEmptyBuffer; ./nsgotest 71, ./internal/platform/imagedecode 26 and ./internal/driver 133 passed.
  • ubuild ... go tool nsgo test ./internal/platform/linux -- -run 'TestPixels|TestCanvasDrawsPixels|TestImageDrawsItsPixels': 3 passed, headless.
  • rbuild ... go tool nsgo test ./internal/platform/apple -- -run 'TestImageViewShowsPixelsInPlace|TestCanvasFramesKeepTheLatest|TestDecode': 3 passed.

Not done: the 60 fps cost measurement at 960x540 and 1920x1080 from the acceptance list (kept in the roadmap row), any Windows run, and any Android device or browser run.

@github-actions github-actions Bot added size/XL documentation Improvements or additions to documentation macOS iOS Windows Linux Web Android core enhancement New feature or request conflict Conflicts with the base branch; resolve it first Mini-program and removed size/XL labels Nov 17, 2026
ImageSource gains Pixels, an *image.RGBA the app draws, and Version, which tells frames written into the same buffer apart. The core copies the pixels once per version when the commit that carries them runs, for image views and for the images a canvas draws, so the app may write the next frame into the same buffer from its next RequestAnimationFrame callback. Pixels load and decode nothing: the view fires no load events and fades nothing in, its alpha kept, and measures its pixels in points without a declared size. ImageSize answers a pixel source at once with its buffer's size, and a shader's Images drop pixels, as the core copies none for them.

Apple (macOS, iOS, tvOS, watchOS), Windows and Linux draw the copy directly, as a CGImage, a premultiplied Direct2D bitmap and a Cairo surface, and swap a new version in place with no blank frame; their canvases keep the images of at most 8 copies and 8 Mi pixels. The web puts the pixels into a canvas, which canvases draw and whose PNG image views show; Android shows a PNG made once per copy, each view keeping only its latest. On Android and the web each version loads as a new image, blank until it decodes. Android's canvases, HarmonyOS and mini programs do not show pixels yet, and a hidden or minimized window still copies each version, as the roadmap records.

Fixes #107
A pixel source loads nothing, so a placeholder only cost a load and could show between versions on Android and the web; the core now sends none with it, as the docs say. A buffer with no pixels sends no copy, which Windows' bitmap path indexed into and Linux scaled by an infinite factor, and a canvas draws no image for it. Mini program canvases skip pixels instead of keeping an image per version that never loads. The changelog entry is one clause, and images.md records why NSGo takes premultiplied image.RGBA it copies where NSH takes straight RGBA.
@houko
houko force-pushed the feat/image-pixel-buffers branch from bd0bd29 to 2a8bcd9 Compare November 17, 2026 11:39
@houko
houko merged commit f982489 into main Nov 17, 2026
12 of 14 checks passed
@houko
houko deleted the feat/image-pixel-buffers branch November 17, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android conflict Conflicts with the base branch; resolve it first core documentation Improvements or additions to documentation enhancement New feature or request iOS Linux macOS Mini-program size/XL Web Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pixel buffers: let an Image show an app-decoded image.RGBA every frame, under overlays (video player frames)

1 participant