Skip to content

perf(web): replace softbuffer canvas present with direct put_image_data#1374

Open
irvingouj@Devolutions (irvingoujAtDevolution) wants to merge 1 commit into
masterfrom
perf/web-remove-softbuffer
Open

perf(web): replace softbuffer canvas present with direct put_image_data#1374
irvingouj@Devolutions (irvingoujAtDevolution) wants to merge 1 commit into
masterfrom
perf/web-remove-softbuffer

Conversation

@irvingoujAtDevolution

Copy link
Copy Markdown
Contributor

What

Removes the softbuffer dependency from ironrdp-web and presents canvas updates via the 2D context's put_image_data directly.

Why

The old render path did two full-surface pixel passes per frame (RGBA → u32 0RGB, then softbuffer repacks u32 → RGBA into a freshly allocated buffer) plus a per-frame allocation. The new path does a single copy of each dirty region into a reused RGBA scratch (alpha forced opaque) followed by put_image_data at the region origin.

Perf

Record/replay draw bench (dev wasm, headless Chromium), draw-stage median:

  • 4K: 1706 ms → 83 ms (~20×)
  • 1080p: 705 ms → 14 ms (~50×)

Byte-identical canvas output; unchanged framebuffer checksums. Mirrors the same fix already in IronVNC.

Notes

  • softbuffer is only removed from ironrdp-web; ironrdp-viewer (native) still uses it, so it remains in Cargo.lock.
  • Adds web-sys CanvasRenderingContext2d + ImageData features.
  • Scoped extract of a single commit from the experimental web-rendering work; no other changes.

The render path converted each dirty region RGBA -> u32 `0RGB`, then let
softbuffer repack u32 -> RGBA into a freshly allocated buffer every frame —
two pixel passes over the whole surface plus a per-frame allocation. Replace
it with the canvas's own 2D context: one copy of the region into a reused
RGBA scratch (alpha forced opaque) followed by put_image_data at the region
origin. softbuffer is dropped from ironrdp-web (still used by ironrdp-viewer).
Mirrors the same fix in IronVNC.

Measured with a record/replay draw bench (dev wasm, headless Chromium),
draw-stage median: 4K 1706ms -> 83ms (~20x), 1080p 705ms -> 14ms (~50x),
with byte-identical canvas output and unchanged framebuffer checksums.
@irvingoujAtDevolution

Copy link
Copy Markdown
Contributor Author

Same as VNC, remove softbuffer

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the ironrdp-web rendering path to remove the softbuffer dependency and present updated regions by uploading RGBA buffers directly to an HTML canvas via CanvasRenderingContext2d::put_image_data, aiming to reduce per-frame work and allocations.

Changes:

  • Replaces the softbuffer-based canvas present path with direct ImageData + put_image_data blits for dirty regions.
  • Removes the softbuffer dependency from ironrdp-web.
  • Enables additional web-sys features needed for 2D canvas rendering (CanvasRenderingContext2d, ImageData).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/ironrdp-web/src/canvas.rs Implements the new 2D-context put_image_data rendering path and removes the softbuffer surface logic.
crates/ironrdp-web/Cargo.toml Drops softbuffer dependency; enables required web-sys features for 2D canvas + ImageData.
Cargo.lock Updates lockfile dependency edges to reflect removal of softbuffer from ironrdp-web.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

})
}

/// Setting width/height resets the canvas backing store; the 2D context persists.
Comment on lines 43 to +45
pub(crate) fn resize(&mut self, width: NonZeroU32, height: NonZeroU32) {
self.surface.resize(width, height).expect("surface resize");
self.width = width;
self.canvas.set_width(width.get());
self.canvas.set_height(height.get());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants