I'm getting confused as to what the problem is.

To restate the advantages of async toBlob: suppose I have code that does
  // no further drawing to the canvas

This has a few advantages over using getImageData and then encoding to JPEG
via JS in a Worker:
1) getImageData will stall the main thread until all canvas rasterization
is finished and the data has been read back from GPU memory. toBlob lets
the main thread run while those things happen. This is the biggest issue.
2) The first stage of JPEG compression is to convert the data to YUV 4:2:0,
which can be done on the GPU and produces a buffer which is only half the
size, so even after you've copied it by reading it back this uses no more
CPU+GPU memory, less GPU-to-CPU bandwidth, and will probably be faster. You
may be able to do even more JPEG compression on the GPU, depending on the
underlying architecture.
3) Using the browser's native JPEG encoder is probably a bit faster and
lighter-weight than JS in a Worker, especially due to SIMD. Browsers must
already have a native JPEG encoder to support canvas.toDataURL().

In the case where someone does
the browser has a few options. After rasterizing the first set of commands
you can make a copy in GPU memory. Or, you can apply #2 above and make a
YUV 4:2:0 copy using half the memory. Or, you can start the readback, and
delay rasterizing the second set of commands until the readback has
finished. You can vary the strategy depending on the amount of memory

If the browser is ever really low on memory, it can always stall everything
until JPEG encoding is done and intermediate buffers released. So there can
never be a memory-use advantage to making the promise fail.

oIo otoeololo oyooouo otohoaoto oaonoyooonoeo owohooo oioso oaonogoroyo
owoiotoho oao oboroootohoeoro oooro osoiosotoeoro owoiololo oboeo
osouobojoeocoto otooo ojouodogomoeonoto.o oAogoaoiono,o oaonoyooonoeo
osoaoyoso otooo oao oboroootohoeoro oooro osoiosotoeoro,o o‘oRoaocoao,o’o
oaonosowoeoroaoboloeo otooo otohoeo ocooouoroto.o oAonodo oaonoyooonoeo
osoaoyoso,o o‘oYooouo ofooooolo!o’o owoiololo oboeo oiono odoaonogoeoro
otohoeo ofoioroeo ooofo ohoeololo.

Reply via email to