Bug 183720 - Complete OffscreenCanvas implementation
Summary: Complete OffscreenCanvas implementation
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Lord
URL:
Keywords: InRadar
: 254071 (view as bug list)
Depends on: 215462 215917 232908 179191 180833 182503 182685 182686 182921 183440 186759 197421 202394 202513 202525 202572 202573 202574 202793 202794 202797 202798 203146 204575 206055 206220 209809 218482 219088 224178 224179 225179 225304 225391 244877 244878 244919 247105 247107
Blocks: 243538
  Show dependency treegraph
 
Reported: 2018-03-17 00:48 PDT by Zan Dobersek
Modified: 2023-11-07 07:40 PST (History)
25 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zan Dobersek 2018-03-17 00:48:36 PDT
SSIA.
Comment 1 Sanjay Kumar 2019-07-20 06:56:57 PDT
Is this planed for near future?

Since webkit does not support Webp, OffscreenCanvas is the only performant way to convert such images on a background thread. Not having Offscreen canvas means no Webp (or any other image format not supported y Safari).

OffScreen canvas will also enables mapping engines such as Mapbox to render tiles on background threads - significantly speeding up maps.

It would be great if Webkit were to implement Offscreen canvas - it will unlock huge potential for the web.

Thank you for considering it a priority.
Comment 2 Chris Lord 2019-08-22 08:37:29 PDT
I'm working on updating/finishing Zan's patches.
Comment 3 Chris Lord 2019-09-19 09:29:37 PDT
Just to note that I'm still working on this, and my current work is available on GitHub here: https://github.com/Cwiiis/webkit/tree/offscreen-canvas

Many tests are passing and the 2d functionality is fairly complete, but there's still a fair amount of work to tidy it up and start submitting patches for review. I expect some of the choices I've made will need to be inspected and re-thought by people with more knowledge of the code-base.
Comment 4 Myles C. Maxfield 2019-10-10 11:33:53 PDT
Finishing OffscreenCanvas support with 2D rendering would be a fantastic addition to WebKit! Thanks for working on it! The WebKit team at Apple would be happy to help and answer any questions you have. We're really looking forward to seeing this happen!
Comment 5 Simon Fraser (smfr) 2019-10-10 11:49:21 PDT
One note of caution: it's going to be very hard for us to verify, via review, that you'd done all the correct locking to make off-main-thread canvas drawing, and all the called code (text, fonts, images etc) thread-safe. Anything you can do to convince us that you got it right will help with review. "I added some locking and it seems to work" won't be entirely convincing :)
Comment 6 Chris Lord 2019-10-11 01:49:19 PDT
(In reply to Simon Fraser (smfr) from comment #5)
> One note of caution: it's going to be very hard for us to verify, via
> review, that you'd done all the correct locking to make off-main-thread
> canvas drawing, and all the called code (text, fonts, images etc)
> thread-safe. Anything you can do to convince us that you got it right will
> help with review. "I added some locking and it seems to work" won't be
> entirely convincing :)

This is absolutely fair :) I've been making sure that all tests run in debug mode (there are a *lot* of thread-related asserts), but really I'm not sure how to best fully guarantee this. I'm reasonably confident that it's only the font bits that are worrisome...

Do you have any suggestions beyond relying on tests? Assuming we can get to the point where everyone is happy that there aren't any obvious concurrency issues, is this something we could land (perhaps disabled on release by default? What's the best way to go about that?) to increase testing?
Comment 7 Ashley Gullen 2019-11-25 06:56:56 PST
I'd like to point out that user gesture requirements equivalent to Chrome's "User Activation v2" are important for some OffscreenCanvas use cases. In our case we can host our entire game engine in a web worker, forwarding input events over postMessage, and posting back for certain DOM APIs not available in workers (e.g. requestFullscreen). If user activation is limited to synchronous callbacks in input events, this blocks the use of any input-restricted APIs (like requestFullscreen), which would block our use of OffscreenCanvas. With User Activation v2, the restrictions are relaxed enough that it keeps working and means we can use OffscreenCanvas. I'm not sure what the status of user gestures are in WebKit but it might be worth reviewing this for OffscreenCanvas.
Comment 8 Simon Fraser (smfr) 2021-03-29 11:39:28 PDT
<rdar://39882956>
Comment 9 Chris Lord 2021-04-22 16:29:12 PDT
Now that bug 224178 has landed, all major OffscreenCanvas features are now implemented, I believe, and enabled on Linux platforms. There's still a fair amount of work to solidify and optimise this implementation, and of course to enable it on all platforms, but the foundations are there. Hurray!
Comment 10 Kenneth Russell 2021-04-23 14:24:38 PDT
That's great news!

