2 #include "../port/lib.h"
7 #include "../port/error.h"
42 flushmemscreen(Rectangle r)
44 if(badrect(fbscreen.rect))
47 combinerect(&fbscreen.rect, r);
58 attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
65 *chan = gscreen->chan;
66 *width = gscreen->width;
68 /* make devdraw use gscreen->data */
69 *softscreen = 0xa110c;
72 return gscreen->data->bdata;
76 getcolor(ulong, ulong *, ulong *, ulong *)
81 setcolor(ulong, ulong, ulong, ulong)
99 return !badrect(fbscreen.rect);
106 uchar *sp, *dp, *top;
109 for(sno = 0; sno < NSEG; sno++)
110 if(up->seg[sno] == nil && sno != ESEG)
129 sleep(&fbscreen, isflush, nil);
134 if(badrect(r) || gscreen == nil || rectclip(&r, gscreen->r) == 0){
138 w = sizeof(ulong)*gscreen->width;
139 n = bytesperline(r, gscreen->depth);
140 sp = byteaddr(gscreen, r.min);
141 dp = (uchar*)fbscreen.addr + (sp - &gscreen->data->bdata[gscreen->zero]);
142 top = (uchar*)up->seg[sno]->top;
143 if(dp+(Dy(r)-1)*w+n > top)
144 r.max.y = (top-(uchar*)fbscreen.addr)/w;
147 while(r.min.y < r.max.y) {
162 static Cmdtab fbctlmsg[] = {
169 fbctlwrite(Chan*, void *a, long n, vlong)
183 ct = lookupcmd(cb, fbctlmsg, nelem(fbctlmsg));
186 addr = strtoul(cb->f[1], 0, 0);
188 eqlock(&up->seglock);
189 if((s = seg(up, addr, 0)) == nil || (s->type&SG_RONLY) != 0){
190 qunlock(&up->seglock);
194 qunlock(&up->seglock);
196 if(fbscreen.proc != nil){
197 postnote(fbscreen.proc, 0, "die", NUser);
198 while(fbscreen.proc != nil)
201 fbscreen.addr = addr;
202 kproc("fbflush", flushproc, s);
206 x = strtoul(cb->f[1], &p, 0);
207 if(x == 0 || x > 10240)
211 y = strtoul(p, &p, 0);
212 if(y == 0 || y > 10240)
216 z = strtoul(p, &p, 0);
218 if((chan = strtochan(cb->f[2])) == 0)
219 error("bad channel");
220 if(chantodepth(chan) != z)
221 error("depth, channel do not match");
226 if(memimageinit() < 0){
228 error("memimageinit failed");
231 freememimage(gscreen);
234 gscreen = allocmemimage(Rect(0,0,x,y), chan);
240 error("no framebuffer");
251 fbctlread(Chan*, void *a, long n, vlong offset)
253 char buf[256], chan[32], *p, *e;
259 p = seprint(p, e, "size %dx%dx%d %s\n",
260 Dx(gscreen->r), Dy(gscreen->r), gscreen->depth,
261 chantostr(chan, gscreen->chan));
264 seprint(p, e, "addr %#p\n", fbscreen.addr);
265 return readstr(offset, a, n, buf);