7 #include "x11-memdraw.h"
10 * Allocate a Memimage with an optional pixmap backing on the X server.
13 _xallocmemimage(Rectangle r, u32int chan, int pixmap)
20 m = _allocmemimage(r, chan);
21 if(chan != GREY1 && chan != _x.chan)
25 * For bootstrapping, don't bother storing 1x1 images
26 * on the X server. Memimageinit needs to allocate these
27 * and we memimageinit before we do the rest of the X stuff.
28 * Of course, 1x1 images on the server are useless anyway.
30 if(Dx(r)==1 && Dy(r)==1)
33 xm = mallocz(sizeof(Xmem), 1);
40 * Allocate backing store.
49 xm->pixmap = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), d);
52 * We want to align pixels on word boundaries.
57 offset = r.min.x&(31/m->depth);
59 assert(wordsperline(r, m->depth) <= m->width);
62 * Wrap our data in an XImage structure.
64 xi = XCreateImage(_x.display, _x.vis, d,
65 ZPixmap, 0, (char*)m->data->bdata, Dx(r), Dy(r),
66 32, m->width*sizeof(u32int));
69 if(xm->pixmap != pixmap)
70 XFreePixmap(_x.display, xm->pixmap);
78 * Set the XImage parameters so that it looks exactly like
79 * a Memimage -- we're using the same data.
81 if(m->depth < 8 || m->depth == 24)
84 xi->bitmap_unit = m->depth;
85 xi->byte_order = LSBFirst;
86 xi->bitmap_bit_order = MSBFirst;
96 allocmemimage(Rectangle r, u32int chan)
98 return _xallocmemimage(r, chan, PMundef);
102 freememimage(Memimage *m)
110 if(xm && m->data->ref == 1){
115 XFreePixmap(_x.display, xm->pixmap);