When to call XDamageSubtract ()

Adam Jackson ajax at nwnk.net
Wed Mar 9 12:43:18 UTC 2016

On Tue, 2016-03-08 at 23:56 +0000, adlo wrote:
> I am writing a window switcher application using GTK that shows live
> previews of windows.
> Should I call XDamageSubtract () before or after I update the image
> widget in response to a damage event?

Before, but in another sense, neither.  X requests are processed as an
arbitrary shuffle of in-order atomic requests from clients.  If you
subtract before updating, the other client might update the window
again in between, which will generate more damage and you'll do excess
work, but at least the preview will look right.  If you subtract after
updating, the client may have updated the window in between, which (if
you're using a damage mode other than RawRectangles, which you have to
be in order for Subtract to mean anything) might not get reported, and
your preview image will be out of sync.

Better is to do XGrabServer/XUngrabServer around the two operations,
which will prevent any other client from updating in between, in which
case the order doesn't matter.  You should attempt to minimize the
amount of work you do while the server is grabbed (eg just do the
ShmGetImage/CopyArea and DamageSubtract, don't do any other requests
that would generate a reply) and you should minimize the number of
grabs you do (you'll get events far faster than the 60fps your display
is probably running at so you should throttle your own framerate) in
order to keep the server responsive to other clients.

- ajax

More information about the xorg mailing list