2 * /dev/draw simulator -- handles the messages prepared by the draw library.
3 * Doesn't simulate the file system part, just the messages.
14 #include <drawfcall.h>
19 static int drawuninstall(Client*, int);
20 static Memimage* drawinstall(Client*, int, Memimage*, DScreen*);
21 static void drawfreedimage(Client*, DImage*);
24 draw_initdisplaymemimage(Client *c, Memimage *m)
33 // gfx_replacescreenimage replaces c's screen image with m.
34 // It is called by the host driver on the main host thread.
36 gfx_replacescreenimage(Client *c, Memimage *m)
39 * Replace the screen image because the screen
42 * In theory there should only be one reference
43 * to the current screen image, and that's through
44 * client0's image 0, installed a few lines above.
45 * Once the client drops the image, the underlying backing
46 * store freed properly. The client is being notified
47 * about the resize through external means, so all we
48 * need to do is this assignment.
56 if(om && --om->screenref == 0){
64 drawrefreshscreen(DImage *l, Client *client)
66 while(l != nil && l->dscreen == nil)
68 if(l != nil && l->dscreen->owner != client)
69 l->dscreen->owner->refreshme = 1;
73 drawrefresh(Memimage *m, Rectangle r, void *v)
87 for(ref=c->refresh; ref; ref=ref->next)
89 combinerect(&ref->r, r);
92 ref = mallocz(sizeof(Refresh), 1);
96 ref->next = c->refresh;
102 addflush(Client *c, Rectangle r)
107 if(/*sdraw.softscreen==0 ||*/ !rectclip(&r, c->screenimage->r))
110 if(c->flushrect.min.x >= c->flushrect.max.x){
116 combinerect(&nbb, r);
118 abb = Dx(c->flushrect)*Dy(c->flushrect);
119 anbb = Dx(nbb)*Dy(nbb);
121 * Area of new waste is area of new bb minus area of old bb,
122 * less the area of the new segment, which we assume is not waste.
123 * This could be negative, but that's OK.
125 c->waste += anbb-abb - ar;
130 * total area is small
131 * waste is less than half total area
134 if(anbb<=1024 || c->waste*2<anbb || rectXrect(c->flushrect, r)){
138 /* emit current state */
142 if(fr.min.x < fr.max.x) {
143 // Unlock drawlk because rpc_flush may want to run on gfx thread,
144 // and gfx thread might be blocked on drawlk trying to install a new screen
148 c->impl->rpc_flush(c, fr);
155 dstflush(Client *c, int dstid, Memimage *dst, Rectangle r)
160 combinerect(&c->flushrect, r);
163 /* how can this happen? -rsc, dec 12 2002 */
165 fprint(2, "nil dstflush\n");
172 if(l->screen->image->data != c->screenimage->data)
174 r = rectaddpt(r, l->delta);
175 l = l->screen->image->layer;
186 c->flushrect = Rect(10000, 10000, -10000, -10000);
187 if(r.min.x < r.max.x) {
188 // Unlock drawlk because rpc_flush may want to run on gfx thread,
189 // and gfx thread might be blocked on drawlk trying to install a new screen
193 c->impl->rpc_flush(c, r);
200 drawcmp(char *a, char *b, int n)
204 return memcmp(a, b, n);
208 drawlookupname(Client *client, int n, char *str)
213 ename = &name[client->nname];
214 for(; name<ename; name++)
215 if(drawcmp(name->name, str, n) == 0)
221 drawgoodname(Client *client, DImage *d)
225 /* if window, validate the screen's own images */
227 if(drawgoodname(client, d->dscreen->dimage) == 0
228 || drawgoodname(client, d->dscreen->dfill) == 0)
232 n = drawlookupname(client, strlen(d->name), d->name);
233 if(n==nil || n->vers!=d->vers)
239 drawlookup(Client *client, int id, int checkname)
243 d = client->dimage[id&HASHMASK];
247 * BUG: should error out but too hard.
250 if(checkname && !drawgoodname(client, d))
260 drawlookupdscreen(Client *c, int id)
274 drawlookupscreen(Client *client, int id, CScreen **cs)
280 if(s->dscreen->id == id){
286 /* caller must check! */
291 drawinstall(Client *client, int id, Memimage *i, DScreen *dscreen)
295 d = mallocz(sizeof(DImage), 1);
308 d->dscreen = dscreen;
309 d->next = client->dimage[id&HASHMASK];
310 client->dimage[id&HASHMASK] = d;
315 drawinstallscreen(Client *client, DScreen *d, int id, DImage *dimage, DImage *dfill, int public)
320 c = mallocz(sizeof(CScreen), 1);
321 if(dimage && dimage->image && dimage->image->chan == 0){
322 fprint(2, "bad image %p in drawinstallscreen", dimage->image);
329 d = mallocz(sizeof(DScreen), 1);
334 s = mallocz(sizeof(Memscreen), 1);
344 s->image = dimage->image;
349 s->fill = dfill->image;
356 d->next = client->dscreen;
362 c->next = client->cscreen;
368 drawdelname(Client *client, DName *name)
372 i = name-client->name;
373 memmove(name, name+1, (client->nname-(i+1))*sizeof(DName));
378 drawfreedscreen(Client *client, DScreen *this)
384 fprint(2, "negative ref in drawfreedscreen\n");
387 ds = client->dscreen;
389 client->dscreen = this->next;
392 while(next = ds->next){ /* assign = */
394 ds->next = this->next;
400 * Should signal Enodrawimage, but too hard.
406 drawfreedimage(client, this->dimage);
408 drawfreedimage(client, this->dfill);
414 drawfreedimage(Client *client, DImage *dimage)
422 fprint(2, "negative ref in drawfreedimage\n");
427 for(i=0; i<client->nname; )
428 if(client->name[i].dimage == dimage)
429 drawdelname(client, client->name+i);
432 if(dimage->fromname){ /* acquired by name; owned by someone else*/
433 drawfreedimage(client, dimage->fromname);
436 ds = dimage->dscreen;
438 dimage->dscreen = nil; /* paranoia */
441 if(l->data == client->screenimage->data)
442 addflush(client, l->layer->screenr);
443 if(l->layer->refreshfn == drawrefresh) /* else true owner will clean up */
444 free(l->layer->refreshptr);
445 l->layer->refreshptr = nil;
446 if(drawgoodname(client, dimage))
450 drawfreedscreen(client, ds);
454 else if(--l->screenref==0)
463 drawuninstallscreen(Client *client, CScreen *this)
467 cs = client->cscreen;
469 client->cscreen = this->next;
470 drawfreedscreen(client, this->dscreen);
474 while(next = cs->next){ /* assign = */
476 cs->next = this->next;
477 drawfreedscreen(client, this->dscreen);
486 drawuninstall(Client *client, int id)
490 for(l=&client->dimage[id&HASHMASK]; (d=*l) != nil; l=&d->next){
493 drawfreedimage(client, d);
501 drawaddname(Client *client, DImage *di, int n, char *str, char **err)
503 DName *name, *ename, *new, *t;
507 ename = &name[client->nname];
508 for(; name<ename; name++)
509 if(drawcmp(name->name, str, n) == 0){
510 *err = "image name in use";
513 t = mallocz((client->nname+1)*sizeof(DName), 1);
515 if(t == nil || ns == nil){
518 *err = "out of memory";
521 memmove(t, client->name, client->nname*sizeof(DName));
524 new = &client->name[client->nname++];
526 memmove(new->name, str, n);
529 new->client = client;
530 new->vers = ++client->namevers;
535 drawclientop(Client *cl)
545 drawimage(Client *client, uchar *a)
549 d = drawlookup(client, BGLONG(a), 1);
551 return nil; /* caller must check! */
556 drawrectangle(Rectangle *r, uchar *a)
558 r->min.x = BGLONG(a+0*4);
559 r->min.y = BGLONG(a+1*4);
560 r->max.x = BGLONG(a+2*4);
561 r->max.y = BGLONG(a+3*4);
565 drawpoint(Point *p, uchar *a)
567 p->x = BGLONG(a+0*4);
568 p->y = BGLONG(a+1*4);
572 drawchar(Memimage *dst, Point p, Memimage *src, Point *sp, DImage *font, int index, int op)
578 fc = &font->fchar[index];
579 r.min.x = p.x+fc->left;
580 r.min.y = p.y-(font->ascent-fc->miny);
581 r.max.x = r.min.x+(fc->maxx-fc->minx);
582 r.max.y = r.min.y+(fc->maxy-fc->miny);
583 sp1.x = sp->x+fc->left;
584 sp1.y = sp->y+fc->miny;
585 memdraw(dst, r, src, sp1, font->image, Pt(fc->minx, fc->miny), op);
592 drawcoord(uchar *p, uchar *maxp, int oldx, int *newx)
617 draw_dataread(Client *cl, void *a, int n)
620 if(cl->readdata == nil){
621 werrstr("no draw data");
624 if(n < cl->nreaddata){
625 werrstr("short read");
629 memmove(a, cl->readdata, cl->nreaddata);
641 draw_datawrite(Client *client, void *v, int n)
643 char cbuf[40], *err, ibuf[12*12+1], *s;
644 int c, ci, doflush, dstid, e0, e1, esize, j, m;
645 int ni, nw, oesize, oldn, op, ox, oy, repl, scrnid, y;
646 uchar *a, refresh, *u;
649 DImage *di, *ddst, *dsrc, *font, *ll;
654 Memimage *dst, *i, *l, **lp, *mask, *src;
669 /*fprint(2, "msgwrite %d(%d)...", n, *a); */
672 /*fprint(2, "bad command %d\n", *a); */
673 err = "bad draw command";
676 /* allocate: 'b' id[4] screenid[4] refresh[1] chan[4] repl[1]
677 R[4*4] clipR[4*4] rrggbbaa[4]
680 m = 1+4+4+1+4+1+4*4+4*4+4;
684 scrnid = BGSHORT(a+5);
688 drawrectangle(&r, a+15);
689 drawrectangle(&clipr, a+31);
690 value = BGLONG(a+47);
691 if(drawlookup(client, dstid, 0))
694 dscrn = drawlookupscreen(client, scrnid, &cs);
697 scrn = dscrn->screen;
698 if(repl || chan!=scrn->image->chan){
699 err = "image parameters incompatibile with screen";
707 reffn = memlnorefresh;
713 err = "unknown refresh method";
716 l = memlalloc(scrn, r, reffn, 0, value);
719 addflush(client, l->layer->screenr);
721 rectclip(&l->clipr, r);
722 if(drawinstall(client, dstid, l, dscrn) == 0){
729 if(reffn == drawrefresh){
730 refx = mallocz(sizeof(Refx), 1);
732 if(drawuninstall(client, dstid) < 0)
736 refx->client = client;
737 refx->dimage = drawlookup(client, dstid, 1);
739 memlsetrefresh(l, reffn, refx);
743 i = allocmemimage(r, chan);
750 rectclip(&i->clipr, r);
751 if(drawinstall(client, dstid, i, 0) == 0){
755 memfillcolor(i, value);
758 /* allocate screen: 'A' id[4] imageid[4] fillid[4] public[1] */
766 if(drawlookupdscreen(client, dstid))
768 ddst = drawlookup(client, BGLONG(a+5), 1);
769 dsrc = drawlookup(client, BGLONG(a+9), 1);
770 if(ddst==0 || dsrc==0)
772 if(drawinstallscreen(client, 0, dstid, ddst, dsrc, a[13]) == 0)
776 /* set repl and clip: 'c' dstid[4] repl[1] clipR[4*4] */
781 ddst = drawlookup(client, BGLONG(a+1), 1);
785 err = "can't change repl/clipr of shared image";
791 drawrectangle(&dst->clipr, a+6);
794 /* draw: 'd' dstid[4] srcid[4] maskid[4] R[4*4] P[2*4] P[2*4] */
796 m = 1+4+4+4+4*4+2*4+2*4;
799 dst = drawimage(client, a+1);
801 src = drawimage(client, a+5);
802 mask = drawimage(client, a+9);
803 if(!dst || !src || !mask)
805 drawrectangle(&r, a+13);
808 op = drawclientop(client);
809 memdraw(dst, r, src, p, mask, q, op);
810 dstflush(client, dstid, dst, r);
813 /* toggle debugging: 'D' val[1] */
821 /* ellipse: 'e' dstid[4] srcid[4] center[2*4] a[4] b[4] thick[4] sp[2*4] alpha[4] phi[4]*/
824 m = 1+4+4+2*4+4+4+4+2*4+2*4;
827 dst = drawimage(client, a+1);
829 src = drawimage(client, a+5);
836 err = "invalid ellipse semidiameter";
841 err = "negative ellipse thickness";
845 drawpoint(&sp, a+29);
851 op = drawclientop(client);
852 /* high bit indicates arc angles are present */
853 if(ox & ((ulong)1<<31)){
854 if((ox & ((ulong)1<<30)) == 0)
855 ox &= ~((ulong)1<<31);
856 memarc(dst, p, e0, e1, c, src, sp, ox, oy, op);
858 memellipse(dst, p, e0, e1, c, src, sp, op);
859 dstflush(client, dstid, dst, Rect(p.x-e0-j, p.y-e1-j, p.x+e0+j+1, p.y+e1+j+1));
862 /* free: 'f' id[4] */
867 ll = drawlookup(client, BGLONG(a+1), 0);
868 if(ll && ll->dscreen && ll->dscreen->owner != client)
869 ll->dscreen->owner->refreshme = 1;
870 if(drawuninstall(client, BGLONG(a+1)) < 0)
874 /* free screen: 'F' id[4] */
879 if(!drawlookupscreen(client, BGLONG(a+1), &cs))
881 drawuninstallscreen(client, cs);
884 /* initialize font: 'i' fontid[4] nchars[4] ascent[1] */
891 err = "can't use display as font";
894 font = drawlookup(client, dstid, 1);
897 if(font->image->layer){
898 err = "can't use window as font";
902 if(ni<=0 || ni>4096){
903 err = "bad font size (4096 chars max)";
906 free(font->fchar); /* should we complain if non-zero? */
907 font->fchar = mallocz(ni*sizeof(FChar), 1);
908 if(font->fchar == 0){
909 err = "no memory for font";
912 memset(font->fchar, 0, ni*sizeof(FChar));
917 /* set image 0 to screen image */
922 if(drawlookup(client, 0, 0))
924 drawinstall(client, 0, client->screenimage, 0);
928 /* get image info: 'I' */
933 if(client->infoid < 0)
935 if(client->infoid == 0){
936 i = client->screenimage;
940 di = drawlookup(client, client->infoid, 1);
945 ni = sprint(ibuf, "%11d %11d %11s %11d %11d %11d %11d %11d"
946 " %11d %11d %11d %11d ",
949 chantostr(cbuf, i->chan),
950 (i->flags&Frepl)==Frepl,
951 i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y,
952 i->clipr.min.x, i->clipr.min.y,
953 i->clipr.max.x, i->clipr.max.y);
954 free(client->readdata);
955 client->readdata = malloc(ni);
956 if(client->readdata == nil)
958 memmove(client->readdata, ibuf, ni);
959 client->nreaddata = ni;
963 /* query: 'Q' n[1] queryspec[n] */
971 for(c=0; c<a[1]; c++) {
974 err = "unknown query";
978 fmtprint(&fmt, "%11d ", client->forcedpi);
980 fmtprint(&fmt, "%11d ", client->displaydpi);
984 client->readdata = (uchar*)fmtstrflush(&fmt);
985 if(client->readdata == nil)
987 client->nreaddata = strlen((char*)client->readdata);
990 /* load character: 'l' fontid[4] srcid[4] index[2] R[4*4] P[2*4] left[1] width[1] */
992 m = 1+4+4+2+4*4+2*4+1+1;
995 font = drawlookup(client, BGLONG(a+1), 1);
998 if(font->nfchar == 0)
1000 src = drawimage(client, a+5);
1004 if(ci >= font->nfchar)
1006 drawrectangle(&r, a+11);
1007 drawpoint(&p, a+27);
1008 memdraw(font->image, r, src, p, memopaque, p, S);
1009 fc = &font->fchar[ci];
1018 /* draw line: 'L' dstid[4] p0[2*4] p1[2*4] end0[4] end1[4] radius[4] srcid[4] sp[2*4] */
1020 m = 1+4+2*4+2*4+4+4+4+4+2*4;
1023 dst = drawimage(client, a+1);
1024 dstid = BGLONG(a+1);
1026 drawpoint(&q, a+13);
1031 err = "negative line width";
1034 src = drawimage(client, a+33);
1037 drawpoint(&sp, a+37);
1038 op = drawclientop(client);
1039 memline(dst, p, q, e0, e1, j, src, sp, op);
1040 /* avoid memlinebbox if possible */
1041 if(dstid==0 || dst->layer!=nil){
1042 /* BUG: this is terribly inefficient: update maximal containing rect*/
1043 r = memlinebbox(p, q, e0, e1, j);
1044 dstflush(client, dstid, dst, insetrect(r, -(1+1+j)));
1048 /* create image mask: 'm' newid[4] id[4] */
1059 /* attach to a named image: 'n' dstid[4] j[1] name[j] */
1065 if(j == 0) /* give me a non-empty name please */
1070 dstid = BGLONG(a+1);
1071 if(drawlookup(client, dstid, 0))
1073 dn = drawlookupname(client, j, (char*)a+6);
1079 if(drawinstall(client, dstid, dn->dimage->image, 0) == 0)
1081 di = drawlookup(client, dstid, 0);
1084 di->vers = dn->vers;
1086 di->fromname = dn->dimage;
1087 di->fromname->ref++;
1088 memmove(di->name, a+6, j);
1090 client->infoid = dstid;
1093 /* name an image: 'N' dstid[4] in[1] j[1] name[j] */
1100 if(j == 0) /* give me a non-empty name please */
1105 di = drawlookup(client, BGLONG(a+1), 0);
1111 if(drawaddname(client, di, j, (char*)a+7, &err) < 0)
1114 dn = drawlookupname(client, j, (char*)a+7);
1117 if(dn->dimage != di)
1119 drawdelname(client, dn);
1123 /* position window: 'o' id[4] r.min [2*4] screenr.min [2*4] */
1128 dst = drawimage(client, a+1);
1133 drawpoint(&q, a+13);
1134 r = dst->layer->screenr;
1135 ni = memlorigin(dst, p, q);
1137 err = "image origin failed";
1141 addflush(client, r);
1142 addflush(client, dst->layer->screenr);
1143 ll = drawlookup(client, BGLONG(a+1), 1);
1144 drawrefreshscreen(ll, client);
1149 /* set compositing operator for next draw operation: 'O' op */
1157 /* filled polygon: 'P' dstid[4] n[2] wind[4] ignore[2*4] srcid[4] sp[2*4] p0[2*4] dp[2*2*n] */
1158 /* polygon: 'p' dstid[4] n[2] end0[4] end1[4] radius[4] srcid[4] sp[2*4] p0[2*4] dp[2*2*n] */
1161 m = 1+4+2+4+4+4+4+2*4;
1164 dstid = BGLONG(a+1);
1165 dst = drawimage(client, a+1);
1168 err = "negative cout in polygon";
1177 err = "negative polygon line width";
1181 src = drawimage(client, a+19);
1184 drawpoint(&sp, a+23);
1185 drawpoint(&p, a+31);
1187 pp = mallocz(ni*sizeof(Point), 1);
1191 if(dstid==0 || (dst->layer && dst->layer->screen->image->data == client->screenimage->data))
1192 doflush = 1; /* simplify test in loop */
1196 for(y=0; y<ni; y++){
1199 u = drawcoord(u, a+n, ox, &p.x);
1202 u = drawcoord(u, a+n, oy, &p.y);
1211 c = memlineendsize(e0);
1216 c = memlineendsize(e1);
1221 if(*a=='P' && e0!=1 && e0 !=~0)
1224 r = Rect(q.x-oesize, q.y-oesize, q.x+oesize+1, q.y+oesize+1);
1225 combinerect(&r, Rect(p.x-esize, p.y-esize, p.x+esize+1, p.y+esize+1));
1227 if(rectclip(&r, dst->clipr)) /* should perhaps be an arg to dstflush */
1228 dstflush(client, dstid, dst, r);
1233 dstflush(client, dstid, dst, Rect(p.x-esize, p.y-esize, p.x+esize+1, p.y+esize+1));
1234 op = drawclientop(client);
1236 mempoly(dst, pp, ni, e0, e1, j, src, sp, op);
1238 memfillpoly(dst, pp, ni, e0, src, sp, op);
1243 /* read: 'r' id[4] R[4*4] */
1248 i = drawimage(client, a+1);
1251 drawrectangle(&r, a+5);
1252 if(!rectinrect(r, i->r))
1254 c = bytesperline(r, i->depth);
1256 free(client->readdata);
1257 client->readdata = mallocz(c, 0);
1258 if(client->readdata == nil){
1259 err = "readimage malloc failed";
1262 client->nreaddata = memunload(i, r, client->readdata, c);
1263 if(client->nreaddata < 0){
1264 free(client->readdata);
1265 client->readdata = nil;
1266 err = "bad readimage call";
1271 /* string: 's' dstid[4] srcid[4] fontid[4] P[2*4] clipr[4*4] sp[2*4] ni[2] ni*(index[2]) */
1272 /* 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]) */
1275 m = 1+4+4+4+2*4+4*4+2*4+2;
1281 dst = drawimage(client, a+1);
1282 dstid = BGLONG(a+1);
1283 src = drawimage(client, a+5);
1286 font = drawlookup(client, BGLONG(a+9), 1);
1289 if(font->nfchar == 0)
1291 drawpoint(&p, a+13);
1292 drawrectangle(&r, a+21);
1293 drawpoint(&sp, a+37);
1301 op = drawclientop(client);
1303 /* paint background */
1304 l = drawimage(client, a+47);
1307 drawpoint(&q, a+51);
1309 r.min.y = p.y-font->ascent;
1311 r.max.y = r.min.y+Dy(font->image->r);
1315 if(ci<0 || ci>=font->nfchar){
1319 r.max.x += font->fchar[ci].width;
1322 memdraw(dst, r, l, q, memopaque, ZP, op);
1328 if(ci<0 || ci>=font->nfchar){
1332 q = drawchar(dst, q, src, &sp, font, ci, op);
1336 p.y -= font->ascent;
1337 dstflush(client, dstid, dst, Rect(p.x, p.y, q.x, p.y+Dy(font->image->r)));
1340 /* use public screen: 'S' id[4] chan[4] */
1345 dstid = BGLONG(a+1);
1348 dscrn = drawlookupdscreen(client, dstid);
1349 if(dscrn==0 || (dscrn->public==0 && dscrn->owner!=client))
1351 if(dscrn->screen->image->chan != BGLONG(a+5)){
1352 err = "inconsistent chan";
1355 if(drawinstallscreen(client, dscrn, 0, 0, 0, 0) == 0)
1359 /* top or bottom windows: 't' top[1] nw[2] n*id[4] */
1372 lp = mallocz(nw*sizeof(Memimage*), 1);
1375 for(j=0; j<nw; j++){
1376 lp[j] = drawimage(client, a+1+1+2+j*4);
1382 if(lp[0]->layer == 0){
1383 err = "images are not windows";
1388 if(lp[j]->layer->screen != lp[0]->layer->screen){
1389 err = "images not on same screen";
1394 memltofrontn(lp, nw);
1396 memltorearn(lp, nw);
1397 if(lp[0]->layer->screen->image->data == client->screenimage->data)
1399 addflush(client, lp[j]->layer->screenr);
1401 ll = drawlookup(client, BGLONG(a+1+1+2), 1);
1402 drawrefreshscreen(ll, client);
1411 /* write: 'y' id[4] R[4*4] data[x*1] */
1412 /* write from compressed data: 'Y' id[4] R[4*4] data[x*1] */
1418 dstid = BGLONG(a+1);
1419 dst = drawimage(client, a+1);
1422 drawrectangle(&r, a+5);
1423 if(!rectinrect(r, dst->r))
1425 y = memload(dst, r, a+m, n-m, *a=='Y');
1427 err = "bad writeimage call";
1430 dstflush(client, dstid, dst, r);
1435 rpc_gfxdrawunlock();
1440 err = "unknown id for draw image";
1443 err = "unknown id for draw screen";
1446 err = "short draw message";
1450 err = "draw read too short";
1454 err = "image id in use";
1457 err = "screen id in use";
1460 err = "image memory allocation failed";
1463 err = "readimage outside image";
1466 err = "writeimage outside image";
1469 err = "image not a font";
1472 err = "character index out of range";
1476 err = "no such draw client";
1479 err = "image has bad depth";
1482 err = "image name in use";
1486 err = "no image with that name";
1489 err = "named image no longer valid";
1492 err = "image already has name";
1495 err = "wrong name for image";
1498 err = "out of memory";
1501 err = "bad argument in draw message";
1506 rpc_gfxdrawunlock();