Skip to content

[web] Adopt single-context OffscreenCanvas rendering on Safari and Firefox (blocked by slow ImageBitmap transfer) #145420

Open

Description

@harryterkelsen

Use case

Flutter Web has adopted a rendering strategy making use of an OffscreenCanvas which acts as a WebGL surface for Skia to render to. The rendering is then displayed to the user by calling transferToImageBitmap to create a BitmapImage from the contents of the OffscreenCanvas, and then by calling transferFromImageBitmap on a bitmaprenderer canvas in the DOM, which is shown to the user. There may be more than one bitmaprenderer canvas (for example, if there are platform views in the Flutter scene which require overlay canvases), but there is only one OffscreenCanvas (and therefore only one WebGL context). Having only a single WebGL context allows Flutter Web to eliminate an entire class of bugs arising from improperly copying GL resources between more than one GL context.

Using transferToImageBitmap/transferFromImageBitmap is very fast on Chrome, since it just uses a texture saved on the GPU to transfer the rendering from the OffscreenCanvas to the bitmaprenderer canvas. However, on Firefox and Safari, calling transferToImageBitmap is significantly slower, because transferToImageBitmap incurs a very expensive call to read all of the pixels in the canvas to create the bitmap image. In practice, this made rendering using transferToImageBitmap untenable on Firefox and Safari since it caused considerable jank. So, on Firefox and Safari we have to fall back on an old (and bug-prone) rendering strategy using many WebGL-backed canvases.

Proposal

This issue tracks the bugs in Firefox and Safari, which are aware of the performance issues with transferToImageBitmap and working on addressing them.

Firefox issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1788206

Safari issue: https://bugs.webkit.org/show_bug.cgi?id=234920 and https://bugs.webkit.org/show_bug.cgi?id=267291

Once the performance issues are addressed in Firefox and Safari, we can remove the alternate multi-surface rendering strategy and keep only the OffscreenCanvas-based strategy.

Activity

  1. added
    c: performanceRelates to speed or footprint issues (see "perf:" labels)
    c: renderingUI glitches reported at the engine/skia or impeller rendering level
    e: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Web
    P2Important issues not at the top of the work list
    e: web_skwasmSkwasm rendering backend for web
    team-webOwned by Web platform team
    triaged-webTriaged by Web platform team
    on Mar 19, 2024
  2. harryterkelsen commented on Mar 20, 2024

    @harryterkelsen
    ContributorAuthor

    Update:

    Mozilla requested a built Flutter app to help them see how Flutter Web makes use of createImageBitmap/transferToImageBitmap: https://bugzilla.mozilla.org/show_bug.cgi?id=1788206

    I uploaded a build of the example app and pointed to where in the code we use createImageBitmap

  3. changed the title [-][web] Remove multi-Surface rendering for Firefox and Safari once they have efficient support for `transferToImageBitmap`/`transferFromImageBitmap`[/-] [+][web] Adopt single-context OffscreenCanvas rendering on Safari and Firefox (blocked by slow ImageBitmap transfer)[/+] on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2Important issues not at the top of the work listbrowser: firefoxonly manifests in Firefoxbrowser: safari-iosonly manifests in Safari on iOSbrowser: safari-macosonly manifests in Safari on macOSc: performanceRelates to speed or footprint issues (see "perf:" labels)c: renderingUI glitches reported at the engine/skia or impeller rendering leveldependency: firefoxThis bug requires a fix in Firefoxe: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Webe: web_skwasmSkwasm rendering backend for webteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions