Skip to content

feat(canvas): draw NativeScript views into a canvas on Linux - #256

Merged
triniwiz merged 1 commit into
masterfrom
feat/html-in-canvas-linux
Nov 18, 2026
Merged

triniwiz merged 1 commit into
masterfrom
feat/html-in-canvas-linux

Conversation

@triniwiz

@triniwiz triniwiz commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Includes #254 and #255: merge those first.

HTML-in-Canvas on NativeScript Linux. A content="drawable" canvas now hosts its children on GTK 4, and drawElementImage, texElementSubImage2D, drawElementImageToTexture, paint events, captureElementImage and element geometry work as on iOS and Android.

Change

NSCDrawableHost (canvas-napi, host/linux/drawable.rs)

  • The canvas widget holds each child in an NSCDrawableSlot and allocates it, but never draws it. A slot is allocated with the transform the child was last drawn with and sized to the drawn part (canvasClip), with overflow hidden. GTK's own picking therefore sends input to where the view appears and stops at the clip. A child with no geometry is allocated outside the canvas.
  • The canvas snapshots its children into a scratch snapshot, which keeps each view's render node current. A GtkWidgetPaintable per drawable view reports when that node changes.
  • Snapshots are rendered from the render node by the window's GSK renderer, so GL content (other canvases) is included.
  • Per frame, JS makes one update() call, which returns the changed views and their sizes. It makes no GTK calls of its own. Geometry is passed as a Float64Array and only when it changed. A press on a hosted view no longer moves focus to the canvas.

Shared Node-API canvas: children are measured at the canvas width and stacked, as on iOS (napi-host.ts).

The htmlincanvas spec suite now runs on Linux, with GTK picking checks for the hit-testing tests and a new test that a source rect limits hit testing to the drawn part.

Verified

Pop!_OS 24.04, GTK 4.14, COSMIC Wayland, Mesa (Intel Iris Xe), apps/demo-linux with this branch's canvasnative.node:

  • htmlincanvas 25/25 on three runs, including WebGPU on a real adapter.
  • 2d 182/182, lifecycle 14/14, canvassource 18/18, webgl 96/96, offscreen 64/64.
  • A rotated 280 DIP form (label, entry, button) drawn by drawElementImage every frame: the drawable tick averages 0.07 ms a frame idle (0.16 ms max), and 0.33 ms (2.6 ms max) while the form changes ten times a second, with 29 paint events for 30 changes (one frame can carry two).

Hit testing follows the geometry of the canvas's own children only: a drawable view nested deeper gets input through its top-level ancestor's geometry.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3ec6055c-67d5-40cd-87d5-465e434b0d9b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@triniwiz
triniwiz force-pushed the feat/html-in-canvas-linux branch 3 times, most recently from e952613 to 7fbbaaf Compare November 18, 2026 15:34
HTML-in-Canvas on GTK 4. A content="drawable" canvas holds each child
in a slot the canvas widget allocates but never draws: the slot is
placed with the transform the child was last drawn with and clipped to
the drawn part, so GTK's own picking sends input where the view
appears. The canvas snapshots its children into a scratch snapshot to
keep their render nodes current; a GtkWidgetPaintable per drawable view
reports when that node changes, and the window's GSK renderer renders
it into the snapshot.

The per-frame work is native (NSCDrawableHost in canvas-napi): JS makes
one update() call a frame and no GTK calls. Geometry is sent as a
Float64Array, and only when it changed. A press on a hosted view no
longer moves focus to the canvas.

Node-API canvases now measure their children at the canvas width and
stack them, as on iOS. The htmlincanvas spec suite runs on Linux, with
a new test that a source rect limits hit testing to the drawn part.
@triniwiz
triniwiz force-pushed the feat/html-in-canvas-linux branch from 7fbbaaf to 3f64be2 Compare November 18, 2026 15:35
@triniwiz
triniwiz merged commit 1380399 into master Nov 18, 2026
26 of 28 checks passed
@triniwiz
triniwiz deleted the feat/html-in-canvas-linux branch November 18, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant