2 * /dev/draw simulator -- handles the messages prepared by the draw library.
3 * Includes all the memlayer code even though most programs don't use it.
4 * This whole approach is overkill, but cpu is cheap and it keeps things simple.
14 #define HASHMASK (NHASH-1)
16 extern void flushmemscreen(Rectangle);
18 typedef struct Client Client;
19 typedef struct Draw Draw;
20 typedef struct DImage DImage;
21 typedef struct DScreen DScreen;
22 typedef struct CScreen CScreen;
23 typedef struct FChar FChar;
24 typedef struct Refresh Refresh;
25 typedef struct Refx Refx;
26 typedef struct DName DName;
43 DImage* dimage[NHASH];
80 int minx; /* left edge of bits */
81 int maxx; /* right edge of bits */
82 uchar miny; /* first non-zero scan-line */
83 uchar maxy; /* last non-zero scan-line + 1 */
84 schar left; /* offset of baseline */
85 uchar width; /* width of baseline */
89 * Reference counts in DImages:
90 * one per open by original client
91 * one per screen image or fill
92 * one per image derived from this one by name
104 DScreen* dscreen; /* 0 if not a window */
105 DImage* fromname; /* image this one is derived from, by name */
128 static Client *client0;
129 static Memimage *screenimage;
130 static Rectangle flushrect;
132 static DScreen* dscreen;
133 static int drawuninstall(Client*, int);
134 static Memimage* drawinstall(Client*, int, Memimage*, DScreen*);
135 static void drawfreedimage(DImage*);
138 _initdisplaymemimage(Display *d, Memimage *m)
142 client0 = mallocz(sizeof(Client), 1);
144 fprint(2, "initdraw: allocating client0: out of memory");
148 client0->clientid = ++sdraw.clientid;
149 client0->op = SoverD;
150 sdraw.client[0] = client0;
155 _drawreplacescreenimage(Memimage *m)
158 * Replace the screen image because the screen
161 * In theory there should only be one reference
162 * to the current screen image, and that's through
163 * client0's image 0, installed a few lines above.
164 * Once the client drops the image, the underlying backing
165 * store freed properly. The client is being notified
166 * about the resize through external means, so all we
167 * need to do is this assignment.
175 if(om && --om->screenref == 0){
183 drawrefreshscreen(DImage *l, Client *client)
185 while(l != nil && l->dscreen == nil)
187 if(l != nil && l->dscreen->owner != client)
188 l->dscreen->owner->refreshme = 1;
193 drawrefresh(Memimage *m, Rectangle r, void *v)
207 for(ref=c->refresh; ref; ref=ref->next)
208 if(ref->dimage == d){
209 combinerect(&ref->r, r);
212 ref = mallocz(sizeof(Refresh), 1);
216 ref->next = c->refresh;
222 addflush(Rectangle r)
227 if(sdraw.softscreen==0 || !rectclip(&r, screenimage->r))
230 if(flushrect.min.x >= flushrect.max.x){
236 combinerect(&nbb, r);
238 abb = Dx(flushrect)*Dy(flushrect);
239 anbb = Dx(nbb)*Dy(nbb);
241 * Area of new waste is area of new bb minus area of old bb,
242 * less the area of the new segment, which we assume is not waste.
243 * This could be negative, but that's OK.
245 waste += anbb-abb - ar;
250 * total area is small
251 * waste is less than half total area
254 if(anbb<=1024 || waste*2<anbb || rectXrect(flushrect, r)){
258 /* emit current state */
259 if(flushrect.min.x < flushrect.max.x)
260 flushmemscreen(flushrect);
267 dstflush(int dstid, Memimage *dst, Rectangle r)
272 combinerect(&flushrect, r);
275 /* how can this happen? -rsc, dec 12 2002 */
277 print("nil dstflush\n");
284 if(l->screen->image->data != screenimage->data)
286 r = rectaddpt(r, l->delta);
287 l = l->screen->image->layer;
296 if(flushrect.min.x < flushrect.max.x)
297 flushmemscreen(flushrect);
298 flushrect = Rect(10000, 10000, -10000, -10000);
303 drawcmp(char *a, char *b, int n)
307 return memcmp(a, b, n);
312 drawlookupname(int n, char *str)
317 ename = &name[sdraw.nname];
318 for(; name<ename; name++)
319 if(drawcmp(name->name, str, n) == 0)
326 drawgoodname(DImage *d)
330 /* if window, validate the screen's own images */
332 if(drawgoodname(d->dscreen->dimage) == 0
333 || drawgoodname(d->dscreen->dfill) == 0)
337 n = drawlookupname(strlen(d->name), d->name);
338 if(n==nil || n->vers!=d->vers)
345 drawlookup(Client *client, int id, int checkname)
349 d = client->dimage[id&HASHMASK];
353 * BUG: should error out but too hard.
356 if(checkname && !drawgoodname(d))
367 drawlookupdscreen(int id)
382 drawlookupscreen(Client *client, int id, CScreen **cs)
388 if(s->dscreen->id == id){
394 /* caller must check! */
400 drawinstall(Client *client, int id, Memimage *i, DScreen *dscreen)
404 d = mallocz(sizeof(DImage), 1);
417 d->dscreen = dscreen;
418 d->next = client->dimage[id&HASHMASK];
419 client->dimage[id&HASHMASK] = d;
425 drawinstallscreen(Client *client, DScreen *d, int id, DImage *dimage, DImage *dfill, int public)
430 c = mallocz(sizeof(CScreen), 1);
431 if(dimage && dimage->image && dimage->image->chan == 0){
432 print("bad image %p in drawinstallscreen", dimage->image);
439 d = mallocz(sizeof(DScreen), 1);
444 s = mallocz(sizeof(Memscreen), 1);
454 s->image = dimage->image;
459 s->fill = dfill->image;
472 c->next = client->cscreen;
479 drawdelname(DName *name)
484 memmove(name, name+1, (sdraw.nname-(i+1))*sizeof(DName));
490 drawfreedscreen(DScreen *this)
496 print("negative ref in drawfreedscreen\n");
501 dscreen = this->next;
504 while(next = ds->next){ /* assign = */
506 ds->next = this->next;
512 * Should signal Enodrawimage, but too hard.
518 drawfreedimage(this->dimage);
520 drawfreedimage(this->dfill);
527 drawfreedimage(DImage *dimage)
535 print("negative ref in drawfreedimage\n");
540 for(i=0; i<sdraw.nname; )
541 if(sdraw.name[i].dimage == dimage)
542 drawdelname(sdraw.name+i);
545 if(dimage->fromname){ /* acquired by name; owned by someone else*/
546 drawfreedimage(dimage->fromname);
549 ds = dimage->dscreen;
552 if(l->data == screenimage->data)
553 addflush(l->layer->screenr);
554 if(l->layer->refreshfn == drawrefresh) /* else true owner will clean up */
555 free(l->layer->refreshptr);
556 l->layer->refreshptr = nil;
557 if(drawgoodname(dimage))
565 else if(--l->screenref==0)
575 drawuninstallscreen(Client *client, CScreen *this)
579 cs = client->cscreen;
581 client->cscreen = this->next;
582 drawfreedscreen(this->dscreen);
586 while(next = cs->next){ /* assign = */
588 cs->next = this->next;
589 drawfreedscreen(this->dscreen);
599 drawuninstall(Client *client, int id)
603 d = client->dimage[id&HASHMASK];
607 client->dimage[id&HASHMASK] = d->next;
611 while(next = d->next){ /* assign = */
613 d->next = next->next;
614 drawfreedimage(next);
624 drawaddname(Client *client, DImage *di, int n, char *str, char **err)
626 DName *name, *ename, *new, *t;
630 ename = &name[sdraw.nname];
631 for(; name<ename; name++)
632 if(drawcmp(name->name, str, n) == 0){
633 *err = "image name in use";
636 t = mallocz((sdraw.nname+1)*sizeof(DName), 1);
638 if(t == nil || ns == nil){
641 *err = "out of memory";
644 memmove(t, sdraw.name, sdraw.nname*sizeof(DName));
647 new = &sdraw.name[sdraw.nname++];
649 memmove(new->name, str, n);
652 new->client = client;
653 new->vers = ++sdraw.vers;
658 drawclientop(Client *cl)
669 drawimage(Client *client, uchar *a)
673 d = drawlookup(client, BGLONG(a), 1);
675 return nil; /* caller must check! */
681 drawrectangle(Rectangle *r, uchar *a)
683 r->min.x = BGLONG(a+0*4);
684 r->min.y = BGLONG(a+1*4);
685 r->max.x = BGLONG(a+2*4);
686 r->max.y = BGLONG(a+3*4);
691 drawpoint(Point *p, uchar *a)
693 p->x = BGLONG(a+0*4);
694 p->y = BGLONG(a+1*4);
699 drawchar(Memimage *dst, Point p, Memimage *src, Point *sp, DImage *font, int index, int op)
705 fc = &font->fchar[index];
706 r.min.x = p.x+fc->left;
707 r.min.y = p.y-(font->ascent-fc->miny);
708 r.max.x = r.min.x+(fc->maxx-fc->minx);
709 r.max.y = r.min.y+(fc->maxy-fc->miny);
710 sp1.x = sp->x+fc->left;
711 sp1.y = sp->y+fc->miny;
712 memdraw(dst, r, src, sp1, font->image, Pt(fc->minx, fc->miny), op);
720 drawcoord(uchar *p, uchar *maxp, int oldx, int *newx)
745 _drawmsgread(Display *d, void *a, int n)
751 if(cl->readdata == nil){
752 werrstr("no draw data");
755 if(n < cl->nreaddata){
756 werrstr("short read");
760 memmove(a, cl->readdata, cl->nreaddata);
772 _drawmsgwrite(Display *d, void *v, int n)
774 char cbuf[40], *err, ibuf[12*12+1], *s;
775 int c, ci, doflush, dstid, e0, e1, esize, j, m;
776 int ni, nw, oesize, oldn, op, ox, oy, repl, scrnid, y;
777 uchar *a, refresh, *u;
781 DImage *di, *ddst, *dsrc, *font, *ll;
785 Memimage *dst, *i, *l, **lp, *mask, *src;
801 //fprint(2, "msgwrite %d(%d)...", n, *a);
804 //fprint(2, "bad command %d\n", *a);
805 err = "bad draw command";
808 /* allocate: 'b' id[4] screenid[4] refresh[1] chan[4] repl[1]
809 R[4*4] clipR[4*4] rrggbbaa[4]
812 m = 1+4+4+1+4+1+4*4+4*4+4;
816 scrnid = BGSHORT(a+5);
820 drawrectangle(&r, a+15);
821 drawrectangle(&clipr, a+31);
822 value = BGLONG(a+47);
823 if(drawlookup(client, dstid, 0))
826 dscrn = drawlookupscreen(client, scrnid, &cs);
829 scrn = dscrn->screen;
830 if(repl || chan!=scrn->image->chan){
831 err = "image parameters incompatibile with screen";
839 reffn = memlnorefresh;
845 err = "unknown refresh method";
848 l = memlalloc(scrn, r, reffn, 0, value);
851 addflush(l->layer->screenr);
853 rectclip(&l->clipr, r);
854 if(drawinstall(client, dstid, l, dscrn) == 0){
861 if(reffn == drawrefresh){
862 refx = mallocz(sizeof(Refx), 1);
864 if(drawuninstall(client, dstid) < 0)
868 refx->client = client;
869 refx->dimage = drawlookup(client, dstid, 1);
871 memlsetrefresh(l, reffn, refx);
875 i = allocmemimage(r, chan);
882 rectclip(&i->clipr, r);
883 if(drawinstall(client, dstid, i, 0) == 0){
887 memfillcolor(i, value);
890 /* allocate screen: 'A' id[4] imageid[4] fillid[4] public[1] */
898 if(drawlookupdscreen(dstid))
900 ddst = drawlookup(client, BGLONG(a+5), 1);
901 dsrc = drawlookup(client, BGLONG(a+9), 1);
902 if(ddst==0 || dsrc==0)
904 if(drawinstallscreen(client, 0, dstid, ddst, dsrc, a[13]) == 0)
908 /* set repl and clip: 'c' dstid[4] repl[1] clipR[4*4] */
913 ddst = drawlookup(client, BGLONG(a+1), 1);
917 err = "can't change repl/clipr of shared image";
923 drawrectangle(&dst->clipr, a+6);
926 /* draw: 'd' dstid[4] srcid[4] maskid[4] R[4*4] P[2*4] P[2*4] */
928 m = 1+4+4+4+4*4+2*4+2*4;
931 dst = drawimage(client, a+1);
933 src = drawimage(client, a+5);
934 mask = drawimage(client, a+9);
935 if(!dst || !src || !mask)
937 drawrectangle(&r, a+13);
940 op = drawclientop(client);
941 memdraw(dst, r, src, p, mask, q, op);
942 dstflush(dstid, dst, r);
945 /* toggle debugging: 'D' val[1] */
953 /* ellipse: 'e' dstid[4] srcid[4] center[2*4] a[4] b[4] thick[4] sp[2*4] alpha[4] phi[4]*/
956 m = 1+4+4+2*4+4+4+4+2*4+2*4;
959 dst = drawimage(client, a+1);
961 src = drawimage(client, a+5);
968 err = "invalid ellipse semidiameter";
973 err = "negative ellipse thickness";
977 drawpoint(&sp, a+29);
983 op = drawclientop(client);
984 /* high bit indicates arc angles are present */
985 if(ox & ((ulong)1<<31)){
986 if((ox & ((ulong)1<<30)) == 0)
987 ox &= ~((ulong)1<<31);
988 memarc(dst, p, e0, e1, c, src, sp, ox, oy, op);
990 memellipse(dst, p, e0, e1, c, src, sp, op);
991 dstflush(dstid, dst, Rect(p.x-e0-j, p.y-e1-j, p.x+e0+j+1, p.y+e1+j+1));
994 /* free: 'f' id[4] */
999 ll = drawlookup(client, BGLONG(a+1), 0);
1000 if(ll && ll->dscreen && ll->dscreen->owner != client)
1001 ll->dscreen->owner->refreshme = 1;
1002 if(drawuninstall(client, BGLONG(a+1)) < 0)
1006 /* free screen: 'F' id[4] */
1011 if(!drawlookupscreen(client, BGLONG(a+1), &cs))
1013 drawuninstallscreen(client, cs);
1016 /* initialize font: 'i' fontid[4] nchars[4] ascent[1] */
1021 dstid = BGLONG(a+1);
1023 err = "can't use display as font";
1026 font = drawlookup(client, dstid, 1);
1029 if(font->image->layer){
1030 err = "can't use window as font";
1034 if(ni<=0 || ni>4096){
1035 err = "bad font size (4096 chars max)";
1038 free(font->fchar); /* should we complain if non-zero? */
1039 font->fchar = mallocz(ni*sizeof(FChar), 1);
1040 if(font->fchar == 0){
1041 err = "no memory for font";
1044 memset(font->fchar, 0, ni*sizeof(FChar));
1046 font->ascent = a[9];
1049 /* set image 0 to screen image */
1054 if(drawlookup(client, 0, 0))
1056 drawinstall(client, 0, screenimage, 0);
1060 /* get image info: 'I' */
1065 if(client->infoid < 0)
1067 if(client->infoid == 0){
1072 di = drawlookup(client, client->infoid, 1);
1077 ni = sprint(ibuf, "%11d %11d %11s %11d %11d %11d %11d %11d"
1078 " %11d %11d %11d %11d ",
1081 chantostr(cbuf, i->chan),
1082 (i->flags&Frepl)==Frepl,
1083 i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y,
1084 i->clipr.min.x, i->clipr.min.y,
1085 i->clipr.max.x, i->clipr.max.y);
1086 free(client->readdata);
1087 client->readdata = malloc(ni);
1088 if(client->readdata == nil)
1090 memmove(client->readdata, ibuf, ni);
1091 client->nreaddata = ni;
1092 client->infoid = -1;
1095 /* load character: 'l' fontid[4] srcid[4] index[2] R[4*4] P[2*4] left[1] width[1] */
1097 m = 1+4+4+2+4*4+2*4+1+1;
1100 font = drawlookup(client, BGLONG(a+1), 1);
1103 if(font->nfchar == 0)
1105 src = drawimage(client, a+5);
1109 if(ci >= font->nfchar)
1111 drawrectangle(&r, a+11);
1112 drawpoint(&p, a+27);
1113 memdraw(font->image, r, src, p, memopaque, p, S);
1114 fc = &font->fchar[ci];
1123 /* draw line: 'L' dstid[4] p0[2*4] p1[2*4] end0[4] end1[4] radius[4] srcid[4] sp[2*4] */
1125 m = 1+4+2*4+2*4+4+4+4+4+2*4;
1128 dst = drawimage(client, a+1);
1129 dstid = BGLONG(a+1);
1131 drawpoint(&q, a+13);
1136 err = "negative line width";
1139 src = drawimage(client, a+33);
1142 drawpoint(&sp, a+37);
1143 op = drawclientop(client);
1144 memline(dst, p, q, e0, e1, j, src, sp, op);
1145 /* avoid memlinebbox if possible */
1146 if(dstid==0 || dst->layer!=nil){
1147 /* BUG: this is terribly inefficient: update maximal containing rect*/
1148 r = memlinebbox(p, q, e0, e1, j);
1149 dstflush(dstid, dst, insetrect(r, -(1+1+j)));
1153 /* create image mask: 'm' newid[4] id[4] */
1164 /* attach to a named image: 'n' dstid[4] j[1] name[j] */
1170 if(j == 0) /* give me a non-empty name please */
1175 dstid = BGLONG(a+1);
1176 if(drawlookup(client, dstid, 0))
1178 dn = drawlookupname(j, (char*)a+6);
1184 if(drawinstall(client, dstid, dn->dimage->image, 0) == 0)
1186 di = drawlookup(client, dstid, 0);
1189 di->vers = dn->vers;
1191 di->fromname = dn->dimage;
1192 di->fromname->ref++;
1193 memmove(di->name, a+6, j);
1195 client->infoid = dstid;
1198 /* name an image: 'N' dstid[4] in[1] j[1] name[j] */
1205 if(j == 0) /* give me a non-empty name please */
1210 di = drawlookup(client, BGLONG(a+1), 0);
1216 if(drawaddname(client, di, j, (char*)a+7, &err) < 0)
1219 dn = drawlookupname(j, (char*)a+7);
1222 if(dn->dimage != di)
1228 /* position window: 'o' id[4] r.min [2*4] screenr.min [2*4] */
1233 dst = drawimage(client, a+1);
1238 drawpoint(&q, a+13);
1239 r = dst->layer->screenr;
1240 ni = memlorigin(dst, p, q);
1242 err = "image origin failed";
1247 addflush(dst->layer->screenr);
1248 ll = drawlookup(client, BGLONG(a+1), 1);
1249 drawrefreshscreen(ll, client);
1254 /* set compositing operator for next draw operation: 'O' op */
1262 /* filled polygon: 'P' dstid[4] n[2] wind[4] ignore[2*4] srcid[4] sp[2*4] p0[2*4] dp[2*2*n] */
1263 /* polygon: 'p' dstid[4] n[2] end0[4] end1[4] radius[4] srcid[4] sp[2*4] p0[2*4] dp[2*2*n] */
1266 m = 1+4+2+4+4+4+4+2*4;
1269 dstid = BGLONG(a+1);
1270 dst = drawimage(client, a+1);
1273 err = "negative cout in polygon";
1282 err = "negative polygon line width";
1286 src = drawimage(client, a+19);
1289 drawpoint(&sp, a+23);
1290 drawpoint(&p, a+31);
1292 pp = mallocz(ni*sizeof(Point), 1);
1296 if(dstid==0 || (dst->layer && dst->layer->screen->image->data == screenimage->data))
1297 doflush = 1; /* simplify test in loop */
1301 for(y=0; y<ni; y++){
1304 u = drawcoord(u, a+n, ox, &p.x);
1307 u = drawcoord(u, a+n, oy, &p.y);
1316 c = memlineendsize(e0);
1321 c = memlineendsize(e1);
1326 if(*a=='P' && e0!=1 && e0 !=~0)
1329 r = Rect(q.x-oesize, q.y-oesize, q.x+oesize+1, q.y+oesize+1);
1330 combinerect(&r, Rect(p.x-esize, p.y-esize, p.x+esize+1, p.y+esize+1));
1332 if(rectclip(&r, dst->clipr)) /* should perhaps be an arg to dstflush */
1333 dstflush(dstid, dst, r);
1338 dstflush(dstid, dst, Rect(p.x-esize, p.y-esize, p.x+esize+1, p.y+esize+1));
1339 op = drawclientop(client);
1341 mempoly(dst, pp, ni, e0, e1, j, src, sp, op);
1343 memfillpoly(dst, pp, ni, e0, src, sp, op);
1348 /* read: 'r' id[4] R[4*4] */
1353 i = drawimage(client, a+1);
1356 drawrectangle(&r, a+5);
1357 if(!rectinrect(r, i->r))
1359 c = bytesperline(r, i->depth);
1361 free(client->readdata);
1362 client->readdata = mallocz(c, 0);
1363 if(client->readdata == nil){
1364 err = "readimage malloc failed";
1367 client->nreaddata = memunload(i, r, client->readdata, c);
1368 if(client->nreaddata < 0){
1369 free(client->readdata);
1370 client->readdata = nil;
1371 err = "bad readimage call";
1376 /* string: 's' dstid[4] srcid[4] fontid[4] P[2*4] clipr[4*4] sp[2*4] ni[2] ni*(index[2]) */
1377 /* stringbg: 'x' dstid[4] srcid[4] fontid[4] P[2*4] clipr[4*4] sp[2*4] ni[2] bgid[4] bgpt[2*4] ni*(index[2]) */
1380 m = 1+4+4+4+2*4+4*4+2*4+2;
1386 dst = drawimage(client, a+1);
1387 dstid = BGLONG(a+1);
1388 src = drawimage(client, a+5);
1391 font = drawlookup(client, BGLONG(a+9), 1);
1394 if(font->nfchar == 0)
1396 drawpoint(&p, a+13);
1397 drawrectangle(&r, a+21);
1398 drawpoint(&sp, a+37);
1406 op = drawclientop(client);
1408 /* paint background */
1409 l = drawimage(client, a+47);
1412 drawpoint(&q, a+51);
1414 r.min.y = p.y-font->ascent;
1416 r.max.y = r.min.y+Dy(font->image->r);
1420 if(ci<0 || ci>=font->nfchar){
1424 r.max.x += font->fchar[ci].width;
1427 memdraw(dst, r, l, q, memopaque, ZP, op);
1433 if(ci<0 || ci>=font->nfchar){
1437 q = drawchar(dst, q, src, &sp, font, ci, op);
1441 p.y -= font->ascent;
1442 dstflush(dstid, dst, Rect(p.x, p.y, q.x, p.y+Dy(font->image->r)));
1445 /* use public screen: 'S' id[4] chan[4] */
1450 dstid = BGLONG(a+1);
1453 dscrn = drawlookupdscreen(dstid);
1454 if(dscrn==0 || (dscrn->public==0 && dscrn->owner!=client))
1456 if(dscrn->screen->image->chan != BGLONG(a+5)){
1457 err = "inconsistent chan";
1460 if(drawinstallscreen(client, dscrn, 0, 0, 0, 0) == 0)
1464 /* top or bottom windows: 't' top[1] nw[2] n*id[4] */
1477 lp = mallocz(nw*sizeof(Memimage*), 1);
1480 for(j=0; j<nw; j++){
1481 lp[j] = drawimage(client, a+1+1+2+j*4);
1487 if(lp[0]->layer == 0){
1488 err = "images are not windows";
1493 if(lp[j]->layer->screen != lp[0]->layer->screen){
1494 err = "images not on same screen";
1499 memltofrontn(lp, nw);
1501 memltorearn(lp, nw);
1502 if(lp[0]->layer->screen->image->data == screenimage->data)
1504 addflush(lp[j]->layer->screenr);
1506 ll = drawlookup(client, BGLONG(a+1+1+2), 1);
1507 drawrefreshscreen(ll, client);
1516 /* write: 'y' id[4] R[4*4] data[x*1] */
1517 /* write from compressed data: 'Y' id[4] R[4*4] data[x*1] */
1523 dstid = BGLONG(a+1);
1524 dst = drawimage(client, a+1);
1527 drawrectangle(&r, a+5);
1528 if(!rectinrect(r, dst->r))
1530 y = memload(dst, r, a+m, n-m, *a=='Y');
1532 err = "bad writeimage call";
1535 dstflush(dstid, dst, r);
1544 err = "unknown id for draw image";
1547 err = "unknown id for draw screen";
1550 err = "short draw message";
1554 err = "draw read too short";
1558 err = "image id in use";
1561 err = "screen id in use";
1564 err = "image memory allocation failed";
1567 err = "readimage outside image";
1570 err = "writeimage outside image";
1573 err = "image not a font";
1576 err = "character index out of range";
1580 err = "no such draw client";
1583 err = "image has bad depth";
1586 err = "image name in use";
1590 err = "no image with that name";
1593 err = "named image no longer valid";
1596 err = "image already has name";
1599 err = "wrong name for image";
1602 err = "out of memory";
1605 err = "bad argument in draw message";