Sign in

    moui_web_renderer

    Browser WebGPU renderer with Canvas2D fallback providers for MoUI

    moui
    renderer
    webgpu
    canvas2d
    web
    Download zip
    Author
    Version
    0.2.2
    License
    Apache-2.0
    Last updated
    2 days ago
    Downloads
    125

    Dependencies

    #WebGPU Wasm-GC Host Boundary

    render/webgpu_adapter is the only Web renderer path. It targets MoonBit wasm-gc and calls a browser-provided webgpu import module.

    This package intentionally does not depend on WIT/component today. The public boundary is kept thin so a future WIT/component migration can replace only the port implementation:

    WebGpuWasmRenderer -> WebGpuHostRendererPort -> wasm-gc webgpu imports today -> WIT/component resources later

    The rest of MoUI should depend on WebGpuWasmRenderer, WebGpuHostRendererPort, and the renderer facade concepts, not on individual import names.

    #Current Host Imports

    The browser loader must provide a webgpu import object with:

    capabilities: webgpu_available, adapter_ready, can_render strings: begin_create_string, string_append_char, finish_create_string surface: create_surface, surface_is_valid, surface_resize, surface_dispose renderer: create_renderer, renderer_is_valid, renderer_resize, begin_frame, clear, fill_rect, stroke_rect, fill_rounded_rect, stroke_rounded_rect, draw_text, draw_image, push_clip, pop_clip, push_transform, pop_transform, push_opacity, pop_opacity, present, renderer_dispose

    Opaque browser objects are represented as integer handles. That is deliberate: MoonBit wasm-gc host import stubs currently accept this ABI shape reliably, while direct opaque host resource types do not.

    #Future WIT Migration

    When MoonBit has a stable WIT/component path for wasm-gc, map the same conceptual operations to WIT resources:

    HostWebGpuSurface handle -> resource surface HostWebGpuRenderer handle -> resource renderer WebGpuHostRendererPort -> generated WIT adapter implementation

    The migration should keep backend/web and core draw-command conversion unchanged except for swapping wasm_gc_host_port() to a generated WIT-backed port.

    WebGpuHostError

    pub(all) suberror WebGpuHostError {
    Unavailable
    AdapterUnavailable
    DeviceUnavailable
    SurfaceUnavailable
    PipelineUnavailable
    InvalidResource
    HostError(String)
    } derive(Eq, ToJson,
    Debug
    )

    WebGpuHostError::equal

    WebGpuHostError::not_equal

    fn WebGpuHostError::not_equal(x : WebGpuHostError, y : WebGpuHostError) -> Bool

    WebGpuHostError::to_json

    WebGpuHostAdapterInfo

    pub struct WebGpuHostAdapterInfo {
    // private fields
    } derive(Eq, ToJson,
    Debug
    )

    WebGpuHostAdapterInfo::capabilities

    WebGpuHostAdapterInfo::description

    fn WebGpuHostAdapterInfo::description(self : WebGpuHostAdapterInfo) -> String

    WebGpuHostAdapterInfo::equal

    WebGpuHostAdapterInfo::imports

    WebGpuHostAdapterInfo::not_equal

    WebGpuHostAdapterInfo::surface_contract

    WebGpuHostAdapterInfo::to_json

    WebGpuHostCall

    WebGpuHostCall::equal

    WebGpuHostCall::not_equal

    fn WebGpuHostCall::not_equal(x : WebGpuHostCall, y : WebGpuHostCall) -> Bool

    WebGpuHostCall::to_json

    WebGpuHostCapabilities

    pub struct WebGpuHostCapabilities {
    // private fields
    } derive(Eq, ToJson,
    Debug
    )

    WebGpuHostCapabilities::adapter_ready

    fn WebGpuHostCapabilities::adapter_ready(self : WebGpuHostCapabilities) -> Bool

    WebGpuHostCapabilities::can_render

    fn WebGpuHostCapabilities::can_render(self : WebGpuHostCapabilities) -> Bool

    WebGpuHostCapabilities::equal

    WebGpuHostCapabilities::new

    fn WebGpuHostCapabilities::new(webgpu_available? : Bool, adapter_ready? : Bool, can_render? : Bool) -> WebGpuHostCapabilities

    WebGpuHostCapabilities::not_equal

    WebGpuHostCapabilities::to_json

    WebGpuHostCapabilities::webgpu_available

    fn WebGpuHostCapabilities::webgpu_available(self : WebGpuHostCapabilities) -> Bool

    WebGpuHostImportInfo

    pub struct WebGpuHostImportInfo {
    // private fields
    } derive(Eq, ToJson,
    Debug
    )

    WebGpuHostImportInfo::description

    fn WebGpuHostImportInfo::description(self : WebGpuHostImportInfo) -> String

    WebGpuHostImportInfo::equal

    WebGpuHostImportInfo::import_module

    fn WebGpuHostImportInfo::import_module(self : WebGpuHostImportInfo) -> String

    WebGpuHostImportInfo::new

    fn WebGpuHostImportInfo::new(import_module~ : String, target~ : String, surface_resource~ : String, renderer_resource~ : String, description? : String) -> WebGpuHostImportInfo

    WebGpuHostImportInfo::not_equal

    WebGpuHostImportInfo::renderer_resource

    fn WebGpuHostImportInfo::renderer_resource(self : WebGpuHostImportInfo) -> String

    WebGpuHostImportInfo::surface_resource

    fn WebGpuHostImportInfo::surface_resource(self : WebGpuHostImportInfo) -> String

    WebGpuHostImportInfo::target

    fn WebGpuHostImportInfo::target(self : WebGpuHostImportInfo) -> String

    WebGpuHostImportInfo::to_json

    WebGpuHostRendererPort

    pub struct WebGpuHostRendererPort {
    // private fields
    }

    WebGpuHostRendererPort::capabilities

    WebGpuHostRendererPort::create_renderer

    fn WebGpuHostRendererPort::create_renderer(self : WebGpuHostRendererPort, surface : WebGpuHostSurface) -> Unit raise WebGpuHostError

    WebGpuHostRendererPort::create_surface

    WebGpuHostRendererPort::dispose

    WebGpuHostRendererPort::image_resource

    WebGpuHostRendererPort::register_font_data

    fn WebGpuHostRendererPort::register_font_data(self : WebGpuHostRendererPort, family :
    FontFamily
    , data : Bytes) -> Unit

    WebGpuHostRendererPort::resize

    WebGpuHostRendererPort::submit

    WebGpuHostSurface

    pub struct WebGpuHostSurface {
    // private fields
    } derive(Eq, ToJson,
    Debug
    )

    WebGpuHostSurface::canvas_id

    fn WebGpuHostSurface::canvas_id(self : WebGpuHostSurface) -> String

    WebGpuHostSurface::equal

    WebGpuHostSurface::new

    WebGpuHostSurface::not_equal

    fn WebGpuHostSurface::not_equal(x : WebGpuHostSurface, y : WebGpuHostSurface) -> Bool

    WebGpuHostSurface::to_json

    WebGpuWasmRenderer

    pub struct WebGpuWasmRenderer {
    // private fields
    }

    WebGpuWasmRenderer::apply_image_resource_load_completion

    WebGpuWasmRenderer::dispose

    fn WebGpuWasmRenderer::dispose(self : WebGpuWasmRenderer) -> Unit

    WebGpuWasmRenderer::last_calls

    WebGpuWasmRenderer::last_fallback_plan

    WebGpuWasmRenderer::present_count

    fn WebGpuWasmRenderer::present_count(self : WebGpuWasmRenderer) -> Int

    WebGpuWasmRenderer::render

    WebGpuWasmRenderer::resize

    WebGpuWasmRenderer::surface

    WebGpuWasmRenderer::text_system

    WebGpuWasmRenderer::to_renderer_session

    adapter_info

    fn adapter_info() -> WebGpuHostAdapterInfo

    browser_canvas2d_fallback_capabilities

    canvas2d_fallback

    canvas_surface_contract

    create_browser_canvas2d_fallback_provider

    Build the browser Canvas2D fallback provider. The browser runtime exposes its Canvas2D implementation through the WebGPU-compatible host-import port, so this provider intentionally creates WebGpuWasmRenderer values instead of importing the WeChat-only canvas2d wasm host module.

    create_renderer

    fn create_renderer(canvas_id~ : String, logical_size~ :
    Size
    , scale_factor? : Double, port~ : WebGpuHostRendererPort) -> WebGpuWasmRenderer raise WebGpuHostError

    create_surface

    fn create_surface(canvas_id~ : String, logical_size~ :
    Size
    , scale_factor? : Double, port~ : WebGpuHostRendererPort) -> WebGpuHostSurface raise WebGpuHostError

    create_webgpu_provider

    Provider factory for the wasm-gc WebGPU adapter. Browser composition owns the canvas-specific renderer factory while this package owns negotiation and its capability declaration.

    create_webgpu_renderer

    fn create_webgpu_renderer(canvas_id~ : String, logical_size~ :
    Size
    , scale_factor? : Double) -> WebGpuWasmRenderer raise WebGpuHostError

    draw_commands_to_host_calls

    host_import_info

    fn host_import_info() -> WebGpuHostImportInfo

    providers

    Renderer-owned providers used by application diagnostics.

    renderer_descriptor

    required_capabilities

    fn required_capabilities() -> WebGpuHostCapabilities

    wasm_gc_host_port

    fn wasm_gc_host_port() -> WebGpuHostRendererPort

    webgpu

    Browser WebGPU provider. The canvas id is supplied by the opaque host surface after each browser window is created.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io