- From: Robert O'Callahan <robert@ocallahan.org>
- Date: Mon, 23 Mar 2015 10:02:43 +1300
- To: Rik Cabanier <cabanier@gmail.com>
- Cc: WHATWG <whatwg@whatwg.org>, Jake Archibald <jaffathecake@gmail.com>, Ian Hickson <ian@hixie.ch>, Ashley Gullen <ashley@scirra.com>
I'm getting confused as to what the problem is. To restate the advantages of async toBlob: suppose I have code that does drawStuffTo(context); context.canvas.toBlob().then(callback); // 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 drawStuffTo(context); context.canvas.toBlob().then(callback); drawStuffTo(context); 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 available. 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. Rob -- oIo otoeololo oyooouo otohoaoto oaonoyooonoeo owohooo oioso oaonogoroyo owoiotoho oao oboroootohoeoro oooro osoiosotoeoro owoiololo oboeo osouobojoeocoto otooo ojouodogomoeonoto.o oAogoaoiono,o oaonoyooonoeo owohooo osoaoyoso otooo oao oboroootohoeoro oooro osoiosotoeoro,o o‘oRoaocoao,o’o oioso oaonosowoeoroaoboloeo otooo otohoeo ocooouoroto.o oAonodo oaonoyooonoeo owohooo osoaoyoso,o o‘oYooouo ofooooolo!o’o owoiololo oboeo oiono odoaonogoeoro ooofo otohoeo ofoioroeo ooofo ohoeololo.
Received on Sunday, 22 March 2015 21:03:08 UTC