Skip to content

feat(harmonyos): tint canvas images - #2016

Merged
houko merged 4 commits into
mainfrom
feat/harmony-image-tint-2003
Nov 23, 2026
Merged

houko merged 4 commits into
mainfrom
feat/harmony-image-tint-2003

Conversation

@houko

@houko houko commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #2003, #1111

What

This restores the HarmonyOS half of canvas image tinting that was taken out of #1200. It is the patch from #2003, plus the host rebuild the patch was waiting for.

  • Go: canvasOp carries tint for tinted DrawImage ops. A zero (transparent black) tint is still sent.
  • ArkTS: CanvasView draws the PixelMap into an OffscreenCanvasRenderingContext2D, multiplies each RGBA byte by the tint over 255 and draws the result. Tinted copies are kept per source image and tint, so several tinted images or tints in one drawing each hit their own copy. A copy that two paints in a row did not draw is released with PixelMap.release() (not right after drawing, since the Canvas may still read the last paint's), and the rest are released in aboutToDisappear. A tint that changes every frame, such as one bound to ArgColor, still costs a JS pass over the image's pixels per change. Only images from bytes or the app's resources are tinted, since the HarmonyOS canvas does not draw pixel buffers or offscreen images yet.
  • Docs: the HarmonyOS exceptions in the canvas docs (en/zh), docs/architecture/canvas.md and skills/nsgo/references/components.md now say HarmonyOS tints images from bytes or the app's resources but is not yet checked on a device. The roadmap row's criterion is the shared pixel test's encoded case, with a status clause and harmonyos: tint canvas images and rebuild the committed host #2003 linked. The changelog fragment uses (#2003 by @houko), and feat(canvas): add per-draw image tinting #1200's fragment drops "except HarmonyOS" so one release does not say both.
  • Committed host: rebuilt with cmd/nsgo/harmony/host/build.sh, using the OpenHarmony 7.0 public SDK (26.0.0.38) and hvigor 6.26.20 (see HarmonyOS: make the committed host rebuildable (toolchain recipe, or rebuild it in CI) #2015). The ArkTS compiles against API 26.

Tests

  • New TestCanvasImagesCarryTheirTint (js/wasm): tinted, zero-tint and untinted image ops.
  • TestCanvasImageTint now skips its pixels and offscreen cases on HarmonyOS, which does not draw those sources yet.
  • cmd/nsgo/harmony: 21 passed, including TestCommittedHostMatchesTemplates.
  • go tool nsgo check -target harmonyos: vetted.

Still open on #2003

TestCanvasImageTint (encoded) has not run on a HarmonyOS emulator or device, and the tint cache's release timing and memory use have not been observed on one.

Screenshots

None. Not captured on a HarmonyOS device.

@github-actions github-actions Bot added enhancement New feature or request size/L documentation Improvements or additions to documentation macOS iOS Windows Linux Web Android Mini-program core tsx cli ci conflict Conflicts with the base branch; resolve it first labels Nov 22, 2026
@houko
houko force-pushed the feat/harmony-image-tint-2003 branch from d8719ab to be4ec2a Compare November 22, 2026 14:29
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.
…ase them

The one-entry cache missed on every paint with two tinted images or one image in two tints, and never released the PixelMap it replaced. The canvas now keys tinted copies by source image and tint, releases a copy two paints in a row did not draw, and releases the rest when it disappears. The docs, roadmap and changelog now say HarmonyOS tints only images from bytes or the app's resources, and the shared tint pixel test skips its pixel-buffer and offscreen cases there.
Built with cmd/nsgo/harmony/host/build.sh, the OpenHarmony 7.0 public SDK (26.0.0.38) and hvigor 6.26.20.
@houko
houko force-pushed the feat/harmony-image-tint-2003 branch from be4ec2a to a769d4d Compare November 23, 2026 00:09
@houko
houko marked this pull request as ready for review November 23, 2026 00:10
@github-actions github-actions Bot added size/M and removed size/L labels Nov 23, 2026
@houko
houko merged commit a19c0d6 into main Nov 23, 2026
17 of 25 checks passed
@houko
houko deleted the feat/harmony-image-tint-2003 branch November 23, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android ci cli 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/M tsx Web Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant