/texture-bridge:migrating-to-forward-framesfrom texture-bridge
Replaces CPU-based Electron preview paths (capturePage polling, paint-event bitmap IPC, toBitmap/toPNG transfers, Syphon loopback) with @napolab/texture-bridge zero-copy GPU forwarding using forwardFrames or forwardSharedTexture.
Ships in texture-bridge. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
forwardFrames pushes a bridge's paint frames to any renderer WebContents as zero-copy GPU handles — full resolution, paint-rate, no readback. It replaces CPU preview paths (capturePage polling, bitmap IPC) with one registration per source.
Prerequisites: Electron 40+, and a @napolab/texture-bridge-renderer version that ships TextureBridge.forwardFrames (check bridge.forwardFrames exists in your installed node_modules types before starting; upgrade if not).
Applies when sources are TextureBridge instances and previews poll capturePage (or IPC bitmaps from paint events).
Delete: the capture timer, the bitmap IPC channel (send + ipcRenderer.on + putImageData/drawImage of bitmaps), and any downscale logic — receivers draw the full-resolution VideoFrame scaled by canvas.
Add (sender, main process): one line per source:
const forward = deck.bridge.forwardFrames(previewWindow.webContents, {
extraArgs: [deckIndex], // arrives verbatim as trailing onFrame args — the demux tag
});
// teardown: forward.dispose() — idempotent; bridge.dispose() also clears it
The option is extraArgs (an array). There is no sourceId, channel, or maxFps option. The handle's cleanup method is dispose(), not stop() or unsubscribe().
Add (receiver): the preview window consumes exactly like any shared-texture receiver — const receiver = bindSharedTextureReceiver(sharedTexture) once (sharedTexture from electron) + receiver.consume({ onFrame: (frame, deckIndex) => ... }), with bindSharedTextureReceiver imported from @napolab/texture-bridge-renderer/client (the /client subpath — the package root exports the main-process API only), in a preload, window running nodeIntegration: true, contextIsolation: false, sandbox: false. Full recipe (frame cloning, coalescing, rAF, cleanup): see the receiving-shared-textures skill.
Applies when you run your own offscreen window + paint handler (core tier) and currently copy pixels out for a monitor. Forward inside the same handler:
import { forwardSharedTexture } from "@napolab/texture-bridge-core/electron";
win.webContents.on("paint", (e) => { // stays sync — see below
const texture = e.texture;
if (!texture) return;
try {
void forwardSharedTexture(texture.textureInfo, monitorWC, [slot]); // fire-and-forget
sendTextureFromPaintEvent(sender, texture.textureInfo); // existing Syphon/Spout send
} finally {
texture.release(); // exactly once, on every path
}
});
forwardSharedTexture imports and releases its own imported texture internally (release-in-finally) — your e.texture.release() obligation is unchanged. It never throws synchronously; it resolves undefined or a ForwardDefect (target-destroyed / import-failed / send-failed) — check it if you want failure metrics, ignore it for best-effort.
Three properties of that handler are load-bearing, and adding forwarding is exactly when they get broken:
try/finally — sendTextureFromPaintEvent throws on native send failure. Releasing after a bare sequence leaks one paint texture per frame from the first failure onward, until the shared-texture pool starves and paint stops.await — the primitive's import and send dispatch both run before its first await, so releasing in the same tick is safe. Awaiting instead pins this paint texture for a full IPC round-trip.async paint handler converts a send throw into an unhandled rejection."error" event or frameDropped. A dead preview window never affects the live Syphon/Spout output, and vice versa — the two paths are fully independent per frame.bridge.dispose() destroys the offscreen window synchronously via destroy(). disposed listeners must not touch bridge.renderWindow.webContents; remove any external bridge.renderWindow.destroy() workarounds — a second destroy can throw.forwardFrames; verify Electron ≥ 40.forward.dispose() when a preview closes or a source disconnects; dispose before destroying source windows.| Mistake | Reality |
|---|---|
bridge.forwardFrames(wc, { sourceId }) / { channel } / { maxFps } | Only { extraArgs: [...] } exists. Rate control belongs to the receiver's rAF coalescing. |
forward.stop() / subscription.unsubscribe() | forward.dispose(). |
Expecting forward failures on bridge.on("error") | Wrong channel. bridge.on("forwardStatus") (or forwardFrames's onStatus) reports them as deduped state changes; with the primitive, read the resolved ForwardDefect yourself. |
Preview window with default webPreferences | Shared-texture consumption needs the receiver preload setup — see receiving-shared-textures skill. |
Calling frame.videoFrame.close() on the frame passed to onFrame | The consumer pool closes the original after your handler settles. clone() if you hold it; close only clones. |
Keeping a capturePage fallback "just in case" | Delete it once verified — a hidden 30fps readback timer defeats the migration. |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
8 skills in this plugin
/choosing-texture-bridge-apiUse when deciding which @napolab/texture-bridge API tier to use for a feature — simple vs core, Syphon/Spout output vs in-app preview/monitor, forwardSharedTexture vs forwardFrames — when reviewing an integration plan that uses the library, or when unsure whether a texture-bridge function, method, or option actually exists./delivering-imported-texturesUse when delivering a GPU texture to a renderer from the Electron main process — about to call `sharedTexture.importSharedTexture` / `sendSharedTexture` / `release()` by hand, deciding where `release()` belongs, wrapping delivery in try/finally or neverthrow tees to guarantee exactly-once release, writing the same deliver-and-release dance in a second module, or delivering a texture you imported yourself from a receiver's native handle./diagnosing-dead-frame-forwardsUse when forwarded frames stop arriving — a preview or monitor window that goes black or shows a "no signal" placeholder, a multiviewer deck frozen on its last frame, previews that die during a long session or for only some targets while Syphon/Spout output keeps working, a forwardFrames registration you suspect never delivered anything, or a dead preview with nothing in the logs./handling-texture-bridge-failuresUse when adding error handling, telemetry, or crash-safety to code that uses @napolab/texture-bridge — deciding whether a call needs a try/catch or a Result.fromThrowable wrapper, reviewing the failure handling of a texture-bridge integration, defining error classes for bridge or receiver operations, or diagnosing silently black output or a main-process crash from a bridge call./managing-frame-forward-lifecycleUse when registering or tearing down `TextureBridge.forwardFrames` targets — a monitor/multiviewer window the user can close and reopen, decks connected and disconnected repeatedly, a bridge disposed while forwards are still registered — or when about to add "destroyed"/"closed" listener bookkeeping, removeListener hygiene, isDestroyed guards, or try/catch around `forward.dispose()`, or when chasing a MaxListenersExceededWarning or a leak around forwarding./receiving-shared-texturesUse when implementing the receiving side of @napolab/texture-bridge shared-texture frames in an Electron renderer — consuming forwardFrames/forwardSharedTexture output, displaying createSharedTextureReceiver frames, building a multiviewer/preview grid, or debugging leaked VideoFrames, black canvases, or frames from a disconnected source reappearing.npx claudepluginhub naporin0624/electron-texture-bridge --plugin texture-bridgeOther plugins' skills for the same job