6 #include "x11-memdraw.h"
11 * Allocate a Memimage with an optional pixmap backing on the X server.
14 _xallocmemimage(Rectangle r, u32int chan, int pixmap)
21 m = _allocmemimage(r, chan);
22 if(chan != GREY1 && chan != _x.chan)
24 if(_x.display == 0 || _x.windows == nil)
28 * For bootstrapping, don't bother storing 1x1 images
29 * on the X server. Memimageinit needs to allocate these
30 * and we memimageinit before we do the rest of the X stuff.
31 * Of course, 1x1 images on the server are useless anyway.
33 if(Dx(r)==1 && Dy(r)==1)
36 xm = mallocz(sizeof(Xmem), 1);
43 * Allocate backing store.
52 xm->pixmap = XCreatePixmap(_x.display, _x.windows->drawable, Dx(r), Dy(r), d);
55 * We want to align pixels on word boundaries.
60 offset = r.min.x&(31/m->depth);
62 assert(wordsperline(r, m->depth) <= m->width);
65 * Wrap our data in an XImage structure.
67 xi = XCreateImage(_x.display, _x.vis, d,
68 ZPixmap, 0, (char*)m->data->bdata, Dx(r), Dy(r),
69 32, m->width*sizeof(u32int));
72 if(xm->pixmap != pixmap)
73 XFreePixmap(_x.display, xm->pixmap);
81 * Set the XImage parameters so that it looks exactly like
82 * a Memimage -- we're using the same data.
84 if(m->depth < 8 || m->depth == 24)
87 xi->bitmap_unit = m->depth;
88 xi->byte_order = LSBFirst;
89 xi->bitmap_bit_order = MSBFirst;
99 allocmemimage(Rectangle r, u32int chan)
101 return _xallocmemimage(r, chan, PMundef);
105 freememimage(Memimage *m)
113 if(xm && m->data->ref == 1){
118 XFreePixmap(_x.display, xm->pixmap);