XCompositeNameWindowPixmap vs using window directly
aplattner at nvidia.com
Wed Feb 10 09:09:14 CET 2016
On 02/09/2016 12:48 PM, adlo wrote:
> I am writing a window switcher application using GTK, Cairo, and Xlib that shows previews of windows.
> Assuming that I don't want to save the window's image for later use, what are the advantages of using XCompositeNameWindowPixmap () compared to simply using the X11 Window directly?
Windows can be resized or destroyed at any time, regardless of whether
you're trying to use them.
Naming the window pixmap gives you a reference to that particular
instance of the window's backing pixmap. That means that the pixmap
can't be freed while you're using it, and pixmaps can't be resized.
When a redirected window is resized, its backing pixmap is replaced by a
new one. It's your application's responsibility to select for and
handle the appropriate events to know when the backing pixmap is
replaced and to switch to the new backing pixmap as necessary, but you
don't need to worry about the pixmap disappearing while you're using it.
The other benefit of using the backing pixmap is that you can bind it
into OpenGL using the GLX_EXT_texture_from_pixmap extension. That
extension doesn't work with windows, mostly because windows can be
resized and destroyed at any time.
The biggest downside to using XCompositeNameWindowPixmap() is that it
requires the window to be redirected. Redirecting windows can incur
significant overhead just to display them, which might outweigh the
benefits of your window preview app. Depending on how you want your UI
to work, your window switcher app might need to be a composite manager,
at which point you're probably better off trying to build it into an
existing compositor framework such as mutter or compiz rather than
trying to write your own.
More information about the xorg