6 #include "x11-memdraw.h"
9 * Allocate a Memimage with an optional pixmap backing on the X server.
12 _xallocmemimage(Rectangle r, u32int chan, int pixmap)
19 m = _allocmemimage(r, chan);
20 if(chan != GREY1 && chan != _x.chan)
26 * For bootstrapping, don't bother storing 1x1 images
27 * on the X server. Memimageinit needs to allocate these
28 * and we memimageinit before we do the rest of the X stuff.
29 * Of course, 1x1 images on the server are useless anyway.
31 if(Dx(r)==1 && Dy(r)==1)
34 xm = mallocz(sizeof(Xmem), 1);
41 * Allocate backing store.
50 xm->pixmap = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), d);
53 * We want to align pixels on word boundaries.
58 offset = r.min.x&(31/m->depth);
60 assert(wordsperline(r, m->depth) <= m->width);
63 * Wrap our data in an XImage structure.
65 xi = XCreateImage(_x.display, _x.vis, d,
66 ZPixmap, 0, (char*)m->data->bdata, Dx(r), Dy(r),
67 32, m->width*sizeof(u32int));
70 if(xm->pixmap != pixmap)
71 XFreePixmap(_x.display, xm->pixmap);
79 * Set the XImage parameters so that it looks exactly like
80 * a Memimage -- we're using the same data.
82 if(m->depth < 8 || m->depth == 24)
85 xi->bitmap_unit = m->depth;
86 xi->byte_order = LSBFirst;
87 xi->bitmap_bit_order = MSBFirst;
97 allocmemimage(Rectangle r, u32int chan)
99 return _xallocmemimage(r, chan, PMundef);
103 freememimage(Memimage *m)
111 if(xm && m->data->ref == 1){
116 XFreePixmap(_x.display, xm->pixmap);