Repository navigation
feat(core): show app-drawn pixel buffers in images and canvases - #587
Merged
Merged
Conversation
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
force-pushed
the
feat/image-pixel-buffers
branch
from
November 17, 2026 11:39
bd0bd29 to
2a8bcd9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #107.
ImageSourcegainsPixels, an*image.RGBAthe app draws, andVersion, 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 nextRequestAnimationFramecallback.ImageSizeanswers a pixel source at once with its buffer's size; a shader'sImagesdrop pixels, as the core copies none for them.nsgotestreports the pixels an image shows; public docs (en/zh), architecture docs, the nsgo skill references and the changelog are updated.Targets
internal/platform/appletests run on Mac Studio over SSH (no GUI session); no interactive run.TestPixelsReplaceThePictureInPlaceand the pixel limit.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
mainthe same example does not compile, becauseImageSource.Pixelsis missing.Verification
All run from the feature worktree with Go 1.27.3 via mise;
rbuildis the Mac Studio,ubuildthe 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 animagename 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 newTestPixelsAreCopiedOncePerVersion,TestPixelsMeasureTheirPixels,TestPixelsCopyASubImage,TestPixelsFireNoLoadEventsandTestCanvasCopiesThePixelsItDraws.ubuild ... go tool nsgo test ./internal/driver: 133 passed.ubuild ... go tool nsgo test ./internal/platform/imagedecode: 26 passed, includingTestFromPixelsSwapsToBGRAandTestAsPNGEncodesEachCopyOnce(alpha survives the PNG round trip).ubuild ... go tool nsgo test ./nsgotest: 71 passed, includingTestImageReportsThePixelsItShows.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), includingTestImageViewShowsPixelsInPlaceandTestCanvasFramesKeepTheLatest.After review fixes:
ubuild ... go tool nsgo test -run 'Pixel|ImageSize|Shader|Image' ./core: 21 passed, including the 2 new tests;./internal/platform/imagedecodeand./internal/driverpassed.ubuild ... go tool nsgo check -targetfor linux_x64, windows_x64, android_arm64 and web: clean.TestPixelsDrawWithTheirAlphaAndSwapInPlaceandTestCanvasDrawsPixelsAtOnce: 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 -targetmacos_arm64 and ios: clean.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 newTestPixelsTakeNoPlaceholderAndEmptyBuffersNoCopyandTestCanvasDrawsNoEmptyBuffer;./nsgotest71,./internal/platform/imagedecode26 and./internal/driver133 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.