Skip to content

feat(canvas): render drawings offscreen and add Windows/Linux windowless helpers - #2564

Open
houko wants to merge 2 commits into
mainfrom
feat/render-drawing-offscreen-565
Open

houko wants to merge 2 commits into
mainfrom
feat/render-drawing-offscreen-565

Conversation

@houko

@houko houko commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Completes the remaining slices of #565 on top of #1871 (macOS windowless nsgotest helpers):

  • Runtime offscreen drawing service (core, internal/driver):
    • Added Scope.RenderDrawing(d *Drawing, size Size, scale float64, done func(image.Image, error)) and Env.CanRenderDrawings() bool backed by driver.ItemRenderDrawing and driver.RenderDrawingRequest.
    • Validates finite positive dimensions and enforces the 16 Mi pixel ceiling (driver.RenderPixelSize), resolves scale variants, copies pixel frames, enforces the owner's Access rules on image URIs inside the drawing, and enables canvas (and shader) linking on demand so minimal apps never pull in canvas players.
    • Wired across macOS, iOS, tvOS, watchOS (apple.RenderDrawingAsync), Windows (Direct2D/DirectWrite), Linux (Cairo/Pango), Web (HTML Canvas2D), and headless nsgotest (with App.RenderDrawing override hook); Android, HarmonyOS, and mini-program backends answer driver.NoDrawingRenderer (CodeUnavailable).
  • Windows and Linux windowless nsgotest support:
    • Implemented PlatformTextEngine(), RegisterFont([]byte) error, and RenderDrawing(*driver.Drawing, driver.Size, float64) in internal/platform/windows/render.go (DirectWrite/Direct2D offscreen bitmap with private per-call image and nested-offscreen caches) and internal/platform/linux/render.go (Cairo/Pango/Fontconfig without GTK or a display, via split openCanvasLibs()).
    • Wired nsgotest.PlatformTextEngine(), nsgotest.RegisterFont, and nsgotest.Render on Windows and Linux alongside macOS.
  • Tests, docs, skill, and changelog:
    • Added unit and pixel tests in internal/driver/render_test.go, core/render_test.go, nsgotest/render_test.go, and nsgotest/render_macos_test.go (broadened to macOS/Windows/Linux).
    • Updated architecture docs, English/Chinese public docs, roadmap, skills/nsgo/references/testing.md, and added changelog.d/render-drawing-offscreen.md.

Verification

  • gofmt -l on all changed Go files: clean
  • go tool nsgo test ./core ./internal/driver ./nsgotest ./internal/platform/apple ./internal/platform/macos ./internal/moduletest: passed
  • NSGO_PLATFORM_DUPLICATES_BASE=origin/main go tool nsgo test -run '^TestPlatformFunctionDuplicates$' ./internal/moduletest: passed
  • go tool nsgo test -run TestRepositoryFragments ./tools/changelog: passed
  • go tool nsgo check -target macos,ios,windows_x64,linux_x64,android_arm64,web,harmonyos,watchos,tui -jobs 2: passed

Fixes #565.

🤖 Gemini 4 Neon

@github-actions github-actions Bot added size/XL enhancement New feature or request documentation Improvements or additions to documentation macOS iOS watchOS Windows Linux Web Android Mini-program core and removed enhancement New feature or request labels Nov 27, 2026
@github-actions github-actions Bot added enhancement New feature or request cli labels Nov 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Render a Drawing to pixels without a window, and give headless tests the platform's text engine

1 participant