Question

How do I enable hardware acceleration for HTML5 canvas in JavaScript? Or is it not possible in JavaScript? I remember that I read somewhere about doing that using something CSS or Webgl but I cannot remember.

Was it helpful?

Solution 2

UPDATE: as mentioned in other answers, this is not the correct answer as the css trick doesn't influence 3d canvas.

What you probably remember is the CSS 'trick' that triggers accelerated display even if you don't really do 3d yourself:

A common way is using:

transform: translateZ(0);

in your css. (add the browser-prefixed versions if needed)

Please note that this is by no means an officially supported way of switching on hardware acceleration, it's just an (undocumented?) side-effect in some browsers.

OTHER TIPS

The answer marked correct is incorrect, as long as this question is about javascript for Canvas.

This only applies to regular DOM objects, not elements within a canvas:

transform: translateZ(0); // doesn't apply in Canvas

Canvas hardware acceleration will be available if your browser supports it and your computer has a GPU.

In some older browsers this has to be activated by the user in their browser settings.

Google Chrome activates it when available. You can check if your chrome is running HTML Canvas hardware acceleration by visiting the following chrome URL: Google Chrome GPU Page

Canvas hardware acceleration in Chrome has been introduced back in 2012.

You can see the example provided in the article here.

If your intention is to unleash the full power of GPU hardware acceleration in HTML, you should go with WEBGL. A good and easier way to get started with WEBGL is THREE.JS.

It's not necessarily a bad question, but you do have to research a little more. It's natively provided in nearly every modern browser (don't know about IE). So basically, you're not really able to turn it on or off, it just is there, and the only way to turn it off is through client, not server.

http://www.htmlgoodies.com/html5/client/unleash-the-power-of-hardware-accelerated-html5-canvas.html#fbid=F8_jSGY0u2D

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top