Looking forward to being able to do effective off-main-thread rendering via OffscreenCanvas in WebKit!
Comment 11 Jeffrey Gilbert 2021-10-29 08:37:19 PDT
Cross linking Mozilla ticket for this feature to track support level of this feature on the big 3: https://bugzilla.mozilla.org/show_bug.cgi?id=1390089
Comment 12 Jen Simmons 2023-10-25 12:22:05 PDT
*** Bug 254071 has been marked as a duplicate of this bug. ***
Comment 13 Michael Hagar 2023-11-03 09:56:27 PDT
I'm seeing that the WebGL context is supported on Mac OS Ventura on the main thread, but not the worker threads. This is causing a problem because we were doing the detection of the WebGL context on the main thread, and not the worker. And we are actually trying to use the WebGL context from a worker.

1. Was it intended that WebGL context support be added to Mac OS Ventura 17.1 (it wasn't in 17.0 on Ventura)

2. Can this be fixed in future releases of Safari on Ventura, so that either the WebGL context is not supported at all (main thread or worker), or the WebGL context be supported in the main thread *and* workers.
Comment 14 Michael Hagar 2023-11-03 09:57:22 PDT
The specific check we're doing (on the main thread) is this:

if (typeof OffscreenCanvas !== 'function') {
      return false;
    }

    const ofs = new OffscreenCanvas(1, 1);
    if (ofs.getContext('webgl')) {
      return true;
    }

    return false;
Comment 15 Ashley Gullen 2023-11-07 01:09:24 PST
That sounds similar to a problem we had with Safari 16.4-16.6 - it shipped OffscreenCanvas but with no support for WebGL in a worker, which broke all of our feature detection. It was a big problem for us and I wrote about it here: https://www.construct.net/en/blogs/ashleys-blog-2/safari-releases-development-1616

Even though this was not web compatible Apple shipped it anyway, but added a hack for our engine only (which we're now trying to get removed in issue 263010), so it will still have broken other content like yours.

However AFAIK from Safari 17.0+ WebGL is supported in OffscreenCanvas. So things ought to be working from there.
Comment 16 Kimmo Kinnunen 2023-11-07 02:51:12 PST
>Can this be fixed in future releases of Safari on Ventura, so that either the WebGL context is not supported at all (main thread or worker), or the WebGL context be supported in the main thread *and* workers.

Given not everybody updates when the update is available, some clients would still run into the issue.

The recommended way would be to detect the Worker feature by running the feature detection in a Worker task.

OffscreenCanvas and Worker are related but orthogonal concepts, so disabling OffscreenCanvas on main thread is likely not feasible.
Comment 17 Kimmo Kinnunen 2023-11-07 03:00:48 PST
Safari 17.1 on macOS 13 Ventura does not support WebGL in Web Workers.

(You can see the setting in Settings, Advanced, Show features for web developers then Feature Flags, search for "WebGL")
Comment 18 Michael Hagar 2023-11-07 07:40:47 PST
Yes, we're now updating our code to run the OffscreenCanvas feature detection in the worker itself. 

I think my confusion was that on Safari 17.1 on Mac OS Sonoma, WebGL in Workers is supported, but it is not on Safari 17.1 on Mac OS Ventura. So I thought it was maybe a bug that WebGL in Workers is not supported on Safari 17.1 on Mac OS Ventura, but it sounds like that's the intended behavior.

I guess there's nothing for Safari to do now, but here are my thoughts:

It is confusing for developers when feature support differs by OS instead of Safari version, and doubly so when this is not mentioned in the release notes. I was going off of the release notes here: https://developer.apple.com/documentation/safari-release-notes/safari-17-release-notes#New-Features , which I took to mean that full (main thread and worker)WebGL OffscreenCanvas is supported on Safari 17+, regardless of the OS. While it is still our responsibility to test with the beta versions, I would have not thought to test on both Sonoma and Ventura for this.