ai / offscreen-canvas

Polyfill for OffscreenCanvas to move Three.js/WebGL/2D canvas to Web Worker
MIT License
332 stars 13 forks source link

Nit, this isn't a polyfill #34

Open Pyrolistical opened 2 years ago

Pyrolistical commented 2 years ago

This doesn't work as expected on mac/safari as discussed in this other issue.

> [Mac/safari] will work, but use normal canvas without offscreen and web worker

So then this isn't a polyfill then? This is a library that wraps offscreen canvas if available.

To me a polyfill implements the API for platforms that don't support it using the standard interface. This library requires users to a non-standard interface.

Furthermore it would be ideal if the polyfill could actually provide the desired functionality, in this case being able to offload canvas work to another web worker.

I think this could be done with iframes and proxies.

sequenceDiagram
  main->>iframe: create canvas in iframe
  main->>worker: use this offscreen canvas proxy
  worker->>iframe: ctx.draw...
  worker->>iframe: ctx.draw...
  main->>+worker: getImageData
  worker->>+iframe: forwardImageData
  iframe-->>-main: ImageData
ai commented 2 years ago

It is too small project to spend time for improving it.

If you have a better idea, just implement it in new project. I will add a link to your project from README.md.