History

devdraw: DName

yiyus committed 15 years ago

Commit a36fccd1 parent 88a652f6 files · +195 −51Browse files

Unified · Split

6 files
  1. devwsys/dat.h +46 −35
  2. devwsys/devdraw.c +104 −4
  3. devwsys/fns.h +3 −1
  4. devwsys/ixp_fsys.c +40 −8
  5. devwsys/window.c +1 −2
  6. devwsys/x11/window.c +1 −1
devwsys/dat.h+46−35
@@ -32,12 +32,12 @@ typedef struct Draw Draw; · 31 unmodified lines
3232 typedef struct Client Client;
3333 typedef struct FChar FChar;
3434 typedef struct DImage DImage;
35+typedef struct DName DName;
3536 typedef struct DScreen DScreen;
3637 typedef struct Kbdbuf Kbdbuf;
3738 typedef struct Mousebuf Mousebuf;
3839 typedef struct Reqbuf Reqbuf;
3940 typedef struct Window Window;
40−typedef struct Wsysmsg Wsysmsg;
4141
4242 /* Drawing device */
4343 #define NHASH (1<<5)
@@ -45,24 +45,26 @@ typedef struct Wsysmsg Wsysmsg; · 1 unmodified line
4545
4646 struct Draw
4747 {
48+ int nname;
49+ DName* name;
4850 Rectangle flushrect;
4951 };
5052
5153 struct Client
5254 {
53− /*Ref r;*/
54− DImage* dimage[NHASH];
55+ int r; // Ref
56+ DImage* dimage[NHASH];
5557 // CScreen* cscreen;
5658 // Refresh* refresh;
57−// Rendez refrend;
59+// Rendez refrend;
5860 Window *window;
59−// uchar* readdata;
60−// int nreaddata;
61+ uchar* readdata;
62+ int nreaddata;
6163 int busy;
6264 int clientid;
6365 int slot;
6466 // int refreshme;
65−// int infoid;
67+ int infoid;
6668 int op;
6769 };
6870
@@ -70,10 +72,10 @@ struct FChar · 1 unmodified line
7072 {
7173 int minx; /* left edge of bits */
7274 int maxx; /* right edge of bits */
73− uchar miny; /* first non-zero scan-line */
74− uchar maxy; /* last non-zero scan-line + 1 */
75− schar left; /* offset of baseline */
76− uchar width; /* width of baseline */
75+ uchar miny; /* first non-zero scan-line */
76+ uchar maxy; /* last non-zero scan-line + 1 */
77+ schar left; /* offset of baseline */
78+ uchar width; /* width of baseline */
7779 };
7880
7981 struct DImage
@@ -85,10 +87,18 @@ struct DImage · 5 unmodified lines
8587 Memimage* image;
8688 int ascent;
8789 int nfchar;
88− FChar* fchar;
89− DScreen* dscreen; /* 0 if not a window */
90+ FChar* fchar;
91+ DScreen* dscreen; /* 0 if not a window */
9092 DImage* fromname; /* image this one is derived from, by name */
91− DImage* next;
93+ DImage* next;
94+};
95+
96+struct DName
97+{
98+ char *name;
99+ Client *client;
100+ DImage* dimage;
101+ int vers;
92102 };
93103
94104 struct DScreen
@@ -99,20 +109,20 @@ struct DScreen · 4 unmodified lines
99109 DImage *dimage;
100110 DImage *dfill;
101111 Memscreen* screen;
102− Client* owner;
112+ Client* owner;
103113 DScreen* next;
104114 };
105115
106116 /* Events */
107117 struct Kbdbuf
108118 {
109− Rune r[32];
110− int ri;
111− int wi;
112− int stall;
119+ Rune r[32];
120+ int ri;
121+ int wi;
122+ int stall;
113123 /* Used by kbdputc */
114124 uchar k[5*UTFmax];
115− int alting, nk;
125+ int alting, nk;
116126 };
117127
118128 struct Mouse
@@ -142,23 +152,24 @@ struct Reqbuf · 23 unmodified lines
142152 /* Window system */
143153 struct Window
144154 {
145− int id;
146− int deleted;
147− char *label;
148− Draw draw;
149− Kbdbuf kbd;
155+ int id;
156+ int deleted;
157+ char *label;
158+ Draw draw;
159+ Kbdbuf kbd;
150160 Memimage *screenimage;
151− Mousebuf mouse;
152− Reqbuf kbdreqs;
153− Reqbuf mousereqs;
154− Rectangle r;
155− void *x;
161+ Memdata screendata;
162+ Mousebuf mouse;
163+ Reqbuf kbdreqs;
164+ Reqbuf mousereqs;
165+ Rectangle r;
166+ void *x;
156167 };
157168
158169 /* Global Vars */
159−int debuglevel;
160−int nwindow;
161−Window **window;
162−int nclient;
163−Client** client;
170+int debuglevel;
171+int nwindow;
172+Window **window;
173+int nclient;
174+Client **client;
164175
devwsys/devdraw.c+104−4
@@ -6,7 +6,15 @@ · 5 unmodified lines
66 #include "dat.h"
77 #include "fns.h"
88
9+/* Error messages */
10+static char
11+ Enodrawimage[] = "unknown id for draw image",
12+ Eoldname[] = "named image no longer valid";
13+
14+DImage* drawlookup(Client*, int, int);
15+
916 int nclient = 0;
17+char *error = nil;
1018
1119 Client*
1220 drawnewclient(Window *w)
@@ -30,10 +38,9 @@ drawnewclient(Window *w) · 17 unmodified lines
3038 nclient++;
3139 cp[i] = 0;
3240 }
33− cl = malloc(sizeof(Client));
41+ cl = mallocz(sizeof(Client), 1);
3442 if(cl == 0)
3543 return 0;
36− memset(cl, 0, sizeof(Client));
3744 cl->slot = i;
3845 cl->clientid = ++clientid;
3946 cl->op = SoverD;
@@ -64,9 +71,102 @@ drawinstall(Client *client, int id, Memimage *i, DScreen *dscreen) · 24 unmodified lines
6471 return i;
6572 }
6673
74+void
75+readdrawctl(char *buf, Client *cl)
76+{
77+ int n;
78+ DImage *di;
79+ Memimage *i;
80+
81+ if(cl->infoid < 0)
82+ error = Enodrawimage;
83+ if(cl->infoid == 0){
84+ i = cl->window->screenimage;
85+ if(i == nil)
86+ error = Enodrawimage;
87+ }else{
88+ di = drawlookup(cl, cl->infoid, 1);
89+ if(di == nil)
90+ error = Enodrawimage;
91+ i = di->image;
92+ }
93+ n = sprint(buf, "%11d %11d %11s %11d %11d %11d %11d %11d %11d %11d %11d %11d ",
94+ cl->clientid, cl->infoid, chantostr(buf, i->chan), (i->flags&Frepl)==Frepl,
95+ i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y,
96+ i->clipr.min.x, i->clipr.min.y, i->clipr.max.x, i->clipr.max.y);
97+ cl->infoid = -1;
98+}
99+
100+void
101+drawmesg(Client *client, void *av, int n)
102+{
103+}
104+
105+static
67106 int
68−initscreenimage(Memimage *m)
107+drawcmp(char *a, char *b, int n)
108+{
109+ if(strlen(a) != n)
110+ return 1;
111+ return memcmp(a, b, n);
112+}
113+
114+DName*
115+drawlookupname(Draw *draw, int n, char *str)
69116 {
70− // TODO: inferno-os/emu/port/devdraw.c:855,881
117+ DName *name, *ename;
118+
119+ name = draw->name;
120+ ename = &name[draw->nname];
121+ for(; name<ename; name++)
122+ if(drawcmp(name->name, str, n) == 0)
123+ return name;
124+ return 0;
125+}
126+
127+int
128+drawgoodname(Draw *draw, DImage *d)
129+{
130+ DName *n;
131+
132+ /* if window, validate the screen's own images */
133+ if(d->dscreen)
134+ if(drawgoodname(draw, d->dscreen->dimage) == 0
135+ || drawgoodname(draw, d->dscreen->dfill) == 0)
136+ return 0;
137+ if(d->name == nil)
138+ return 1;
139+ n = drawlookupname(draw, strlen(d->name), d->name);
140+ if(n==nil || n->vers!=d->vers)
141+ return 0;
71142 return 1;
72143 }
144+
145+DImage*
146+drawlookup(Client *client, int id, int checkname)
147+{
148+ DImage *d;
149+ Draw *draw;
150+
151+ d = client->dimage[id&HASHMASK];
152+ while(d){
153+ if(d->id == id){
154+ draw = &client->window->draw;
155+ if(checkname && !drawgoodname(draw, d))
156+ error = Eoldname;
157+ return d;
158+ }
159+ d = d->next;
160+ }
161+ return 0;
162+}
163+
164+char*
165+drawerr(void)
166+{
167+ char *err;
168+
169+ err = error;
170+ error = nil;
171+ return err;
172+}
devwsys/fns.h+3−1
@@ -4,7 +4,9 @@ · 3 unmodified lines
44 /* Devdraw */
55 Client* drawnewclient(Window*);
66 Memimage* drawinstall(Client*, int, Memimage*, DScreen*);
7−int initscreenimage(Memimage*);
7+void readdrawctl(char*, Client*);
8+void drawmesg(Client*, void*, int);
9+char* drawerr(void);
810
911 /* Keyboard */
1012 void writekbd(Window*, int);
devwsys/ixp_fsys.c+40−8
@@ -16,6 +16,9 @@ union IxpFileIdU { · 15 unmodified lines
1616 };
1717 #include <ixp_srvutil.h>
1818
19+#define incref(r) ((*r) = ++(*r))
20+#define decref(r) ((*r) = --(*r))
21+
1922 /* Constants */
2023 enum {
2124 /* Dirs */
@@ -281,10 +284,11 @@ fs_open(Ixp9Req *r) { · 259 unmodified lines
281284 return;
282285 }
283286 cl->busy = 1;
284− d = &cl->window->draw;
287+ w = cl->window;
288+ d = &w->draw;
285289 d->flushrect = Rect(10000, 10000, -10000, -10000);
286− // drawinstall(cl, 0, screenimage, 0);
287− // incref(&cl->r);
290+ drawinstall(cl, 0, w->screenimage, 0);
291+ incref(&cl->r);
288292 break;
289293 case FsFMouse:
290294 w = f->p.window;
@@ -315,8 +319,9 @@ fs_walk(Ixp9Req *r) { · 24 unmodified lines
315319
316320 void
317321 fs_read(Ixp9Req *r) {
318− char buf[512];
322+ char buf[512], *err;
319323 IxpFileId *f;
324+ Client *cl;
320325 Window *w;
321326
322327 debug("fs_read(%p)\n", r);
@@ -338,14 +343,28 @@ fs_read(Ixp9Req *r) { · 15 unmodified lines
338343 ixp_pending_respond(r);
339344 return;
340345 }
346+ cl = f->p.client;
341347 switch(f->tab.type) {
342− case FsFData:
343− sprint(buf, "%d", f->p.client->clientid);
348+ case FsFCtl:
349+ readdrawctl(buf, cl);
350+ err = drawerr();
351+ if(err != nil) {
352+ ixp_respond(r, err);
353+ return;
354+ }
344355 ixp_srv_readbuf(r, buf, strlen(buf));
356+ return;
357+ case FsFData:
358+ if(cl->readdata == nil) {
359+ ixp_respond(r, "no draw data");
360+ return;
361+ }
362+ ixp_srv_readbuf(r, cl->readdata, cl->nreaddata);
345363 ixp_respond(r, nil);
364+ free(cl->readdata);
365+ cl->readdata = nil;
346366 return;
347367 case FsFNew:
348− case FsFCtl:
349368 case FsFColormap:
350369 case FsFRefresh:
351370 return;
@@ -420,6 +439,7 @@ fs_write(Ixp9Req *r) { · 68 unmodified lines
420439 char *label;
421440 IxpFileId *f;
422441 Window *w;
442+ Client *cl;
423443
424444 debug("fs_write(%p)\n", r);
425445
@@ -433,10 +453,22 @@ fs_write(Ixp9Req *r) { · 7 unmodified lines
433453 return;
434454 }
435455
456+ cl = f->p.client;
436457 switch(f->tab.type) {
458+ case FsFData:
459+ r->ofcall.io.count = r->ifcall.io.count;
460+ drawmesg(cl, r->ifcall.twrite.data, r->ofcall.rwrite.count);
461+ // drawwakeall();
462+ ixp_respond(r, nil);
463+ return;
437464 case FsFNew:
438465 case FsFCtl:
439− case FsFData:
466+ r->ofcall.io.count = r->ifcall.io.count;
467+ if(r->ofcall.io.count != 4)
468+ ixp_respond(r, "unknown draw control request");
469+ cl->infoid = BGLONG((uchar*)r->ifcall.twrite.data);
470+ ixp_respond(r, nil);
471+ return;
440472 case FsFColormap:
441473 case FsFRefresh:
442474 return;
devwsys/window.c+1−2
@@ -14,13 +14,12 @@ newwin(char *label, char *winsize) · 13 unmodified lines
1414 static int id = 0;
1515 Window *w;
1616
17− if(!(w = malloc(sizeof(Window))))
17+ if(!(w = mallocz(sizeof(Window), 1)))
1818 return nil;
1919 if(!(window = realloc(window, ++nwindow*sizeof(Window*))))
2020 return nil;
2121 window[nwindow-1] = w;
2222
23− memset(w, 0, sizeof(*w));
2423 w->id = id++;
2524 w->label = label;
2625
devwsys/x11/window.c+1−1
@@ -34,7 +34,7 @@ xattach(Window *w, char *winsize) · 33 unmodified lines
3434 w->r = xmapwin(xw, havemin, w->r);
3535 w->x = xw;
3636 w->screenimage = xallocmemimage(w, w->r, xconn.chan, xw->screenpm);
37− initscreenimage(w->screenimage);
37+ // initscreenimage(w);
3838 }
3939
4040 Rectangle