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 channel descriptor");
34 depth = chantodepth(chan);
36 err = "bad channel descriptor";
39 werrstr("allocimage: %s", err);
41 werrstr("allocimage: %r");
46 /* flush pending data so we don't get error allocating the image */
48 a = bufimage(d, 1+4+4+1+4+1+4*4+4*4+4);
55 BPLONG(a+5, screenid);
59 BPLONG(a+15, r.min.x);
60 BPLONG(a+19, r.min.y);
61 BPLONG(a+23, r.max.x);
62 BPLONG(a+27, r.max.y);
64 /* huge but not infinite, so various offsets will leave it huge, not overflow */
65 clipr = Rect(-0x3FFFFFFF, -0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF);
68 BPLONG(a+31, clipr.min.x);
69 BPLONG(a+35, clipr.min.y);
70 BPLONG(a+39, clipr.max.x);
71 BPLONG(a+43, clipr.max.y);
73 if(flushimage(d, 0) < 0)
79 i = malloc(sizeof(Image));
103 namedimage(Display *d, char *name)
106 char *err, buf[12*12+1];
116 err = "name too long";
119 werrstr("namedimage: %s", err);
121 werrstr("namedimage: %r");
126 /* flush pending data so we don't get error allocating the image */
128 a = bufimage(d, 1+4+1+n);
136 memmove(a+6, name, n);
137 if(flushimage(d, 0) < 0)
140 if(pread(d->ctlfd, buf, sizeof buf, 0) < 12*12)
144 i = malloc(sizeof(Image));
147 a = bufimage(d, 1+4);
157 if((chan=strtochan(buf+2*12))==0){
158 werrstr("bad channel '%.12s' from devdraw", buf+2*12);
162 i->depth = chantodepth(chan);
163 i->repl = atoi(buf+3*12);
164 i->r.min.x = atoi(buf+4*12);
165 i->r.min.y = atoi(buf+5*12);
166 i->r.max.x = atoi(buf+6*12);
167 i->r.max.y = atoi(buf+7*12);
168 i->clipr.min.x = atoi(buf+8*12);
169 i->clipr.min.y = atoi(buf+9*12);
170 i->clipr.max.x = atoi(buf+10*12);
171 i->clipr.max.y = atoi(buf+11*12);
178 nameimage(Image *i, char *name, int in)
184 a = bufimage(i->display, 1+4+1+1+n);
191 memmove(a+7, name, n);
192 if(flushimage(i->display, 0) < 0)
198 _freeimage1(Image *i)
204 if(i == 0 || i->display == 0)
206 /* make sure no refresh events occur on this if we block in the write */
208 /* flush pending data so we don't get error deleting the image */
210 a = bufimage(d, 1+4);
218 d->windows = i->next;
228 if(flushimage(d, i->screen!=0) < 0)
239 ret = _freeimage1(i);