Skip to content

feat(canvas): add per-draw image tinting - #1200

Merged
houko merged 1 commit into
nsgo-dev:mainfrom
houko:feat/canvas-image-tint-1111
Nov 22, 2026
Merged

houko merged 1 commit into
nsgo-dev:mainfrom
houko:feat/canvas-image-tint-1111

Conversation

@houko

@houko houko commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1111

Changes

  • Add DrawTintedImage, DrawTintedImageIn, and DrawTintedImageFrom in Go, plus drawTintedImage in TSX. Tint multiplies the source image's sRGB and alpha channels before the canvas composites it.
  • Keep the original image reusable for other draws, preserve existing crop coordinates, and support Bind(ArgColor, ...) on a tint.
  • Add one shared pixel fixture for differently tinted draws, partial alpha, a clipped source rectangle, and reusing the original image.

Verification

  • Shared pixel test passed on macOS, iOS Simulator, Android on a Pixel 3 XL, Chrome, Linux in GTK on Xvfb, and Windows through Direct2D bitmap readback.
  • The focused Canvas recording, damage and image-cache cases passed. The TSX Canvas package retry passed both tests after a local Go cache error.
  • Windows and Android CI passed the pixel test on this PR's head.
  • The local build and vet passed desktop, Android arm64 and x64, web, HarmonyOS Go/Wasm, and all four mini-program targets. Apple CI passed iOS, tvOS, and watchOS build and vet after the local check encountered missing Go cache entries.
  • HarmonyOS Go/Wasm tests passed. Device pixel coverage remains open for HarmonyOS and mini programs.

HarmonyOS

The ArkTS template implements tint in a separate offscreen canvas. The committed padded host still needs to be rebuilt with OpenHarmony API 26 and tested on an emulator. The roadmap records the remaining work.

@houko houko changed the title Add per-draw canvas image tinting feat(canvas): add per-draw image tinting Nov 21, 2026
@github-actions github-actions Bot added enhancement New feature or request conflict Conflicts with the base branch; resolve it first labels Nov 21, 2026
@houko
houko force-pushed the feat/canvas-image-tint-1111 branch from 3470605 to 8ff9227 Compare November 21, 2026 17:39
@houko

houko commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Reviewed.

  • Rebased onto main and resolved the conflicts with offscreen images, pixel buffers on Android and DrawSVG: CHANGELOG, roadmap, docs and workflow keep both sides; Android's image() now reads the tint flag and applies the ColorMatrixColorFilter for both pixel-buffer pictures and decoded images; classes.dex/jar rebuilt from the merged Java.
  • Tint now also applies to offscreen image sources, which the original branch predated: Apple tints the per-draw offscreen CGImage (released after the draw), Linux keeps one tinted Cairo surface on the offscreen entry, Windows reads the offscreen Direct2D bitmap back once through a CPU-readable bitmap and caches a tinted copy on the entry, and the web passes readable/NewCanvas to the offscreen player and serves offscreen canvases through loadCanvasImage. Android and mini programs draw no offscreen images at all yet, so there is nothing to tint there.
  • The shared pixel test (TestCanvasImageTint in the capture package and the Windows native test) now runs the same sample from an encoded PNG, a pixel buffer and an offscreen image; the offscreen case is skipped on Android.
  • Checked the tint math in TintImagePixels for straight and premultiplied layouts, the cache release paths on eviction, frame turnover and slot reset, and the TSX drawTintedImage argument handling and Bind(ArgColor).
  • Built and vetted linux, windows, js/wasm (web, canvas2d, mini program, HarmonyOS), android and darwin; ran driver, tsx, android, harmony and apple package tests.

@github-actions github-actions Bot removed the conflict Conflicts with the base branch; resolve it first label Nov 21, 2026
@houko
houko enabled auto-merge (rebase) November 21, 2026 17:39
@github-actions github-actions Bot added the conflict Conflicts with the base branch; resolve it first label Nov 21, 2026
@houko
houko force-pushed the feat/canvas-image-tint-1111 branch from 8ff9227 to f916d73 Compare November 21, 2026 17:47
@github-actions github-actions Bot removed the conflict Conflicts with the base branch; resolve it first label Nov 21, 2026
@houko
houko disabled auto-merge November 21, 2026 18:25
@houko

houko commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main again, with the Android runtime rebuilt. Auto-merge is off. Since dc896db on main, TestCommittedHostMatchesTemplates requires the committed HarmonyOS host (cmd/nsgo/harmony/host/) to be rebuilt whenever the templates change. This PR changes templates/entry/src/main/ets/pages/Index.ets, so the test job will fail until cmd/nsgo/harmony/host/build.sh is run with the OpenHarmony API 26 SDK and its outputs (host/ets/*.abc, host-templates.sha256) are committed. None of the build machines available to the review loop has that SDK (DevEco on the Mac Studio has API 22, the local command-line tools have API 24).

Before this rebase, all required checks except the Apple ones passed on f916d73. That includes test, windows, android and Gallery (web), which run the tint pixel test on encoded, pixel-buffer and offscreen sources.

@houko
houko force-pushed the feat/canvas-image-tint-1111 branch from f916d73 to da853b3 Compare November 21, 2026 18:25
@github-actions github-actions Bot added the conflict Conflicts with the base branch; resolve it first label Nov 21, 2026
@houko
houko force-pushed the feat/canvas-image-tint-1111 branch from da853b3 to e5ce885 Compare November 22, 2026 04:59
@github-actions github-actions Bot added conflict Conflicts with the base branch; resolve it first and removed conflict Conflicts with the base branch; resolve it first labels Nov 22, 2026
@houko
houko force-pushed the feat/canvas-image-tint-1111 branch from e5ce885 to d92dbba Compare November 22, 2026 08:18
@github-actions github-actions Bot removed the conflict Conflicts with the base branch; resolve it first label Nov 22, 2026
@houko
houko force-pushed the feat/canvas-image-tint-1111 branch from d92dbba to 6af2f00 Compare November 22, 2026 11:14
@houko

houko commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. Rebased onto main, merged the tint with main's image sampling and textured meshes (Android carries nearest and tinted in one flags byte; Windows, Apple, Linux and the web keep both the mesh texture caches and the tinted copies), and split out the HarmonyOS host change so the committed host stays in sync with its templates; HarmonyOS draws tinted images untinted for now, as the docs, roadmap and changelog fragment say. The shared tint pixel sample runs on Linux, the web, Android, the iOS simulator and Windows, and TSX recording is covered in tsx/elements_test.go.

@houko
houko force-pushed the feat/canvas-image-tint-1111 branch from f58fe64 to ee0f84c Compare November 22, 2026 15:13
@houko
houko merged commit 942f83a into nsgo-dev:main Nov 22, 2026
9 of 10 checks passed
houko added a commit that referenced this pull request Nov 23, 2026
Restores the HarmonyOS part taken out of #1200: canvasOp carries the tint for tinted DrawImage ops, and the ArkTS canvas multiplies the PixelMap's bytes by it in an offscreen context, keeping the last tinted image.
houko added a commit that referenced this pull request Nov 23, 2026
Restores the HarmonyOS part taken out of #1200: canvasOp carries the tint for tinted DrawImage ops, and the ArkTS canvas multiplies the PixelMap's bytes by it in an offscreen context, keeping the last tinted image.
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.

1 participant