UnixDev

MIT-Shm Xdb X Window System

:

Xdb (X Double Buffer) XShm (X Shared memory) X Window System.

pacye. paccay o papee XShm (shared memory, ae eo aa MIT-Shm), oopoe ooe oy po ocy a eoaaepa, e ca ycop paoy poe o X Window System. B pe QuakeII popao peepe coyec eo oo.
Tae paccay o cooae pacpee Xdb (double buffer). Oo ooe opcoa , a aae, a yep (back buffer) ae cey oo yepa a a a aee. Te ca ycpoec o epa a pae p oe opae, aco ooc.

X Shared Memory.
-------------------
oo o oppeo paoa c pacpee (a c o py) eoxoo poep, ea eo oepa:

Display *display;
int mayor = 0, minor = 0;
// ...
XShmQueryVersion (display, &major, &minor, NULL);

if (mayor != 0 && minor != 0) {
  //  
}
Ec aee epc oo o 0, o a pacpee XShm eo.

pao c oae ee p y, oope coa opcoa opaee, axoec a eoaaepa.

Visual *vis;
XVisualInfo *xvis_info;

int width, height;

XImage *img;
XShmSegmentInfo *shminfo;
// ...
img = XShmCreateImage (display, vis, xvis_info->depth, ZPixmap, 
    0, shminfo, width, height); //  
    
shminfo.shmid = shmget (IPC_PRIVATE, img->data_size, IPC_CREAT|0777); //  
shminfo.shmaddr = img->data = shmat (shminfo.shmid, 0, 0); //    
shminfo.readOnly = False; //       False

XShmAttach (display, shminfo); //  ,   shared memory
//...
int src_x, src_y, dest_x, dest_y; //     (src_)    (dest_)
Drawable d;
GC gc;
//...
//  
XShmPutImage (display, d, gc, img, src_x, src_y, dest_x, dest_y, width, height, True);

.

X Double Buffer.
-----------------
o aao c pey pacpee, caaa peyec oy epc ec oa e paec 0, o cooa eo:

Display *display;
int mayor, minor
//...
XdbeQueryExtension (display, &mayor, &minor);

if (mayor != 0 && minor != 0) {
  //  
}
aee eoxoo coa coa a yep a Drawable:
Window      win;
XdbeBackBuffer xdbebb;
//...
xdbebb = XdbeAllocateBackBufferName (display, win, XdbeBackground);
Teep o ce opcoa eo o yep, o ec ao y opco eo o, cooa o yep aece apaepa c o Drawable, apep:
XPutImage (display, [b]xdbebb[/b], gc, image, 0,0,0,0, width, height);
XDrawString (display, [b]xdbebb[/b], gc, 0, 100, "X Double Buffer"0, strlen ("X Double Buffer"));
B oe aoo apa eoxoo oe a yep a eca, o eep e o apcoa pcoa pyo yep:
XdbeSwapInfo swap_info;
Window      win;
//...
swap_info.swap_window = win;
swap_info.swap_action = XdbeBackground;
XdbeSwapBuffers (display, &swap_info, 1);

Koeo aoe pacpee oo oo, coy opae aece aeo yepa oe oopaa eo. Ta, apep, ceao QuakeII. paa o cyae pec peaoa popa o eca.

Coceo ce, ce yaoo !

Aecap ope
2008

#MIT-Shm, #x11, #xdb, #xshm

6 2008