History

import devdraw from 9front

cinap_lenrek committed 10 years ago

Commit df777991 parent 17b41ae6 files · +234 −236Browse files

Unified · Split

6 files
  1. gui-osx/screen.c +6 −6
  2. gui-x11/x11.c +13 −10
  3. kern/devdraw.c +204 −204
  4. kern/fns.h +0 −4
  5. kern/screen.h +4 −7
  6. kern/term.c +7 −5
gui-osx/screen.c+6−6
@@ -313,9 +313,9 @@ leave_full_screen() · 312 unmodified lines
313313 Rectangle rect = { { 0, 0 },
314314 { bounds.size.width,
315315 bounds.size.height} };
316− drawqlock();
316+ qlock(&drawlock);
317317 flushmemscreen(rect);
318− drawqunlock();
318+ qunlock(&drawlock);
319319 }
320320 }
321321
@@ -331,9 +331,9 @@ full_screen() · 9 unmodified lines
331331 Rectangle rect = { { 0, 0 },
332332 { bounds.size.width,
333333 bounds.size.height} };
334− drawqlock();
334+ qlock(&drawlock);
335335 flushmemscreen(rect);
336− drawqunlock();
336+ qunlock(&drawlock);
337337 }
338338 }
339339
@@ -556,9 +556,9 @@ static OSStatus MainWindowCommandHandler(EventHandlerCallRef nextHandler, · 216 unmodified lines
556556 Rectangle rect = { { 0, 0 },
557557 { bounds.size.width,
558558 bounds.size.height} };
559− drawqlock();
559+ qlock(&drawlock);
560560 flushmemscreen(rect);
561− drawqunlock();
561+ qunlock(&drawlock);
562562 break;
563563
564564 default:
gui-x11/x11.c+13−10
@@ -163,7 +163,7 @@ flushmemscreen(Rectangle r) · 162 unmodified lines
163163 int x, y;
164164 uchar *p;
165165
166− assert(!drawcanqlock());
166+ assert(!canqlock(&drawlock));
167167 if(r.min.x >= r.max.x || r.min.y >= r.max.y)
168168 return;
169169
@@ -193,9 +193,9 @@ screeninit(void) · 23 unmodified lines
193193
194194 memimageinit();
195195 terminit();
196− drawqlock();
196+ qlock(&drawlock);
197197 flushmemscreen(gscreen->r);
198− drawqunlock();
198+ qunlock(&drawlock);
199199 }
200200
201201 uchar*
@@ -230,10 +230,10 @@ revbyte(int b) · 28 unmodified lines
230230 void
231231 mouseset(Point xy)
232232 {
233− drawqlock();
233+ qlock(&drawlock);
234234 XWarpPointer(xdisplay, None, xdrawable, 0, 0, 0, 0, xy.x, xy.y);
235235 XFlush(xdisplay);
236− drawqunlock();
236+ qunlock(&drawlock);
237237 }
238238
239239 static XCursor xcursor;
@@ -252,7 +252,7 @@ setcursor(void) · 12 unmodified lines
252252 mask[i] = revbyte(cursor.set[i] | cursor.clr[i]);
253253 }
254254
255− drawqlock();
255+ qlock(&drawlock);
256256 fg = map[0];
257257 bg = map[255];
258258 xsrc = XCreateBitmapFromData(xdisplay, xdrawable, (char*)src, 16, 16);
@@ -267,20 +267,20 @@ setcursor(void) · 8 unmodified lines
267267 XFreePixmap(xdisplay, xsrc);
268268 XFreePixmap(xdisplay, xmask);
269269 XFlush(xdisplay);
270− drawqunlock();
270+ qunlock(&drawlock);
271271 }
272272
273273 void
274274 cursorarrow(void)
275275 {
276− drawqlock();
276+ qlock(&drawlock);
277277 if(xcursor != 0){
278278 XFreeCursor(xdisplay, xcursor);
279279 xcursor = 0;
280280 }
281281 XUndefineCursor(xdisplay, xdrawable);
282282 XFlush(xdisplay);
283− drawqunlock();
283+ qunlock(&drawlock);
284284 }
285285
286286 static void
@@ -716,7 +716,10 @@ xexpose(XEvent *e) · 429 unmodified lines
716716 r.min.y = xe->y;
717717 r.max.x = xe->x + xe->width;
718718 r.max.y = xe->y + xe->height;
719− drawflushr(r);
719+
720+ qlock(&drawlock);
721+ flushmemscreen(r);
722+ qunlock(&drawlock);
720723 }
721724
722725 static void
kern/devdraw.c+204−204
@@ -15,6 +15,7 @@ enum · 14 unmodified lines
1515 {
1616 Qtopdir = 0,
1717 Qnew,
18+ Qwinname,
1819 Q3rd,
1920 Q2nd,
2021 Qcolormap,
@@ -36,7 +37,7 @@ enum · 15 unmodified lines
3637
3738 #define NHASH (1<<5)
3839 #define HASHMASK (NHASH-1)
39−#define IOUNIT (64*1024)
40+#define IOUNIT (64*1024)
4041
4142 typedef struct Client Client;
4243 typedef struct Draw Draw;
@@ -52,17 +53,15 @@ ulong blanktime = 30; /* in minutes; a half hour */ · 9 unmodified lines
5253
5354 struct Draw
5455 {
55− QLock lk;
5656 int clientid;
5757 int nclient;
5858 Client** client;
5959 int nname;
60− DName* name;
60+ DName* name;
6161 int vers;
6262 int softscreen;
6363 int blanked; /* screen turned off */
6464 ulong blanktime; /* time of last operation */
65− ulong savemap[3*256];
6665 };
6766
6867 struct Client
@@ -72,6 +71,7 @@ struct Client · 3 unmodified lines
7271 CScreen* cscreen;
7372 Refresh* refresh;
7473 Rendez refrend;
74+ QLock refq;
7575 uchar* readdata;
7676 int nreaddata;
7777 int busy;
@@ -97,10 +97,10 @@ struct Refx · 19 unmodified lines
9797
9898 struct DName
9999 {
100− char *name;
101− Client *client;
100+ char *name;
101+ Client *client;
102102 DImage* dimage;
103− int vers;
103+ int vers;
104104 };
105105
106106 struct FChar
@@ -130,7 +130,7 @@ struct DImage · 23 unmodified lines
130130 int nfchar;
131131 FChar* fchar;
132132 DScreen* dscreen; /* 0 if not a window */
133− DImage* fromname; /* image this one is derived from, by name */
133+ DImage* fromname; /* image this one is derived from, by name */
134134 DImage* next;
135135 };
136136
@@ -145,16 +145,21 @@ struct DScreen · 8 unmodified lines
145145 int id;
146146 int public;
147147 int ref;
148− DImage *dimage;
149− DImage *dfill;
148+ DImage *dimage;
149+ DImage *dfill;
150150 Memscreen* screen;
151151 Client* owner;
152152 DScreen* next;
153153 };
154154
155155 static Draw sdraw;
156+ QLock drawlock;
157+
156158 static Memimage *screenimage;
157−static Memdata screendata;
159+static DImage* screendimage;
160+static char screenname[40];
161+static int screennameid;
162+
158163 static Rectangle flushrect;
159164 static int waste;
160165 static DScreen* dscreen;
@@ -163,6 +168,7 @@ extern void flushmemscreen(Rectangle); · 2 unmodified lines
163168 void drawuninstall(Client*, int);
164169 void drawfreedimage(DImage*);
165170 Client* drawclientofpath(ulong);
171+ DImage* allocdimage(Memimage*);
166172
167173 static char Enodrawimage[] = "unknown id for draw image";
168174 static char Enodrawscreen[] = "unknown id for draw screen";
@@ -176,42 +182,35 @@ static char Ewriteoutside[] = "writeimage outside image"; · 7 unmodified lines
176182 static char Enotfont[] = "image not a font";
177183 static char Eindex[] = "character index out of range";
178184 static char Enoclient[] = "no such draw client";
179−/* static char Edepth[] = "image has bad depth"; */
180185 static char Enameused[] = "image name in use";
181186 static char Enoname[] = "no image with that name";
182187 static char Eoldname[] = "named image no longer valid";
183188 static char Enamed[] = "image already has name";
184189 static char Ewrongname[] = "wrong name for image";
185190
186−int
187−drawcanqlock(void)
188−{
189− return canqlock(&sdraw.lk);
190−}
191−
192−void
193−drawqlock(void)
191+static void
192+dlock(void)
194193 {
195− qlock(&sdraw.lk);
194+ qlock(&drawlock);
196195 }
197196
198−void
199−drawqunlock(void)
197+static void
198+dunlock(void)
200199 {
201− qunlock(&sdraw.lk);
200+ qunlock(&drawlock);
202201 }
203202
204203 static int
205−drawgen(Chan *c, char *name, Dirtab *dt, int ndt, int s, Dir *dp)
204+drawgen(Chan *c, char *n, Dirtab *d, int nd, int s, Dir *dp)
206205 {
207206 int t;
208207 Qid q;
209208 ulong path;
210209 Client *cl;
211210
212− USED(name);
213− USED(dt);
214− USED(ndt);
211+ USED(n);
212+ USED(d);
213+ USED(nd);
215214
216215 q.vers = 0;
217216
@@ -241,15 +240,17 @@ drawgen(Chan *c, char *name, Dirtab *dt, int ndt, int s, Dir *dp) · 23 unmodified lines
241240 * Top level directory contains the name of the device.
242241 */
243242 t = QID(c->qid);
244− if(t == Qtopdir){
245− switch(s){
246− case 0:
243+ if(t == Qtopdir || t == Qwinname){
244+ if(s == 1 || t == Qwinname){
245+ mkqid(&q, Qwinname, 0, QTFILE);
246+ devdir(c, q, "winname", 0, eve, 0444, dp);
247+ }
248+ else if(s == 0){
247249 mkqid(&q, Q2nd, 0, QTDIR);
248250 devdir(c, q, "draw", 0, eve, 0555, dp);
249− break;
250− default:
251− return -1;
252251 }
252+ else
253+ return -1;
253254 return 1;
254255 }
255256
@@ -326,14 +327,14 @@ drawrefreshscreen(DImage *l, Client *client) · 70 unmodified lines
326327
327328 static
328329 void
329−drawrefresh(Memimage *m, Rectangle r, void *v)
330+drawrefresh(Memimage *i, Rectangle r, void *v)
330331 {
331332 Refx *x;
332333 DImage *d;
333334 Client *c;
334335 Refresh *ref;
335336
336− USED(m);
337+ USED(i);
337338
338339 if(v == 0)
339340 return;
@@ -360,9 +361,8 @@ addflush(Rectangle r) · 20 unmodified lines
360361 int abb, ar, anbb;
361362 Rectangle nbb;
362363
363− if(sdraw.softscreen==0 || !rectclip(&r, screenimage->r))
364+ if(sdraw.softscreen==0 || screenimage == nil || !rectclip(&r, screenimage->r))
364365 return;
365−
366366 if(flushrect.min.x >= flushrect.max.x){
367367 flushrect = r;
368368 waste = 0;
@@ -408,13 +408,7 @@ dstflush(int dstid, Memimage *dst, Rectangle r) · 39 unmodified lines
408408 combinerect(&flushrect, r);
409409 return;
410410 }
411− /* how can this happen? -rsc, dec 12 2002 */
412− if(dst == 0){
413− print("nil dstflush\n");
414− return;
415− }
416− l = dst->layer;
417− if(l == nil)
411+ if(screenimage == nil || dst == nil || (l = dst->layer) == nil)
418412 return;
419413 do{
420414 if(l->screen->image->data != screenimage->data)
@@ -428,20 +422,11 @@ dstflush(int dstid, Memimage *dst, Rectangle r) · 7 unmodified lines
428422 void
429423 drawflush(void)
430424 {
431− if(flushrect.min.x < flushrect.max.x)
425+ if(screenimage && flushrect.min.x < flushrect.max.x)
432426 flushmemscreen(flushrect);
433427 flushrect = Rect(10000, 10000, -10000, -10000);
434428 }
435429
436−void
437−drawflushr(Rectangle r)
438−{
439− qlock(&sdraw.lk);
440− flushmemscreen(r);
441− qunlock(&sdraw.lk);
442−}
443−
444−static
445430 int
446431 drawcmp(char *a, char *b, int n)
447432 {
@@ -529,15 +514,14 @@ drawlookupscreen(Client *client, int id, CScreen **cs) · 81 unmodified lines
529514 return 0;
530515 }
531516
532−Memimage*
533−drawinstall(Client *client, int id, Memimage *i, DScreen *dscreen)
517+DImage*
518+allocdimage(Memimage *i)
534519 {
535520 DImage *d;
536521
537522 d = malloc(sizeof(DImage));
538523 if(d == 0)
539524 return 0;
540− d->id = id;
541525 d->ref = 1;
542526 d->name = 0;
543527 d->vers = 0;
@@ -545,6 +529,18 @@ drawinstall(Client *client, int id, Memimage *i, DScreen *dscreen) · 1 unmodified line
545529 d->nfchar = 0;
546530 d->fchar = 0;
547531 d->fromname = 0;
532+ return d;
533+}
534+
535+Memimage*
536+drawinstall(Client *client, int id, Memimage *i, DScreen *dscreen)
537+{
538+ DImage *d;
539+
540+ d = allocdimage(i);
541+ if(d == 0)
542+ return 0;
543+ d->id = id;
548544 d->dscreen = dscreen;
549545 d->next = client->dimage[id&HASHMASK];
550546 client->dimage[id&HASHMASK] = d;
@@ -607,6 +603,7 @@ drawdelname(DName *name) · 56 unmodified lines
607603 {
608604 int i;
609605
606+ free(name->name);
610607 i = name-sdraw.name;
611608 memmove(name, name+1, (sdraw.nname-(i+1))*sizeof(DName));
612609 sdraw.nname--;
@@ -627,7 +624,7 @@ drawfreedscreen(DScreen *this) · 14 unmodified lines
627624 dscreen = this->next;
628625 goto Found;
629626 }
630− while((next = ds->next)){ /* assign = */
627+ while(next = ds->next){ /* assign = */
631628 if(next == this){
632629 ds->next = this->next;
633630 goto Found;
@@ -668,12 +665,10 @@ drawfreedimage(DImage *dimage) · 34 unmodified lines
668665 drawfreedimage(dimage->fromname);
669666 goto Return;
670667 }
671− if(dimage->image == screenimage) /* don't free the display */
672− goto Return;
673668 ds = dimage->dscreen;
674669 if(ds){
675670 l = dimage->image;
676− if(l->data == screenimage->data)
671+ if(screenimage && l->data == screenimage->data)
677672 addflush(l->layer->screenr);
678673 if(l->layer->refreshfn == drawrefresh) /* else true owner will clean up */
679674 free(l->layer->refreshptr);
@@ -702,7 +697,7 @@ drawuninstallscreen(Client *client, CScreen *this) · 22 unmodified lines
702697 free(this);
703698 return;
704699 }
705− while((next = cs->next)){ /* assign = */
700+ while(next = cs->next){ /* assign = */
706701 if(next == this){
707702 cs->next = this->next;
708703 drawfreedscreen(this->dscreen);
@@ -726,7 +721,7 @@ drawuninstall(Client *client, int id) · 17 unmodified lines
726721 drawfreedimage(d);
727722 return;
728723 }
729− while((next = d->next)){ /* assign = */
724+ while(next = d->next){ /* assign = */
730725 if(next->id == id){
731726 d->next = next->next;
732727 drawfreedimage(next);
@@ -867,12 +862,8 @@ drawpoint(Point *p, uchar *a) · 134 unmodified lines
867862 p->y = BGLONG(a+1*4);
868863 }
869864
870−#define isvgascreen(dst) 1
871−
872−
873865 Point
874−drawchar(Memimage *dst, Memimage *rdst, Point p,
875− Memimage *src, Point *sp, DImage *font, int index, int op)
866+drawchar(Memimage *dst, Memimage *rdst, Point p, Memimage *src, Point *sp, DImage *font, int index, int op)
876867 {
877868 FChar *fc;
878869 Rectangle r;
@@ -886,7 +877,7 @@ drawchar(Memimage *dst, Memimage *rdst, Point p, · 7 unmodified lines
886877 r.max.y = r.min.y+(fc->maxy-fc->miny);
887878 sp1.x = sp->x+fc->left;
888879 sp1.y = sp->y+fc->miny;
889−
880+
890881 /*
891882 * If we're drawing greyscale fonts onto a VGA screen,
892883 * it's very costly to read the screen memory to do the
@@ -895,7 +886,7 @@ drawchar(Memimage *dst, Memimage *rdst, Point p, · 2 unmodified lines
895886 * refer to for the underlying dst pixels instead of reading dst
896887 * directly.
897888 */
898− if(1 || (isvgascreen(dst) && !isvgascreen(rdst) /*&& font->image->depth > 1*/)){
889+ if(ishwimage(dst) && !ishwimage(rdst) && font->image->depth > 1){
899890 if(tmp == nil || tmp->chan != dst->chan || Dx(tmp->r) < Dx(r) || Dy(tmp->r) < Dy(r)){
900891 if(tmp)
901892 freememimage(tmp);
@@ -916,60 +907,112 @@ drawchar(Memimage *dst, Memimage *rdst, Point p, · 14 unmodified lines
916907 return p;
917908 }
918909
919−static int
920−initscreenimage(void)
910+static DImage*
911+makescreenimage(void)
921912 {
922913 int width, depth;
923914 ulong chan;
915+ DImage *di;
916+ Memdata *md;
917+ Memimage *i;
924918 Rectangle r;
919+ uchar *data;
925920
926− if(screenimage != nil)
927− return 1;
921+ if((data = attachscreen(&r, &chan, &depth, &width, &sdraw.softscreen)) == nil)
922+ return nil;
923+ if(sdraw.softscreen == 0xa110c){
924+ /* hack: softscreen is memimage. */
925+ md = *((Memdata**)(data - sizeof(ulong) - sizeof(Memdata*)));
928926
929− screendata.base = nil;
930− screendata.bdata = attachscreen(&r, &chan, &depth, &width, &sdraw.softscreen);
931− if(screendata.bdata == nil)
932− return 0;
933− screendata.ref = 1;
927+ assert(md->bdata == data);
928+ assert(md->ref > 1);
929+ assert(md->allocd);
934930
935− screenimage = allocmemimaged(r, chan, &screendata);
936− if(screenimage == nil){
937− /* RSC: BUG: detach screen */
938− return 0;
931+ if((i = allocmemimaged(r, chan, md)) == nil){
932+ md->ref--;
933+ return nil;
934+ }
935+ }else{
936+ if((md = malloc(sizeof *md)) == nil)
937+ return nil;
938+ md->allocd = 1;
939+ md->base = nil;
940+ md->bdata = data;
941+ md->ref = 1;
942+ if((i = allocmemimaged(r, chan, md)) == nil){
943+ free(md);
944+ return nil;
945+ }
946+ }
947+ i->width = width;
948+ i->clipr = r;
949+ di = allocdimage(i);
950+ if(di == nil){
951+ freememimage(i); /* frees md */
952+ return nil;
953+ }
954+ if(!waserror()){
955+ snprint(screenname, sizeof screenname, "noborder.screen.%d", ++screennameid);
956+ drawaddname(nil, di, strlen(screenname), screenname);
957+ poperror();
939958 }
959+ return di;
960+}
940961
941− screenimage->width = width;
942− screenimage->clipr = r;
962+static int
963+initscreenimage(void)
964+{
965+ if(screenimage != nil)
966+ return 1;
967+
968+ screendimage = makescreenimage();
969+ if(screendimage == nil)
970+ return 0;
971+ screenimage = screendimage->image;
972+// iprint("initscreenimage %p %p\n", screendimage, screenimage);
943973 return 1;
944974 }
945975
946976 void
947977 deletescreenimage(void)
948978 {
949− qlock(&sdraw.lk);
950− /* RSC: BUG: detach screen */
951− if(screenimage)
952− freememimage(screenimage);
953− screenimage = nil;
954− qunlock(&sdraw.lk);
979+ dlock();
980+ if(screenimage){
981+ /* will be freed via screendimage; disable */
982+ screenimage->clipr = ZR;
983+ screenimage = nil;
984+ }
985+ if(screendimage){
986+ drawfreedimage(screendimage);
987+ screendimage = nil;
988+ }
989+ dunlock();
990+}
991+
992+void
993+resetscreenimage(void)
994+{
995+ dlock();
996+ initscreenimage();
997+ dunlock();
955998 }
956999
9571000 static Chan*
9581001 drawattach(char *spec)
9591002 {
960− qlock(&sdraw.lk);
1003+ dlock();
9611004 if(!initscreenimage()){
962− qunlock(&sdraw.lk);
1005+ dunlock();
9631006 error("no frame buffer");
9641007 }
965− qunlock(&sdraw.lk);
1008+ dunlock();
9661009 return devattach('i', spec);
9671010 }
9681011
9691012 static Walkqid*
9701013 drawwalk(Chan *c, Chan *nc, char **name, int nname)
9711014 {
972− if(screendata.bdata == nil)
1015+ if(screenimage == nil)
9731016 error("no frame buffer");
9741017 return devwalk(c, nc, name, nname, 0, 0, drawgen);
9751018 }
@@ -984,15 +1027,17 @@ static Chan* · 8 unmodified lines
9841027 drawopen(Chan *c, int omode)
9851028 {
9861029 Client *cl;
1030+ DName *dn;
1031+ DImage *di;
9871032
9881033 if(c->qid.type & QTDIR){
9891034 c = devopen(c, omode, 0, 0, drawgen);
9901035 c->iounit = IOUNIT;
9911036 }
9921037
993− qlock(&sdraw.lk);
1038+ dlock();
9941039 if(waserror()){
995− qunlock(&sdraw.lk);
1040+ dunlock();
9961041 nexterror();
9971042 }
9981043
@@ -1004,6 +1049,9 @@ drawopen(Chan *c, int omode) · 5 unmodified lines
10041049 }
10051050
10061051 switch(QID(c->qid)){
1052+ case Qwinname:
1053+ break;
1054+
10071055 case Qnew:
10081056 break;
10091057
@@ -1013,9 +1061,22 @@ drawopen(Chan *c, int omode) · 3 unmodified lines
10131061 error(Einuse);
10141062 cl->busy = 1;
10151063 flushrect = Rect(10000, 10000, -10000, -10000);
1016− drawinstall(cl, 0, screenimage, 0);
1064+ dn = drawlookupname(strlen(screenname), screenname);
1065+ if(dn == 0)
1066+ error("draw: cannot happen 2");
1067+ if(drawinstall(cl, 0, dn->dimage->image, 0) == 0)
1068+ error(Edrawmem);
1069+ di = drawlookup(cl, 0, 0);
1070+ if(di == 0)
1071+ error("draw: cannot happen 1");
1072+ di->vers = dn->vers;
1073+ di->name = smalloc(strlen(screenname)+1);
1074+ strcpy(di->name, screenname);
1075+ di->fromname = dn->dimage;
1076+ di->fromname->ref++;
10171077 incref(&cl->r);
10181078 break;
1079+
10191080 case Qcolormap:
10201081 case Qdata:
10211082 case Qrefresh:
@@ -1023,7 +1084,7 @@ drawopen(Chan *c, int omode) · 1 unmodified line
10231084 incref(&cl->r);
10241085 break;
10251086 }
1026− qunlock(&sdraw.lk);
1087+ dunlock();
10271088 poperror();
10281089 c->mode = openmode(omode);
10291090 c->flag |= COPEN;
@@ -1042,9 +1103,9 @@ drawclose(Chan *c) · 12 unmodified lines
10421103
10431104 if(QID(c->qid) < Qcolormap) /* Qtopdir, Qnew, Q3rd, Q2nd have no client */
10441105 return;
1045− qlock(&sdraw.lk);
1106+ dlock();
10461107 if(waserror()){
1047− qunlock(&sdraw.lk);
1108+ dunlock();
10481109 nexterror();
10491110 }
10501111
@@ -1052,7 +1113,7 @@ drawclose(Chan *c) · 1 unmodified line
10521113 if(QID(c->qid) == Qctl)
10531114 cl->busy = 0;
10541115 if((c->flag&COPEN) && (decref(&cl->r)==0)){
1055− while((r = cl->refresh)){ /* assign = */
1116+ while(r = cl->refresh){ /* assign = */
10561117 cl->refresh = r->next;
10571118 free(r);
10581119 }
@@ -1077,7 +1138,7 @@ drawclose(Chan *c) · 18 unmodified lines
10771138 drawflush(); /* to erase visible, now dead windows */
10781139 free(cl);
10791140 }
1080− qunlock(&sdraw.lk);
1141+ dunlock();
10811142 poperror();
10821143 }
10831144
@@ -1096,10 +1157,13 @@ drawread(Chan *c, void *a, long n, vlong off) · 12 unmodified lines
10961157
10971158 if(c->qid.type & QTDIR)
10981159 return devdirread(c, a, n, 0, 0, drawgen);
1160+ if(QID(c->qid) == Qwinname)
1161+ return readstr(off, a, n, screenname);
1162+
10991163 cl = drawclient(c);
1100− qlock(&sdraw.lk);
1164+ dlock();
11011165 if(waserror()){
1102− qunlock(&sdraw.lk);
1166+ dunlock();
11031167 nexterror();
11041168 }
11051169 switch(QID(c->qid)){
@@ -1118,15 +1182,15 @@ drawread(Chan *c, void *a, long n, vlong off) · 12 unmodified lines
11181182 error(Enodrawimage);
11191183 i = di->image;
11201184 }
1121− n = sprint(a, "%11d %11d %11s %11d %11d %11d %11d %11d %11d %11d %11d %11d ",
1185+ n = sprint(a, "%11d %11d %11s %11d %11d %11d %11d %11d %11d %11d %11d %11d",
11221186 cl->clientid, cl->infoid, chantostr(buf, i->chan), (i->flags&Frepl)==Frepl,
11231187 i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y,
11241188 i->clipr.min.x, i->clipr.min.y, i->clipr.max.x, i->clipr.max.y);
1189+ ((char*)a)[n++] = ' ';
11251190 cl->infoid = -1;
11261191 break;
11271192
11281193 case Qcolormap:
1129− drawactive(1); /* to restore map from backup */
11301194 p = malloc(4*12*256+1);
11311195 if(p == 0)
11321196 error(Enomem);
@@ -1156,14 +1220,21 @@ drawread(Chan *c, void *a, long n, vlong off) · 23 unmodified lines
11561220 for(;;){
11571221 if(cl->refreshme || cl->refresh)
11581222 break;
1159− qunlock(&sdraw.lk);
1223+ dunlock();
11601224 if(waserror()){
1161− qlock(&sdraw.lk); /* restore lock for waserror() above */
1225+ dlock();
1226+ nexterror();
1227+ }
1228+ qlock(&cl->refq);
1229+ if(waserror()){
1230+ qunlock(&cl->refq);
11621231 nexterror();
11631232 }
11641233 sleep(&cl->refrend, drawrefactive, cl);
11651234 poperror();
1166− qlock(&sdraw.lk);
1235+ qunlock(&cl->refq);
1236+ poperror();
1237+ dlock();
11671238 }
11681239 p = a;
11691240 while(cl->refresh && n>=5*4){
@@ -1180,8 +1251,9 @@ drawread(Chan *c, void *a, long n, vlong off) · 10 unmodified lines
11801251 }
11811252 cl->refreshme = 0;
11821253 n = p-(uchar*)a;
1254+ break;
11831255 }
1184− qunlock(&sdraw.lk);
1256+ dunlock();
11851257 poperror();
11861258 return n;
11871259 }
@@ -1200,21 +1272,21 @@ drawwakeall(void) · 12 unmodified lines
12001272 }
12011273
12021274 static long
1203−drawwrite(Chan *c, void *a, long n, vlong offset)
1275+drawwrite(Chan *c, void *a, long n, vlong off)
12041276 {
12051277 char buf[128], *fields[4], *q;
12061278 Client *cl;
12071279 int i, m, red, green, blue, x;
12081280
1209− USED(offset);
1281+ USED(off);
12101282
12111283 if(c->qid.type & QTDIR)
12121284 error(Eisdir);
12131285 cl = drawclient(c);
1214− qlock(&sdraw.lk);
1286+ dlock();
12151287 if(waserror()){
12161288 drawwakeall();
1217− qunlock(&sdraw.lk);
1289+ dunlock();
12181290 nexterror();
12191291 }
12201292 switch(QID(c->qid)){
@@ -1225,7 +1297,6 @@ drawwrite(Chan *c, void *a, long n, vlong offset) · 4 unmodified lines
12251297 break;
12261298
12271299 case Qcolormap:
1228− drawactive(1); /* to restore map from backup */
12291300 m = n;
12301301 n = 0;
12311302 while(m > 0){
@@ -1268,7 +1339,7 @@ drawwrite(Chan *c, void *a, long n, vlong offset) · 36 unmodified lines
12681339 default:
12691340 error(Ebadusefd);
12701341 }
1271− qunlock(&sdraw.lk);
1342+ dunlock();
12721343 poperror();
12731344 return n;
12741345 }
@@ -1306,14 +1377,6 @@ printmesg(char *fmt, uchar *a, int plsprnt) · 31 unmodified lines
13061377 int s;
13071378
13081379 if(1|| plsprnt==0){
1309− SET(s);
1310− SET(q);
1311− SET(p);
1312− USED(fmt);
1313− USED(a);
1314− p = buf;
1315− USED(p);
1316− USED(q);
13171380 USED(s);
13181381 return;
13191382 }
@@ -1364,7 +1427,7 @@ drawmesg(Client *client, void *av, int n) · 44 unmodified lines
13641427 ulong value, chan;
13651428 Rectangle r, clipr;
13661429 Point p, q, *pp, sp;
1367− Memimage *i, *dst, *src, *mask;
1430+ Memimage *i, *bg, *dst, *src, *mask;
13681431 Memimage *l, **lp;
13691432 Memscreen *scrn;
13701433 DImage *font, *ll, *di, *ddst, *dsrc;
@@ -1396,7 +1459,7 @@ drawmesg(Client *client, void *av, int n) · 25 unmodified lines
13961459 if(n < m)
13971460 error(Eshortdraw);
13981461 dstid = BGLONG(a+1);
1399− scrnid = BGSHORT(a+5);
1462+ scrnid = BGLONG(a+5);
14001463 refresh = a[9];
14011464 chan = BGLONG(a+10);
14021465 repl = a[14];
@@ -1410,7 +1473,7 @@ drawmesg(Client *client, void *av, int n) · 7 unmodified lines
14101473 scrn = dscrn->screen;
14111474 if(repl || chan!=scrn->image->chan)
14121475 error("image parameters incompatible with screen");
1413− reffn = 0;
1476+ reffn = nil;
14141477 switch(refresh){
14151478 case Refbackup:
14161479 break;
@@ -1493,7 +1556,7 @@ drawmesg(Client *client, void *av, int n) · 76 unmodified lines
14931556 if(ddst == nil)
14941557 error(Enodrawimage);
14951558 if(ddst->name)
1496− error("can't change repl/clipr of shared image");
1559+ error("cannot change repl/clipr of shared image");
14971560 dst = ddst->image;
14981561 if(a[5])
14991562 dst->flags |= Frepl;
@@ -1553,9 +1616,9 @@ drawmesg(Client *client, void *av, int n) · 53 unmodified lines
15531616 oy = BGLONG(a+41);
15541617 op = drawclientop(client);
15551618 /* high bit indicates arc angles are present */
1556− if(ox & (1U<<31)){
1619+ if(ox & (1<<31)){
15571620 if((ox & (1<<30)) == 0)
1558− ox &= ~(1U<<31);
1621+ ox &= ~(1<<31);
15591622 memarc(dst, p, e0, e1, c, src, sp, ox, oy, op);
15601623 }else
15611624 memellipse(dst, p, e0, e1, c, src, sp, op);
@@ -1592,12 +1655,12 @@ drawmesg(Client *client, void *av, int n) · 30 unmodified lines
15921655 error(Eshortdraw);
15931656 dstid = BGLONG(a+1);
15941657 if(dstid == 0)
1595− error("can't use display as font");
1658+ error("cannot use display as font");
15961659 font = drawlookup(client, dstid, 1);
15971660 if(font == 0)
15981661 error(Enodrawimage);
15991662 if(font->image->layer)
1600− error("can't use window as font");
1663+ error("cannot use window as font");
16011664 ni = BGLONG(a+5);
16021665 if(ni<=0 || ni>4096)
16031666 error("bad font size (4096 chars max)");
@@ -1698,7 +1761,7 @@ drawmesg(Client *client, void *av, int n) · 94 unmodified lines
16981761 error(Edrawmem);
16991762 di = drawlookup(client, dstid, 0);
17001763 if(di == 0)
1701− error("draw: can't happen");
1764+ error("draw: cannot happen");
17021765 di->vers = dn->vers;
17031766 di->name = smalloc(j+1);
17041767 di->fromname = dn->dimage;
@@ -1799,7 +1862,7 @@ drawmesg(Client *client, void *av, int n) · 94 unmodified lines
17991862 if(pp == nil)
18001863 error(Enomem);
18011864 doflush = 0;
1802− if(dstid==0 || (dst->layer && dst->layer->screen->image->data == screenimage->data))
1865+ if(dstid==0 || (screenimage && dst->layer && dst->layer->screen->image->data == screenimage->data))
18031866 doflush = 1; /* simplify test in loop */
18041867 ox = oy = 0;
18051868 esize = 0;
@@ -1901,10 +1964,10 @@ drawmesg(Client *client, void *av, int n) · 95 unmodified lines
19011964 clipr = dst->clipr;
19021965 dst->clipr = r;
19031966 op = drawclientop(client);
1904− l = dst;
1967+ bg = dst;
19051968 if(*a == 'x'){
19061969 /* paint background */
1907− l = drawimage(client, a+47);
1970+ bg = drawimage(client, a+47);
19081971 drawpoint(&q, a+51);
19091972 r.min.x = p.x;
19101973 r.min.y = p.y-font->ascent;
@@ -1920,7 +1983,7 @@ drawmesg(Client *client, void *av, int n) · 9 unmodified lines
19201983 r.max.x += font->fchar[ci].width;
19211984 u += 2;
19221985 }
1923− memdraw(dst, r, l, q, memopaque, ZP, op);
1986+ memdraw(dst, r, bg, q, memopaque, ZP, op);
19241987 u -= 2*ni;
19251988 }
19261989 q = p;
@@ -1930,7 +1993,7 @@ drawmesg(Client *client, void *av, int n) · 3 unmodified lines
19301993 dst->clipr = clipr;
19311994 error(Eindex);
19321995 }
1933− q = drawchar(dst, l, q, src, &sp, font, ci, op);
1996+ q = drawchar(dst, bg, q, src, &sp, font, ci, op);
19341997 u += 2;
19351998 }
19361999 dst->clipr = clipr;
@@ -1988,7 +2051,7 @@ drawmesg(Client *client, void *av, int n) · 51 unmodified lines
19882051 memltofrontn(lp, nw);
19892052 else
19902053 memltorearn(lp, nw);
1991− if(lp[0]->layer->screen->image->data == screenimage->data)
2054+ if(screenimage && lp[0]->layer->screen->image->data == screenimage->data)
19922055 for(j=0; j<nw; j++)
19932056 addflush(lp[j]->layer->screenr);
19942057 ll = drawlookup(client, BGLONG(a+1+1+2), 1);
@@ -2060,7 +2123,6 @@ drawcmap(void) · 65 unmodified lines
20602123 int num, den;
20612124 int i, j;
20622125
2063− drawactive(1); /* to restore map from backup */
20642126 for(r=0,i=0; r!=4; r++)
20652127 for(v=0; v!=4; v++,i+=16){
20662128 for(g=0,j=v-r; g!=4; g++)
@@ -2083,65 +2145,3 @@ drawcmap(void) · 16 unmodified lines
20832145 }
20842146 }
20852147 }
2086−
2087−void
2088−drawblankscreen(int blank)
2089−{
2090− int i, nc;
2091− ulong *p;
2092−
2093− if(blank == sdraw.blanked)
2094− return;
2095− if(!canqlock(&sdraw.lk))
2096− return;
2097− if(!initscreenimage()){
2098− qunlock(&sdraw.lk);
2099− return;
2100− }
2101− p = sdraw.savemap;
2102− nc = screenimage->depth > 8 ? 256 : 1<<screenimage->depth;
2103−
2104− /*
2105− * blankscreen uses the hardware to blank the screen
2106− * when possible. to help in cases when it is not possible,
2107− * we set the color map to be all black.
2108− */
2109− if(blank == 0){ /* turn screen on */
2110− for(i=0; i<nc; i++, p+=3)
2111− setcolor(i, p[0], p[1], p[2]);
2112− // blankscreen(0);
2113− }else{ /* turn screen off */
2114− // blankscreen(1);
2115− for(i=0; i<nc; i++, p+=3){
2116− getcolor(i, &p[0], &p[1], &p[2]);
2117− setcolor(i, 0, 0, 0);
2118− }
2119− }
2120− sdraw.blanked = blank;
2121− qunlock(&sdraw.lk);
2122−}
2123−
2124−/*
2125− * record activity on screen, changing blanking as appropriate
2126− */
2127−void
2128−drawactive(int active)
2129−{
2130−/*
2131− if(active){
2132− drawblankscreen(0);
2133− sdraw.blanktime = MACHP(0)->ticks;
2134− }else{
2135− if(blanktime && sdraw.blanktime && TK2SEC(MACHP(0)->ticks - sdraw.blanktime)/60 >= blanktime)
2136− drawblankscreen(1);
2137− }
2138−*/
2139−}
2140−
2141−int
2142−drawidletime(void)
2143−{
2144− return 0;
2145−/* return TK2SEC(MACHP(0)->ticks - sdraw.blanktime)/60; */
2146−}
2147−
kern/fns.h+0−4
@@ -77,11 +77,7 @@ void devshutdown(void); · 76 unmodified lines
7777 int devstat(Chan*, uchar*, int, Dirtab*, int, Devgen*);
7878 Walkqid* devwalk(Chan*, Chan*, char**, int, Dirtab*, int, Devgen*);
7979 int devwstat(Chan*, uchar*, int);
80−void drawactive(int);
8180 void drawcmap(void);
82−int drawcanqlock(void);
83−void drawqlock(void);
84−void drawqunlock(void);
8581 void dumpaproc(Proc*);
8682 void dumpqueues(void);
8783 void dumpregs(Ureg*);
kern/screen.h+4−7
@@ -48,16 +48,13 @@ void screenload(Rectangle, int, uchar *, Point, int); · 47 unmodified lines
4848 void getcolor(ulong, ulong*, ulong*, ulong*);
4949 void setcolor(ulong, ulong, ulong, ulong);
5050
51−void refreshrect(Rectangle);
52−
5351 void cursorarrow(void);
5452 void setcursor(void);
5553 void mouseset(Point);
56−void drawflushr(Rectangle);
5754 void flushmemscreen(Rectangle);
58−uchar *attachscreen(Rectangle*, ulong*, int*, int*, int*);
55+uchar* attachscreen(Rectangle*, ulong*, int*, int*, int*);
56+
57+extern QLock drawlock;
58+#define ishwimage(i) 1
5959
60−void drawqlock(void);
61−void drawqunlock(void);
62−int drawcanqlock(void);
6360 void terminit(void);
kern/term.c+7−5
@@ -34,8 +34,10 @@ static void termscreenputs(char*, int); · 33 unmodified lines
3434 static void
3535 screenflush(void)
3636 {
37− drawflushr(flushr);
37+ qlock(&drawlock);
38+ flushmemscreen(flushr);
3839 flushr = Rect(10000, 10000, -10000, -10000);
40+ qunlock(&drawlock);
3941 }
4042
4143 static void
@@ -54,7 +56,7 @@ screenwin(void) · 12 unmodified lines
5456 char *greet;
5557 Memimage *grey;
5658
57− drawqlock();
59+ qlock(&drawlock);
5860 back = memwhite;
5961 conscol = memblack;
6062 memfillcolor(gscreen, 0x444488FF);
@@ -86,7 +88,7 @@ screenwin(void) · 25 unmodified lines
8688 curpos = window.min;
8789 window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
8890 flushmemscreen(gscreen->r);
89− drawqunlock();
91+ qunlock(&drawlock);
9092 }
9193
9294 void
@@ -184,7 +186,7 @@ termscreenputs(char *s, int n) · 91 unmodified lines
184186 char buf[4];
185187
186188 lock(&screenlock);
187− locked = drawcanqlock();
189+ locked = canqlock(&drawlock);
188190 while(n > 0){
189191 i = chartorune(&r, s);
190192 if(i == 0){
@@ -199,7 +201,7 @@ termscreenputs(char *s, int n) · 8 unmodified lines
199201 screenputc(buf);
200202 }
201203 if(locked)
202− drawqunlock();
204+ qunlock(&drawlock);
203205 screenflush();
204206 unlock(&screenlock);
205207 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t