Efficient Screen Capture

List Sink (Terrence) list-sink at trainedmonkeystudios.org
Fri Dec 22 00:40:40 PST 2006

jason cipriani wrote:
> How do I capture the contents of the screen in less than 10 seconds?
> The following code is entirely too inefficient to be useful:
> Display *disp = XOpenDisplay(NULL);
> Window win = XRootWindow(disp, XDefaultScreen(disp));
> XImage *image = XGetImage(disp, win, 0, 0, WIDTH, HEIGHT, ~0, XYPixmap);
> I'm willing to hack it pretty far so any ideas (such as direct copies
> from video memory) would be useful. I am not willing to use any
> hardware other than this machine.
> Also just to make sure, is ~0 a sane value for plane_mask with format 
> XYPixmap?

What you want is almost certainly the X Shared Memory extension.

My understanding of this area is fuzzy; however, as I grokked it, when 
you use XGet/XPutImage directly, it does a client<->server copy through 
the socket that handles such transactions.  Even if this is a unix 
socket on the local machine, every byte has to go through an 
intermediary buffer in the kernel.  Rather, as long as you are running 
the client and server on the same machine, you can tell X to instead use 
a unix shared memory object to transport the image between client and 
server (instead of a socket).  I have, alas, forgotten the more esoteric 
details, but this gave me memcpy equivalent speeds for grabbing the 
frame buffer.

If you need even higher speeds than this (and it would be oh-so-nice), 
then you will have to consult one of the real X gurus.

The XShm reference that I found most useful is here:

Terrence Cole
terrence at zettabytestorage.com

CTO, Zettabyte Storage

> Thanks,
> Jason
> _______________________________________________
> xorg mailing list
> xorg at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xorg

More information about the xorg mailing list