6 allocimage(Display *d, Rectangle r, u32int chan, int repl, u32int val)
8 return _allocimage(nil, d, r, chan, repl, val, 0, 0);
12 _allocimage(Image *ai, Display *d, Rectangle r, u32int chan, int repl, u32int val, int screenid, int refresh)
25 werrstr("bad channel descriptor");
29 depth = chantodepth(chan);
31 err = "bad channel descriptor";
34 werrstr("allocimage: %s", err);
36 werrstr("allocimage: %r");
41 /* flush pending data so we don't get error allocating the image */
43 a = bufimage(d, 1+4+4+1+4+1+4*4+4*4+4);
50 BPLONG(a+5, screenid);
54 BPLONG(a+15, r.min.x);
55 BPLONG(a+19, r.min.y);
56 BPLONG(a+23, r.max.x);
57 BPLONG(a+27, r.max.y);
59 /* huge but not infinite, so various offsets will leave it huge, not overflow */
60 clipr = Rect(-0x3FFFFFFF, -0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF);
63 BPLONG(a+31, clipr.min.x);
64 BPLONG(a+35, clipr.min.y);
65 BPLONG(a+39, clipr.max.x);
66 BPLONG(a+43, clipr.max.y);
68 if(flushimage(d, 0) < 0)
74 i = malloc(sizeof(Image));
98 namedimage(Display *d, char *name)
101 char *err, buf[12*12+1];
111 err = "name too long";
114 werrstr("namedimage: %s", err);
116 werrstr("namedimage: %r");
121 /* flush pending data so we don't get error allocating the image */
123 a = bufimage(d, 1+4+1+n+1);
131 memmove(a+6, name, n);
133 if(flushimage(d, 0) < 0)
135 if(_drawmsgread(d, buf, sizeof buf) < 12*12)
139 i = malloc(sizeof(Image));
142 a = bufimage(d, 1+4);
152 if((chan=strtochan(buf+2*12))==0){
153 werrstr("bad channel '%.12s' from devdraw", buf+2*12);
157 i->depth = chantodepth(chan);
158 i->repl = atoi(buf+3*12);
159 i->r.min.x = atoi(buf+4*12);
160 i->r.min.y = atoi(buf+5*12);
161 i->r.max.x = atoi(buf+6*12);
162 i->r.max.y = atoi(buf+7*12);
163 i->clipr.min.x = atoi(buf+8*12);
164 i->clipr.min.y = atoi(buf+9*12);
165 i->clipr.max.x = atoi(buf+10*12);
166 i->clipr.max.y = atoi(buf+11*12);
173 nameimage(Image *i, char *name, int in)
179 a = bufimage(i->display, 1+4+1+1+n);
186 memmove(a+7, name, n);
187 if(flushimage(i->display, 0) < 0)
193 _freeimage1(Image *i)
201 /* make sure no refresh events occur on this if we block in the write */
203 /* flush pending data so we don't get error deleting the image */
205 a = bufimage(d, 1+4);
213 d->windows = i->next;
223 if(flushimage(d, i->screen!=0) < 0)
234 ret = _freeimage1(i);