10 static char deffontname[] = "*default*";
13 int debuglockdisplay = 1;
28 initdraw(void (*error)(Display*, char*), char *fontname, char *label)
33 display = _initdisplay(error, label); /* sets screen too */
38 display->image = display->screenimage;
39 screen = display->screenimage;
44 df = getdefont(display);
45 display->defaultsubfont = df;
47 fprint(2, "imageinit: can't open default subfont: %r\n");
49 closedisplay(display);
54 fontname = getenv("font"); /* leak */
57 * Build fonts with caches==depth of screen, for speed.
58 * If conversion were faster, we'd use 0 and save memory.
61 snprint(buf, sizeof buf, "%d %d\n0 %d\t%s\n", df->height, df->ascent,
62 df->n-1, deffontname);
63 //BUG: Need something better for this installsubfont("*default*", df);
64 font = buildfont(display, buf, deffontname);
66 fprint(2, "initdraw: can't open default font: %r\n");
70 font = openfont(display, fontname); /* BUG: grey fonts */
72 fprint(2, "initdraw: can't open font %s: %r\n", fontname);
76 display->defaultfont = font;
78 display->white = allocimage(display, Rect(0,0,1,1), GREY1, 1, DWhite);
79 display->black = allocimage(display, Rect(0,0,1,1), GREY1, 1, DBlack);
80 if(display->white == nil || display->black == nil){
81 fprint(2, "initdraw: can't allocate white and black");
84 display->opaque = display->white;
85 display->transparent = display->black;
91 * Call with d unlocked.
92 * Note that disp->defaultfont and defaultsubfont are not freed here.
95 closedisplay(Display *disp)
104 if(disp->oldlabel[0]){
105 snprint(buf, sizeof buf, "%s/label", disp->windir);
106 fd = open(buf, OWRITE);
108 write(fd, disp->oldlabel, strlen(disp->oldlabel));
115 freeimage(disp->white);
116 freeimage(disp->black);
121 lockdisplay(Display *disp)
123 if(debuglockdisplay){
124 /* avoid busy looping; it's rare we collide anyway */
125 while(!canqlock(&disp->qlock)){
126 fprint(1, "proc %d waiting for display lock...\n", getpid());
134 unlockdisplay(Display *disp)
136 qunlock(&disp->qlock);
140 drawerror(Display *d, char *s)
147 errstr(err, sizeof err);
148 fprint(2, "draw: %s: %s\n", s, err);
163 if(_drawmsgwrite(d, d->buf, n) != n){
165 fprint(2, "flushimage fail: d=%p: %r\n", d); /**/
166 d->bufp = d->buf; /* might as well; chance of continuing */
174 flushimage(Display *d, int visible)
177 *d->bufp++ = 'v'; /* five bytes always reserved for this */
178 if(d->_isnewdisplay){
179 BPLONG(d->bufp, d->screenimage->id);
187 bufimage(Display *d, int n)
191 if(n<0 || n>d->bufsize){
193 werrstr("bad count in bufimage");
196 if(d->bufp+n > d->buf+d->bufsize)