C.4 Graphics Batching
If you extend X to add more poly graphics primitives, you may be
able to take advantage of facilities in the library to allow
back-to-back single calls to be transformed into poly requests. This may
dramatically improve performance of programs that are not written using
poly requests. A pointer to an xReq()
, called
last_req
in the display structure, is the last
request being processed. By checking that the last request type,
drawable, gc, and other options are the same as the new one and that
there is enough space left in the buffer, you may be able to just extend
the previous graphics request by extending the length field of the
request and appending the data to the buffer. This can improve
performance by five times or more in naive programs. For example, here
is the source for the XDrawPoint()
stub. (Writing
extension stubs is discussed in the next section.)
#include "copyright.h" #include "Xlibint.h" /* precompute the maximum size of batching request allowed */ static int size = sizeof(xPolyPointReq) + EPERBATCH * sizeof(xPoint); XDrawPoint()(dpy, d, gc, x, y) register Display *dpy; Drawable d; GC gc; int x, y; /* INT16 */ { xPoint *point; LockDisplay()(dpy); FlushGC()(dpy, gc); { register xPolyPointReq *req = (xPolyPointReq *) dpy->last_req; /* if same as previous request, with same drawable, batch requests */ if ( (req->reqType == X_PolyPoint) && (req->drawable == d) && (req->gc == gc->gid) && (req->coordMode == CoordModeOrigin) && ((dpy->bufptr + sizeof ...
Get XLIB Programming Manual, Rel. 5, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.