I have a very large html canvas element covering a solid background. I would assume that a lot of cpu could be saved when scrolling/panning if the browser did not blend the canvas to elements behind it (in this case, a solid color).
Is it possible to remove the canvas alpha channel? Should this be left up to browsers to detect and optimize for? Or would speed gains be insignificant?
MDN suggests setting the alpha option in the canvas context:
If your application uses canvas and doesn’t need a transparent backdrop, set the
alpha
option tofalse
when creating a drawing context withHTMLCanvasElement.getContext()
. This information can be used internally by the browser to optimize rendering.
var ctx = canvas.getContext('2d', { alpha: false });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With