Bas Schouten has posted a lot about hardware accelerating Firefox, specifically with Direct2D and OpenGL. However, there’s been some confusion as to what it is we’re going to hardware accelerate, and how we’re going to do it. This blog post aims to be the definitive reference for hardware acceleration in Firefox.
Please note: We have committed to turning on certain parts of hardware acceleration in developer previews, but that’s not a guarantee of those bits shipping in Firefox 4. We’re going to try hard to ship some form of acceleration, though.
Layers is a technology that lets conceptually simple, but computationally expensive, parts of the web get offloaded to GPUs. Examples of this include transparency, scaling, composition, and simple animations of those attributes. Since we’re dealing mostly with images on the GPU, we can also accelerate operations on these images, like converting colours; this is especially useful in the case of video, because we can get the GPU to convert from video’s native YCbCr to the GPU’s native RGB, and then scale the result, for example to fullscreen. Both of these operations are expensive on the CPU, but relatively free on the GPU.
The downside of layers is that, in order to get the sort of benefit that’s possible from GPU acceleration, a lot of analysis of the document needs to be done to identify the parts that need to be separated into their own layers. Some of this is relatively easy, like background images; other parts are much harder. Also, layers is designed to accelerate only portions of the web; this means that, in the common case, we will render most of the web page using software, then do only the hardest/slowest part using the GPU directly.
Code currently in mozilla-central supports layers in three modes: a basic software-only mode (using Cairo); a mode that combines software with OpenGL; and a mode that combines software with Direct3D 9 (D3D9). At the time of this writing, only full-screen HTML5 video is rendered using our GPU accelerated (OpenGL and D3D9) layers backends, but in the future we plan to accelerate all of our rendering. To test this hardware acceleration, right-click on a video and select “Full Screen.” GPU accelerated full-screen video is turned on by default; you can check its status in your error console.
Direct2D (D2D) is a Cairo backend that GPU accelerates everything displayed by Firefox. Some parts of the web are more amenable to acceleration than others; for example, moving and scaling images around (like in photos.svg) is much faster. The average page that displays a lot of text and perhaps a few images won’t see nearly as big a speedup, though. The Direct2D Cairo backend doesn’t require any special analysis like the layers backends require, because everything in Firefox is already rendered using Cairo.
The downside to Direct2D is that it’s only supported on Windows Vista + Platform Update and Windows 7, and only then on relatively new GPUs (generally, GPUs that support DirectX 10).
Direct2D support is currently turned off by default, but can be turned on manually using about:config.