Repository navigation
feat(web): honor WindowOptions::transparent on WebGPU, WebGL2, and CPU 2D canvases - #3026
Merged
Merged
Conversation
kebab-casee
approved these changes
Dec 1, 2026
kebab-casee
left a comment
There was a problem hiding this comment.
lgtm (need more review: pending)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
WindowOptions::transparentAPI 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 breakingAppSpecliterals.GPUCanvasAlphaMode("premultiplied"when transparent,"opaque"by default), Khronos WebGL2 default context attributes ({ alpha: true, premultipliedAlpha: true }), and WHATWG HTML Canvas 2D straight-alphaImageData.Changes
crates/rune/src/platform/web_math.rs: addedSurfaceAlpha/select_surface_alpha(picksCompositeAlphaMode::PreMultipliedon WebGPU when offered, falls back to opaque if unavailable, keepsOpaqueon WebGL2 to satisfywgpu-hal's GLES advertised capabilities while keepingtransparent: truebecause WebGL2 contexts default to premultiplied alpha, and keeps opaque appsOpaque); propagatedapp.window_options.transparenttoRuntimeCore::transparentinstart_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: threadedtransparentthroughPendingApp,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 andsource-overscroll self-blit when transparent, and unpremultiplies0 < a < 255BGRA pixels to straight RGBA forImageDatainputCpuRectwhile 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 transparentputCpuRectunpremultiplication (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-kitcargo lint-wasmandcargo 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 549runedoctests passed)bash scripts/file-size.sh(0 errors)Also seen
RUNE_ALLOW_NO_GPU=1withrune/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, andheap_trim_guards::glibc_detection_coalescing_cooldown_and_app_opt_out.Closes #3014