Skip to content

OffscreenCanvas new commit solution #3587

Closed

Description

@fserb

Following up on the discussion that happened on W3C Tag review on OffscreenCanvas. There were some concerns that commit() was a bit of a duplicate solution for the frame rendering problem.

The 3 main issues that emerged from this conversation were:

  • We don't want a separate mechanism to solve the same case that RequestAnimationFrame solves. Current commit() doesn't add new capabilities and solve the same problem as RAF.
  • We want a solution that addresses future needs by WebXR and friends.
  • We want to address WebAssembly's existing code bases need for a way to commit frames on a busy-loop.

Trying to solve all this, we have a modified proposal for OffscreenCanvas animation.

Details can be found in the link, but in summary, we are proposing:

  • A new RequestAnimationProvider mixin that is implemented by Window, WorkerGlobalScope and eventually XRSession.
  • an OffscreenCanvasContext.commit() function that blocks until the UA is ready to start receiving commands for the new frame. This enables busy-loop on worker type of applications.

The writing is not spec ready, but we would really like to have input from @whatwg/canvas as soon as possible while we begin to implement those changes.

Activity

  1. guest271314 commented on Mar 22, 2018

    @guest271314
    Contributor

    At https://github.com/junov/OffscreenCanvasAnimation/blob/master/OffscreenCanvasAnimation.md

    The animation frames are propagated via commit() to a placeholder canvas element that is in a visible document.

    Why is a <canvas> element within a visible document necessary?

  2. guest271314 commented on Mar 22, 2018

    @guest271314
    Contributor

    Has AudioContext (see https://stackoverflow.com/a/40691112) been considered for usage instead of requestAnimationFrame?

  3. guest271314 commented on Mar 22, 2018

    @guest271314
    Contributor

    Another use case for an OffscreenCanvas would be to decode both specific time slice of one or more video files represented as ArrayBuffer (in addition to an HTMLVideoElement), possibly faster than real-time, returning only those portions of one or more files as ImageBitmaps.

  4. junov commented on Mar 22, 2018

    @junov
    Member

    Good point about the visible document thing. We don't really need that constraint. It just creates an explicit path to a display device that can provide a vsync heartbeat. But we don't need the connection to be that explicit.

    Regarding AudioContext, we want to avoid using APIs for thing that were not their original purpose because it can lead to all sort unintended weird bugs. In this particular case, AudioContext is unable to apply GPU backpressure. This can cause the browser to hang if the app is pumping out rendering instructions faster than the GPU can process them. A purposely designed API on the other hand, can throttle down the frame rate when the GPU can't keep up, ensuring that the rendering backlog is never more than X frames behind.

  5. added
    topic: canvas
    on Mar 23, 2018
  6. smaug---- commented on Apr 24, 2018

    @smaug----

    an OffscreenCanvasContext.commit() function that blocks until the UA is ready to start receiving commands for the new frame. This enables busy-loop on worker type of applications.

    This is very much unclear. Why do we want to block anything and possibly miss some frames if calculating a new frame after commit() returns takes too much time?

  7. fserb commented on Apr 24, 2018

    @fserb
    ContributorAuthor

    @smaug----, not sure if I get your question. We want to block because an application can generate frames much faster than the UA can consume, right? (either because of display sync, or because the UA is busy). This doesn't mean that the UA needs to block at all (it can triple or quad buffer), but that it CAN block if it's being overwhelmed by frames.

    The way this was phrased was an attempt to capture a similar behavior to SwapBuffers on desktop graphics APIs.

  8. smaug---- commented on Apr 24, 2018

    @smaug----

    aha, " it CAN block if it's being overwhelmed by frames." is the missing piece.
    Not clear from 'an OffscreenCanvasContext.commit() function that blocks until the UA is ready to start receiving commands for the new frame. '

  9. fserb commented on Apr 24, 2018

    @fserb
    ContributorAuthor

    Ahn, I see. I thought it was implied from the "is ready", but I'll clarify it on the draft change.

  10. fserb commented on May 9, 2018

    @fserb
    ContributorAuthor

    Proposed change: #3677

  11. added 2 commits that reference this issue on Feb 15, 2019
    f4ef7de
    3845569
  12. added a commit that references this issue on May 18, 2025
    3d9b41d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    normative changetopic: canvas

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions