[Xcb] Is there any way to intercept or generate protocol to an in-memory buffer?

Clemens Eisserer linuxhippy at gmail.com
Thu Dec 28 19:38:56 UTC 2017

Hi Bart,

> The overhead of doing separate XShmPutImages should be minimal.

Xcb is performing fine, what is causing performance issues is how the
drivers implement those tiny XPutImage requests (especially when
operating on top of OpenGL like all glamor based setups).
I've found a way to implement the deferred protocol submission using
the socket handoff mechanism and it seems to work really well.

However, currently the socket owner changes quite frequently, so I am
struggling with the requirement to issue a XGetInputFocus-Request
*every* time I call xcb_take_socket.
For cases where there are only 4 requests to submit, an additional
XGetInputFocus hurts.

What I tried instead was:

uint64_t lastManualSyncSeq; //Remember sequence-number, when the last
manual sync was issued
uint64_t socketTakenSeq; //Sequence number when the socket was taken
uint32_t self_generated_count; //Number of self-generated X requests

while(1) {
xcb_take_socket(xcbCon, &returnSocketCB, &flags, 0, &socketTakenSeq);

   while(1) {
     if((socketTakenSeq + self_generated_count) - lastManualSyncSeq > 65000) {
        //will cause socket to be revoked, callback will take care of
flushing out generated protocol
        lastManualSyncSeq = xcb_get_input_focus(xcbCon).sequence;
        xcb_discard_reply(xcbCon, lastManualSyncSeq);
        self_generated_count = 0;

    GenerateXrenderFillRectanglesRequest(); //appends reply-less
request to request data buffer

The idea is I can't be sure when xcb automatically generated the last
XGetInputFocus request, but I know when I last called
xcb_get_input_focus myself.
As long as the last call to xcb_get_input_focus is less than 65k
requests away, everything is fine (regardless of whether xcb issued
some xcb_get_input_focus requests in between).

However, this doesn't seem to work out as expected - I still get hangs
from time to time.

Any idea what is wrong with the above snippit?

Thank you in advance, Clemens

More information about the Xcb mailing list