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. What we call a 32-bit image
41 * the X server calls a 24-bit image.
47 xm->pixmap = XCreatePixmap(_x.display, _x.drawable,
48 Dx(r), Dy(r), d==32 ? 24 : d);
51 * We want to align pixels on word boundaries.
56 offset = r.min.x&(31/m->depth);
58 assert(wordsperline(r, m->depth) <= m->width);
61 * Wrap our data in an XImage structure.
63 xi = XCreateImage(_x.display, _x.vis, d==32 ? 24 : d,
64 ZPixmap, 0, (char*)m->data->bdata, Dx(r), Dy(r),
65 32, m->width*sizeof(u32int));
68 if(xm->pixmap != pixmap)
69 XFreePixmap(_x.display, xm->pixmap);
77 * Set the XImage parameters so that it looks exactly like
78 * a Memimage -- we're using the same data.
80 if(m->depth < 8 || m->depth == 24)
83 xi->bitmap_unit = m->depth;
84 xi->byte_order = LSBFirst;
85 xi->bitmap_bit_order = MSBFirst;
95 allocmemimage(Rectangle r, u32int chan)
97 return xallocmemimage(r, chan, PMundef);
101 freememimage(Memimage *m)
109 if(xm && m->data->ref == 1){
114 XFreePixmap(_x.display, xm->pixmap);