GTK+ Indirect Renderer
The GTK+ Indirect Renderer is a new GDK backend for the GTK+ toolkit. It renders each toplevel window to a Cairo image surface, and lets the application sort out the details of blitting these to a device. This is useful for applications that want to use GTK+ widgets in contexts that are not officially supported, such as games that use SDL or OpenGL.
Note that this is a different approach from the offscreen patches that are being merged into GTK+ at the moment. While those wrap the rendering being done by the current GDK backend (for instance, the X11 backend), this is a new backend that does all the rendering on the client side. Thus, we can render without depending on X11 or an equivalent display system at all.
Please note that this is a work in progress. Critical parts - like keyboard input handling - are missing, and the code quality is still very low.
That said, it already renders fairly well, and takes mouse input.
The project lives in a Git repository based on the official GTK+ repository available from git.gnome.org. To set up a local Git checkout, do the following:
git clone http://nanosleep.org/git/gtk+ cd gtk+ git checkout -b gtk-2-16-indirect-backend origin/gtk-2-16-indirect-backend
Once you have the gtk-2-16-indirect-backend branch checked out, you can compile and install it to $HOME/opt/gtk-test like this:
./autogen.sh --prefix=$HOME/opt/gtk-test --with-gdktarget=indirect make install
Note that you may need compatible versions of GTK+'s dependencies as well. This is best accomplished using JHBuild. After GTK+'s dependencies are built and installed, you need to set the PKG_CONFIG_PATH and LD_LIBRARY_PATH variables correctly before issuing the build commands above.
Hopefully, the indirect backend will be integrated with GTK+ proper at some point and appear in tarball releases. This should make building it a lot easier.
The indirect backend doesn't do much by itself. In fact, the tests and demos shipping with GTK+ will appear to do nothing at all when linked with it. This is because the indirect backend requires the application to bridge the gap between Cairo surfaces and the display device.
In order to show how this is done, I've prepared some example code that links with the indirect-enabled GTK+ and produces appreciable results. You can get it from its Git repository:
git clone http://nanosleep.org/git/gtk+-indirect-tests cd gtk+-indirect-tests
You will need the development files for SDL and OpenGL installed to build the tests. When you think everything is in order, issue:
export PKG_CONFIG_PATH=$HOME/opt/gtk-test/lib/pkgconfig export LD_LIBRARY_PATH=$HOME/opt/gtk-test/lib make
If you built and installed GTK+ dependencies using JHBuild, you may have to adjust PKG_CONFIG_PATH and LD_LIBRARY_PATH accordingly. With a little luck, this should produce binaries in the toplevel directory and the gtk-demo subdirectory. The latter contains an adaptation of the gtk-demo that ships with GTK+, made to render to an OpenGL surface.
The demo windows can be fullscreened or windowized using <Alt-Enter>. <Escape> quits.