6 allocimage(Display *d, Rectangle r, ulong chan, int repl, ulong val)
10 i = _allocimage(nil, d, r, chan, repl, val, 0, 0);
12 setmalloctag(i, getcallerpc(&d));
17 _allocimage(Image *ai, Display *d, Rectangle r, ulong chan, int repl, ulong val, int screenid, int refresh)
30 werrstr("bad rectangle");
34 werrstr("bad channel descriptor");
38 depth = chantodepth(chan);
40 err = "bad channel descriptor";
43 werrstr("allocimage: %s", err);
45 werrstr("allocimage: %r");
50 /* flush pending data so we don't get error allocating the image */
52 a = bufimage(d, 1+4+4+1+4+1+4*4+4*4+4);
59 BPLONG(a+5, screenid);
63 BPLONG(a+15, r.min.x);
64 BPLONG(a+19, r.min.y);
65 BPLONG(a+23, r.max.x);
66 BPLONG(a+27, r.max.y);
68 /* huge but not infinite, so various offsets will leave it huge, not overflow */
69 clipr = Rect(-0x3FFFFFFF, -0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF);
72 BPLONG(a+31, clipr.min.x);
73 BPLONG(a+35, clipr.min.y);
74 BPLONG(a+39, clipr.max.x);
75 BPLONG(a+43, clipr.max.y);
77 if(flushimage(d, 0) < 0)
83 i = malloc(sizeof(Image));
107 namedimage(Display *d, char *name)
110 char *err, buf[12*12+1];
120 err = "name too long";
123 werrstr("namedimage: %s", err);
125 werrstr("namedimage: %r");
130 /* flush pending data so we don't get error allocating the image */
132 a = bufimage(d, 1+4+1+n);
140 memmove(a+6, name, n);
141 if(flushimage(d, 0) < 0)
144 if(pread(d->ctlfd, buf, sizeof buf, 0) < 12*12)
148 i = malloc(sizeof(Image));
151 a = bufimage(d, 1+4);
161 if((chan=strtochan(buf+2*12))==0){
162 werrstr("bad channel '%.12s' from devdraw", buf+2*12);
166 i->depth = chantodepth(chan);
167 i->repl = atoi(buf+3*12);
168 i->r.min.x = atoi(buf+4*12);
169 i->r.min.y = atoi(buf+5*12);
170 i->r.max.x = atoi(buf+6*12);
171 i->r.max.y = atoi(buf+7*12);
172 i->clipr.min.x = atoi(buf+8*12);
173 i->clipr.min.y = atoi(buf+9*12);
174 i->clipr.max.x = atoi(buf+10*12);
175 i->clipr.max.y = atoi(buf+11*12);
182 nameimage(Image *i, char *name, int in)
188 a = bufimage(i->display, 1+4+1+1+n);
195 memmove(a+7, name, n);
196 if(flushimage(i->display, 0) < 0)
202 _freeimage1(Image *i)
208 if(i == 0 || i->display == 0)
210 /* make sure no refresh events occur on this if we block in the write */
212 /* flush pending data so we don't get error deleting the image */
214 a = bufimage(d, 1+4);
222 d->windows = i->next;
232 if(flushimage(d, i->screen!=0) < 0)
243 ret = _freeimage1(i);