So Long and Thanks for the Blit!

There have been a number of requests to be able to replace the rendering engine used for widgets and pixmaps to be either OpenGL or the Raster backends as these have much better support for more advanced graphics features, such as gradients, blending and transformations compared to, specially, the X11 painting backend.

There existed some previous tricks to swap these things around. For instance, it was common to do "setViewport(new QGLWidget())" on a graphicsview it if ran slow. Similarly, one could create a QImage the size of the widget and do paintEvent into the QImage and just copy the data at the end using QPainter::drawImage().

Now we provide you with the real option. Starting Qt 4.5 you can choose the graphics system to use. It is ready available in the Technology Preview and in the snapshots. The way to pick backend is currently to specify a command line argument: "-graphicssystem raster" for the software engine or "-graphicssystem opengl" for OpenGL. The OpenGL graphicssystem is considered experimental for 4.5, while the raster backlend is considered fully supported on all platforms.

"But hey, this means we have tons of XPutImage calls as part of the repainting, doesn't it?" you are probably thinking. Luckily not... The raster graphics system is using the X Shared Memory extension to allocate the bits shared with an XPixmap so the end of a paint is a mere XCopyArea, which happens in-place on the X server, so it is quite cheap. Needless to say this is a solution that works best on local displays, but that does cover most of the Linux desktops out there, so it should be a gain in general.

Using this also means that QPixmaps reside in system memory and QImage < -> QPixmap conversions are cheap, making things like smoothScaled significantly faster. Another nice side effect is 100% feature compliance as the raster backend is the reference implementation of QPainter. In general you should expect speedups in anything related to svg's, pixmap transformations and gradients when switching to the raster system.

Just to give you an idea, below you see results of running the svgviewer with the bubbles.svg file on the various systems

Windows (Intel Core 2 Quad 2.6 GHz, 4 GB Ram, NVidia GeForce 8500 GT)

  • Native: 60 Fps
  • Raster: 60 Fps
  • OpenGL: 245 Fps

Naturally, Native and Raster run at the same speed on windows because native is the raster backend.

X11 (Intel Pentium 4, 3 GHz, 1 Gb Ram, Nvidia GeForce 6600)

  • Native: 20 Fps
  • Raster: 36 Fps
  • OpenGL: 92 Fps

This machine is running a slightly older graphics card than the other two machines, but its still a significant boost compared to native and raster when running with OpenGL.

Mac OS X (PowerBook, Intel Core 2 Duo, 2.4 GHz, 4 GB Ram, NVidia GeForce 8600 GM)

  • Native: 9 Fps
  • Raster: 30 Fps
  • OpenGL: 215 Fps

So, to sum up, any Qt application can now be run with the command line option

> app -graphicssystem raster


> app -graphicssystem opengl

and it will use a different rendering backend. So to underlying graphics libraries we say:
"So long and thanks for the Blit!"

Blog Topics: