removed screen clearing from the screensize() function as this is now done by vgascreenwin(). initialize softcursor backup image with DTransparent color. produce a nice and distinctive image in vgascreenwin() like drawterm: text is now black on white and border size was reduced from 48 pixel to 30. it draws a purple background and a distinctive window frame with the title "Plan 9 Console" wich makes it more distinct from the cga text console. vgaimageinit just assigns text and background color from predefined memblack and memwhite instead of allocating its own colors. Reference: /n/sources/patch/maybe/vgaconsole-softcurs Date: Sat Mar 12 18:04:28 CET 2011 Signed-off-by: cinap_lenrek@gmx.de --- /sys/src/9/pc/screen.c Sat Mar 12 17:55:00 2011 +++ /sys/src/9/pc/screen.c Sat Mar 12 17:54:57 2011 @@ -39,8 +39,7 @@ }; int didswcursorinit; - -static void *softscreen; +void *softscreen; int screensize(int x, int y, int z, ulong chan) @@ -55,6 +54,7 @@ } memimageinit(); + scr = &vgascreen[0]; oldsoft = softscreen; @@ -83,6 +83,7 @@ gscreen = allocmemimaged(Rect(0,0,x,y), chan, &gscreendata); if(gscreen == nil) error("no memory for vga memimage"); + vgaimageinit(chan); scr->palettedepth = 6; /* default */ @@ -95,10 +96,6 @@ poperror(); if(oldsoft) xfree(oldsoft); - - memimagedraw(gscreen, gscreen->r, memblack, ZP, nil, ZP, S); - flushmemscreen(gscreen->r); - if(didswcursorinit) swcursorinit(); drawcmap(); @@ -360,34 +357,25 @@ Memimage *dst, *src, *mask; int m; - if(hwaccel == 0) - return 0; - scr = &vgascreen[0]; if((dst=par->dst) == nil || dst->data == nil) return 0; if((src=par->src) == nil || src->data == nil) - return 0; + src = nil; if((mask=par->mask) == nil || mask->data == nil) - return 0; - + mask = nil; if(scr->cur == &swcursor){ - /* - * always calling swcursorhide here doesn't cure - * leaving cursor tracks nor failing to refresh menus - * with the latest libmemdraw/draw.c. - */ if(dst->data->bdata == gscreendata.bdata) swcursoravoid(par->r); - if(src->data->bdata == gscreendata.bdata) + if(src && src->data->bdata == gscreendata.bdata) swcursoravoid(par->sr); - if(mask->data->bdata == gscreendata.bdata) + if(mask && mask->data->bdata == gscreendata.bdata) swcursoravoid(par->mr); } - - if(dst->data->bdata != gscreendata.bdata) + if(hwaccel == 0) + return 0; + if(dst->data->bdata != gscreendata.bdata || src == nil || mask == nil) return 0; - if(scr->fill==nil && scr->scroll==nil) return 0; @@ -693,7 +681,7 @@ void swcursorinit(void) { - static int init, warned; + static int init; VGAscr *scr; didswcursorinit = 1; @@ -701,17 +689,10 @@ init = 1; addclock0link(swcursorclock, 10); } - scr = &vgascreen[0]; - if(scr==nil || scr->gscreen==nil) - return; - if(scr->dev == nil || scr->dev->linear == nil){ - if(!warned){ - print("cannot use software cursor on non-linear vga screen\n"); - warned = 1; - } + scr = &vgascreen[0]; + if(scr->gscreen==nil) return; - } if(swback){ freememimage(swback); @@ -730,7 +711,7 @@ print("software cursor: allocmemimage fails"); return; } - + memfillcolor(swback, DTransparent); memfillcolor(swmask, DOpaque); memfillcolor(swmask1, DOpaque); memfillcolor(swimg, DBlack); --- /sys/src/9/pc/vga.c Sat Mar 12 17:55:05 2011 +++ /sys/src/9/pc/vga.c Sat Mar 12 17:55:02 2011 @@ -12,8 +12,8 @@ #include #include "screen.h" -static Memimage* back; static Memimage *conscol; +static Memimage *back; static Point curpos; static Rectangle window; @@ -23,25 +23,10 @@ int drawdebug; void -vgaimageinit(ulong chan) +vgaimageinit(ulong) { - if(back == nil){ - back = allocmemimage(Rect(0,0,1,1), chan); /* RSC BUG */ - if(back == nil) - panic("back alloc"); /* RSC BUG */ - back->flags |= Frepl; - back->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF); - memfillcolor(back, DBlack); - } - - if(conscol == nil){ - conscol = allocmemimage(Rect(0,0,1,1), chan); /* RSC BUG */ - if(conscol == nil) - panic("conscol alloc"); /* RSC BUG */ - conscol->flags |= Frepl; - conscol->clipr = Rect(-0x3FFFFFF, -0x3FFFFFF, 0x3FFFFFF, 0x3FFFFFF); - memfillcolor(conscol, DWhite); - } + conscol = memblack; + back = memwhite; } static void @@ -69,13 +54,11 @@ int h, w, pos; Rectangle r; -// drawdebug = 1; if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)]) xp = xbuf; h = scr->memdefont->height; switch(buf[0]){ - case '\n': if(curpos.y+h >= window.max.y){ vgascroll(scr); @@ -100,7 +83,7 @@ pos = 4-(pos%4); *xp++ = curpos.x; r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h); - memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min, S); + memimagedraw(scr->gscreen, r, back, ZP, nil, ZP, S); curpos.x += pos*w; break; @@ -109,7 +92,7 @@ break; xp--; r = Rect(*xp, curpos.y, curpos.x, curpos.y+h); - memimagedraw(scr->gscreen, r, back, back->r.min, nil, ZP, S); + memimagedraw(scr->gscreen, r, back, r.min, nil, ZP, S); combinerect(flushr, r); curpos.x = *xp; break; @@ -126,12 +109,11 @@ *xp++ = curpos.x; r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y+h); - memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min, S); + memimagedraw(scr->gscreen, r, back, r.min, nil, ZP, S); memimagestring(scr->gscreen, curpos, conscol, ZP, scr->memdefont, buf); combinerect(flushr, r); curpos.x += w; } -// drawdebug = 0; } static void @@ -187,16 +169,51 @@ void vgascreenwin(VGAscr* scr) { - int h, w; + Memimage *i; + Rectangle r; + Point p; + int h; + qlock(&drawlock); + h = scr->memdefont->height; - w = scr->memdefont->info[' '].width; + r = scr->gscreen->r; + + if(i = allocmemimage(Rect(0,0,1,1), CMAP8)){ + i->flags |= Frepl; + i->clipr = scr->gscreen->r; + memfillcolor(i, 0x444488FF); + memimagedraw(scr->gscreen, r, i, ZP, nil, ZP, S); + freememimage(i); + } - window = insetrect(scr->gscreen->r, 48); - window.max.x = window.min.x+((window.max.x-window.min.x)/w)*w; - window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h; + window = insetrect(r, 20); + memimagedraw(scr->gscreen, window, conscol, ZP, memopaque, ZP, S); + window = insetrect(window, 4); + memimagedraw(scr->gscreen, window, back, ZP, memopaque, ZP, S); + + if(i = allocmemimage(Rect(0,0,1,1), CMAP8)){ + i->flags |= Frepl; + i->clipr = scr->gscreen->r; + memfillcolor(i, 0xAAAAAAFF); + memimagedraw(scr->gscreen, Rect(window.min.x, window.min.y, + window.max.x, window.min.y+h+5+6), i, ZP, nil, ZP, S); + freememimage(i); + + window = insetrect(window, 5); + p = addpt(window.min, Pt(10, 0)); + memimagestring(scr->gscreen, p, memblack, ZP, scr->memdefont, " Plan 9 Console "); + window.min.y += h+6; + } else + window = insetrect(window, 5); + + window.max.y = window.min.y+(Dy(window)/h)*h; curpos = window.min; + flushmemscreen(r); + + qunlock(&drawlock); + screenputs = vgascreenputs; } @@ -250,14 +267,14 @@ Point p; scr = &vgascreen[0]; - if(scr->vaddr == nil || screenputs != vgascreenputs) + if(scr->gscreen == nil || screenputs != vgascreenputs) return; p = memsubfontwidth(scr->memdefont, s); w = p.x; h = scr->memdefont->height; r = Rect(0, 0, w, h); - memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min, S); + memimagedraw(scr->gscreen, r, back, r.min, nil, ZP, S); memimagestring(scr->gscreen, r.min, conscol, ZP, scr->memdefont, s); -// flushmemscreen(r); + flushmemscreen(r); }