Skip to content

feat(web): honor WindowOptions::transparent on WebGPU, WebGL2, and CPU 2D canvases - #3026

Merged
opencodejr[bot] merged 1 commit into
devfrom
bot/issue-3014
Dec 1, 2026
Merged

opencodejr[bot] merged 1 commit into
devfrom
bot/issue-3014

Conversation

@opencodejr

@opencodejr opencodejr Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Honors App::window_options(WindowOptions { transparent: true, ..Default::default() }) on web so page-level backgrounds (CSS, Three.js, video) show through when the root element has no opaque fill. Thanks to @kebab-casee for reporting the gap and validating the WebGPU/WebGL2 behavior in #3014.

Precedent

  • Follows Rune's existing WindowOptions::transparent API used by macOS, Windows, Linux, and headless (crates/rune/src/tooling/headless.rs, crates/rune/src/window/host/create/surface.rs), avoiding a duplicate builder or breaking AppSpec literals.
  • Follows W3C WebGPU GPUCanvasAlphaMode ("premultiplied" when transparent, "opaque" by default), Khronos WebGL2 default context attributes ({ alpha: true, premultipliedAlpha: true }), and WHATWG HTML Canvas 2D straight-alpha ImageData.

Changes

  • crates/rune/src/platform/web_math.rs: added SurfaceAlpha / select_surface_alpha (picks CompositeAlphaMode::PreMultiplied on WebGPU when offered, falls back to opaque if unavailable, keeps Opaque on WebGL2 to satisfy wgpu-hal's GLES advertised capabilities while keeping transparent: true because WebGL2 contexts default to premultiplied alpha, and keeps opaque apps Opaque); propagated app.window_options.transparent to RuntimeCore::transparent in start_web_runtime.
  • crates/rune/src/platform/web/app.rs, crates/rune/src/platform/web.rs, crates/rune/src/platform/web/gpu.rs, crates/rune/src/platform/web/handover.rs, crates/rune/src/platform/web/recovery.rs, crates/rune/src/platform/web/draw.rs: threaded transparent through PendingApp, Browser, gpu_side, canvas_config, CPU-first startup, handover, WebGPU recovery, WebGL2 restore, and GPU-loss CPU fallback.
  • crates/rune/src/platform/web/cpu_canvas.rs, crates/rune/src/platform/web/cpu_canvas.js: creates the CPU 2D canvas with { alpha: transparent }, disables subpixel LCD text and source-over scroll self-blit when transparent, and unpremultiplies 0 < a < 255 BGRA pixels to straight RGBA for ImageData in putCpuRect while keeping the opaque path unchanged.
  • crates/rune/src/window/spec/options.rs, crates/rune/src/app/options.rs, changelog/unreleased/2026-12-01-web-transparent-canvas.md: updated docs and added changelog entry.
  • crates/rune/src/platform/web_math_tests.rs, crates/rune/src/platform/web/cpu_canvas.test.mjs: added unit tests for opaque defaults, WebGPU/WebGL2 alpha mode selection, runtime clear color, and transparent putCpuRect unpremultiplication (aligned full-canvas, aligned sub-rect, and unaligned fallback); verified both fail when the implementation changes are reverted.

Testing

  • cargo check -p rune -p rune-kit
  • cargo lint-wasm and cargo lint-webgl (both green with -D warnings)
  • RUNE_ALLOW_NO_GPU=1 cargo test -p rune --lib --features rune/test-gpu-noop platform::web_math (73 passed)
  • node --test crates/rune/src/platform/web/*.test.mjs (113 passed)
  • RUNE_ALLOW_NO_GPU=1 cargo test -p rune -p rune-mermaid -p rune-kit --features rune-kit/markdown,rune-kit/mermaid,rune/test-gpu-noop --no-fail-fast (rune-kit, rune-mermaid, and all 549 rune doctests passed)
  • bash scripts/file-size.sh (0 errors)

Also seen

  • In the GPU-less Linux container under RUNE_ALLOW_NO_GPU=1 with rune/test-gpu-noop, 9 unrelated tests failed at runtime: render::upload::atlas_tests::{a_page_zero_growth_resends_that_page_only, a_small_icon_update_uploads_only_its_rectangle, direct_dirty_mutation_uploads_full_width_pixels, fill_masks_tracks_dirty_rect_for_sub_rect_and_byte_exact_handover, give_back_all_frees_atlas_rect_scratch_and_recovers_on_next_upload} (no-op GPU readback zeros), runtime::font_families::tests::live_runtime_async_system_fallbacks_wake_relayout_and_preserve_waker_on_replace, runtime::selection::selectable::virtual_selection_tests::cmd_a_and_select_all_text_over_55_virtual_rows_copy_every_row, window::state::heap_trim_tests::platform_guard_matches_target_abi_and_coalesces_live_trim, and heap_trim_guards::glibc_detection_coalescing_cooldown_and_app_opt_out.
  • Web code was not run in a real browser window in this headless Linux environment.

Closes #3014

@opencodejr
opencodejr Bot merged commit d321d0d into dev Dec 1, 2026
5 checks passed

@kebab-casee kebab-casee 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.

lgtm (need more review: pending)

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.

Web: the canvas is opaque, so a page-level background (three.js, CSS) can't sit behind the app

1 participant