Browse Source

Plan 9 from Bell Labs 2005-05-01

David du Colombier 15 years ago
parent
commit
439fe52cac
4 changed files with 108 additions and 72 deletions
  1. 9 1
      dist/replica/_plan9.db
  2. 9 9
      dist/replica/plan9.db
  3. 9 0
      dist/replica/plan9.log
  4. 81 62
      sys/src/libmemdraw/draw.c

+ 9 - 1
dist/replica/_plan9.db

@@ -12586,7 +12586,7 @@ sys/src/libmemdraw/cload.c - 664 sys sys 944961741 1337
 sys/src/libmemdraw/cmap.c - 664 sys sys 1029430942 25150
 sys/src/libmemdraw/cread.c - 664 sys sys 1014930216 1982
 sys/src/libmemdraw/defont.c - 664 sys sys 944961741 1288
-sys/src/libmemdraw/draw.c - 664 sys sys 1039752933 55250
+sys/src/libmemdraw/draw.c - 664 sys sys 1114867396 55720
 sys/src/libmemdraw/drawtest.c - 664 sys sys 1045502228 23441
 sys/src/libmemdraw/ellipse.c - 664 sys sys 1039752933 4866
 sys/src/libmemdraw/fillpoly.c - 664 sys sys 1039752933 9841
@@ -12963,3 +12963,11 @@ usr/glenda/lib/profile - 664 glenda glenda 1105128663 890
 usr/glenda/readme.acme - 664 glenda glenda 1019860628 4753
 usr/glenda/readme.rio - 664 glenda glenda 1019860628 6370
 usr/glenda/tmp - 20000000775 glenda glenda 1018802620 0
+386/bin/crop - 775 sys sys 1114917029 116008
+386/bin/iconv - 775 sys sys 1114917030 113265
+386/bin/resample - 775 sys sys 1114917030 120740
+386/bin/topng - 775 sys sys 1114917031 138328
+386/bin/vncs - 775 sys sys 1114917032 471140
+386/bin/togif - 775 sys sys 1114917030 189766
+386/bin/toppm - 775 sys sys 1114917031 165150
+386/lib/libmemdraw.a - 664 sys sys 1114917033 283978

+ 9 - 9
dist/replica/plan9.db

@@ -185,7 +185,7 @@
 386/bin/cp - 775 sys sys 1104121996 63215
 386/bin/cpp - 775 sys sys 1113794392 149779
 386/bin/cpu - 775 sys sys 1108354550 137694
-386/bin/crop - 775 sys sys 1104121998 115763
+386/bin/crop - 775 sys sys 1114917029 116008
 386/bin/date - 775 sys sys 1104121998 43261
 386/bin/db - 775 sys sys 1114484869 336153
 386/bin/dc - 775 sys sys 1104121999 99028
@@ -269,7 +269,7 @@
 386/bin/html2ms - 775 sys sys 1104122018 66095
 386/bin/htmlfmt - 775 sys sys 1104122019 160683
 386/bin/ico - 775 sys sys 1106799175 160621
-386/bin/iconv - 775 sys sys 1104122020 113020
+386/bin/iconv - 775 sys sys 1114917030 113265
 386/bin/idiff - 775 sys sys 1104122020 76112
 386/bin/import - 775 sys sys 1104122020 100041
 386/bin/iostats - 775 sys sys 1108354556 97978
@@ -378,7 +378,7 @@
 386/bin/replica/scan - 775 sys sys 1020319083 39
 386/bin/replica/setupdirs - 775 sys sys 1020319083 44
 386/bin/replica/updatedb - 775 sys sys 1104122050 95895
-386/bin/resample - 775 sys sys 1104122050 120495
+386/bin/resample - 775 sys sys 1114917030 120740
 386/bin/rio - 775 sys sys 1111205298 309212
 386/bin/rm - 775 sys sys 1104122051 61333
 386/bin/rx - 775 sys sys 1104122051 82055
@@ -420,10 +420,10 @@
 386/bin/time - 775 sys sys 1104122063 61386
 386/bin/tlsclient - 775 sys sys 1109132004 197187
 386/bin/tlssrv - 775 sys sys 1109132004 197434
-386/bin/togif - 775 sys sys 1108960015 189521
+386/bin/togif - 775 sys sys 1114917030 189766
 386/bin/toico - 775 sys sys 1104122065 123524
-386/bin/topng - 775 sys sys 1108872012 138083
-386/bin/toppm - 775 sys sys 1104122065 164905
+386/bin/topng - 775 sys sys 1114917031 138328
+386/bin/toppm - 775 sys sys 1114917031 165150
 386/bin/touch - 775 sys sys 1104122066 63763
 386/bin/tprof - 775 sys sys 1114484873 289115
 386/bin/tr - 775 sys sys 1104122066 61851
@@ -493,7 +493,7 @@
 386/bin/venti/verifyarena - 775 sys sys 1104122086 104270
 386/bin/venti/wrarena - 775 sys sys 1104122086 176179
 386/bin/venti/write - 775 sys sys 1104122087 102499
-386/bin/vncs - 775 sys sys 1110946101 470895
+386/bin/vncs - 775 sys sys 1114917032 471140
 386/bin/vncv - 775 sys sys 1109132010 518017
 386/bin/vt - 775 sys sys 1106799182 172859
 386/bin/vtdump - 775 sys sys 1104122090 159451
@@ -550,7 +550,7 @@
 386/lib/libip.a - 664 sys sys 1108268398 35602
 386/lib/libl.a - 664 sys sys 1108268398 5384
 386/lib/libmach.a - 664 sys sys 1114484874 755168
-386/lib/libmemdraw.a - 664 sys sys 1110946101 283198
+386/lib/libmemdraw.a - 664 sys sys 1114917033 283978
 386/lib/libmemlayer.a - 664 sys sys 1108699740 47360
 386/lib/libmp.a - 664 sys sys 1108268401 79532
 386/lib/libndb.a - 664 sys sys 1108268401 60666
@@ -12586,7 +12586,7 @@ sys/src/libmemdraw/cload.c - 664 sys sys 944961741 1337
 sys/src/libmemdraw/cmap.c - 664 sys sys 1029430942 25150
 sys/src/libmemdraw/cread.c - 664 sys sys 1014930216 1982
 sys/src/libmemdraw/defont.c - 664 sys sys 944961741 1288
-sys/src/libmemdraw/draw.c - 664 sys sys 1039752933 55250
+sys/src/libmemdraw/draw.c - 664 sys sys 1114867396 55720
 sys/src/libmemdraw/drawtest.c - 664 sys sys 1045502228 23441
 sys/src/libmemdraw/ellipse.c - 664 sys sys 1039752933 4866
 sys/src/libmemdraw/fillpoly.c - 664 sys sys 1039752933 9841

+ 9 - 0
dist/replica/plan9.log

@@ -14849,3 +14849,12 @@
 1114745573 1 c 386/bin/upas/nedmail - 775 sys sys 1114744259 156346
 1114745573 2 c acme/bin/386/Mail - 775 sys sys 1114744260 179115
 1114804874 0 c sys/games/lib/fortunes - 664 sys sys 1114803424 253725
+1114867888 0 c sys/src/libmemdraw/draw.c - 664 sys sys 1114867396 55720
+1114918292 0 c 386/bin/crop - 775 sys sys 1114917029 116008
+1114918292 1 c 386/bin/iconv - 775 sys sys 1114917030 113265
+1114918292 2 c 386/bin/resample - 775 sys sys 1114917030 120740
+1114918292 3 c 386/bin/topng - 775 sys sys 1114917031 138328
+1114918292 4 c 386/bin/vncs - 775 sys sys 1114917032 471140
+1114918292 5 c 386/bin/togif - 775 sys sys 1114917030 189766
+1114918292 6 c 386/bin/toppm - 775 sys sys 1114917031 165150
+1114918292 7 c 386/lib/libmemdraw.a - 664 sys sys 1114917033 283978

+ 81 - 62
sys/src/libmemdraw/draw.c

@@ -441,7 +441,6 @@ struct Param {
 static uchar *drawbuf;
 static int	ndrawbuf;
 static int	mdrawbuf;
-static Param spar, mpar, dpar;	/* easier on the stacks */
 static Readfn	greymaskread, replread, readptr;
 static Writefn	nullwrite;
 static Calcfn	alphacalc0, alphacalc14, alphacalc2810, alphacalc3679, alphacalc5, alphacalc11, alphacalcS;
@@ -452,7 +451,7 @@ static Readfn*	readalphafn(Memimage*);
 static Writefn*	writefn(Memimage*);
 
 static Calcfn*	boolcopyfn(Memimage*, Memimage*);
-static Readfn*	convfn(Memimage*, Param*, Memimage*, Param*);
+static Readfn*	convfn(Memimage*, Param*, Memimage*, Param*, int*);
 static Readfn*	ptrfn(Memimage*);
 
 static Calcfn *alphacalc[Ncomp] = 
@@ -487,59 +486,66 @@ static Calcfn *boolcalc[Ncomp] =
 	boolcalc1011,		/* SoverD */
 };
 
-static int
-allocdrawbuf(void)
+/*
+ * Avoid standard Lock, QLock so that can be used in kernel.
+ */
+typedef struct Dbuf Dbuf;
+struct Dbuf
 {
 	uchar *p;
+	int n;
+	Param spar, mpar, dpar;
+	int inuse;
+};
+static Dbuf dbuf[10];
 
-	if(ndrawbuf > mdrawbuf){
-		p = realloc(drawbuf, ndrawbuf);
-		if(p == nil){
-			werrstr("memimagedraw out of memory");
-			return -1;
-		}
-		drawbuf = p;
-		mdrawbuf = ndrawbuf;
+static Dbuf*
+allocdbuf(void)
+{
+	int i;
+
+	for(i=0; i<nelem(dbuf); i++){
+		if(dbuf[i].inuse)
+			continue;
+		if(!_tas(&dbuf[i].inuse))
+			return &dbuf[i];
 	}
-	return 0;
+	return nil;
 }
 
-static Param
-getparam(Memimage *img, Rectangle r, int convgrey, int needbuf)
+static void
+getparam(Param *p, Memimage *img, Rectangle r, int convgrey, int needbuf, int *ndrawbuf)
 {
-	Param p;
 	int nbuf;
 
-	memset(&p, 0, sizeof p);
+	memset(p, 0, sizeof *p);
 
-	p.img = img;
-	p.r = r;
-	p.dx = Dx(r);
-	p.needbuf = needbuf;
-	p.convgrey = convgrey;
+	p->img = img;
+	p->r = r;
+	p->dx = Dx(r);
+	p->needbuf = needbuf;
+	p->convgrey = convgrey;
 
 	assert(img->r.min.x <= r.min.x && r.min.x < img->r.max.x);
 
-	p.bytey0s = byteaddr(img, Pt(img->r.min.x, img->r.min.y));
-	p.bytermin = byteaddr(img, Pt(r.min.x, img->r.min.y));
-	p.bytey0e = byteaddr(img, Pt(img->r.max.x, img->r.min.y));
-	p.bwidth = sizeof(ulong)*img->width;
+	p->bytey0s = byteaddr(img, Pt(img->r.min.x, img->r.min.y));
+	p->bytermin = byteaddr(img, Pt(r.min.x, img->r.min.y));
+	p->bytey0e = byteaddr(img, Pt(img->r.max.x, img->r.min.y));
+	p->bwidth = sizeof(ulong)*img->width;
 
-	assert(p.bytey0s <= p.bytermin && p.bytermin <= p.bytey0e);
+	assert(p->bytey0s <= p->bytermin && p->bytermin <= p->bytey0e);
 
-	if(p.r.min.x == p.img->r.min.x)
-		assert(p.bytermin == p.bytey0s);
+	if(p->r.min.x == p->img->r.min.x)
+		assert(p->bytermin == p->bytey0s);
 
 	nbuf = 1;
 	if((img->flags&Frepl) && Dy(img->r) <= MAXBCACHE && Dy(img->r) < Dy(r)){
-		p.replcache = 1;
+		p->replcache = 1;
 		nbuf = Dy(img->r);
 	}
-	p.bufdelta = 4*p.dx;
-	p.bufoff = ndrawbuf;
-	ndrawbuf += p.bufdelta*nbuf;
-
-	return p;
+	p->bufdelta = 4*p->dx;
+	p->bufoff = *ndrawbuf;
+	*ndrawbuf += p->bufdelta*nbuf;
 }
 
 static void
@@ -610,19 +616,23 @@ alphadraw(Memdrawparam *par)
 {
 	int isgrey, starty, endy, op;
 	int needbuf, dsty, srcy, masky;
-	int y, dir, dx, dy;
+	int y, dir, dx, dy, ndrawbuf;
+	uchar *drawbuf;
 	Buffer bsrc, bdst, bmask;
 	Readfn *rdsrc, *rdmask, *rddst;
 	Calcfn *calc;
 	Writefn *wrdst;
 	Memimage *src, *mask, *dst;
 	Rectangle r, sr, mr;
+	Dbuf *z;
 
 	r = par->r;
 	dx = Dx(r);
 	dy = Dy(r);
 
-	ndrawbuf = 0;
+	z = allocdbuf();
+	if(z == nil)
+		return 0;
 
 	src = par->src;
 	mask = par->mask;	
@@ -641,12 +651,13 @@ alphadraw(Memdrawparam *par)
 	 */
 	needbuf = (src->data == dst->data);
 
-	spar = getparam(src, sr, isgrey, needbuf);
-	dpar = getparam(dst, r, isgrey, needbuf);
-	mpar = getparam(mask, mr, 0, needbuf);
+	ndrawbuf = 0;
+	getparam(&z->spar, src, sr, isgrey, needbuf, &ndrawbuf);
+	getparam(&z->dpar, dst, r, isgrey, needbuf, &ndrawbuf);
+	getparam(&z->mpar, mask, mr, 0, needbuf, &ndrawbuf);
 
 	dir = (needbuf && byteaddr(dst, r.min) > byteaddr(src, sr.min)) ? -1 : 1;
-	spar.dir = mpar.dir = dpar.dir = dir;
+	z->spar.dir = z->mpar.dir = z->dpar.dir = dir;
 
 	/*
 	 * If the mask is purely boolean, we can convert from src to dst format
@@ -666,7 +677,7 @@ alphadraw(Memdrawparam *par)
 //if(drawdebug) iprint("flag %lud mchan %lux=?%x dd %d\n", src->flags&Falpha, mask->chan, GREY1, dst->depth);
 	if(!(src->flags&Falpha) && mask->chan == GREY1 && dst->depth >= 8 && op == SoverD){
 //if(drawdebug) iprint("boolcopy...");
-		rdsrc = convfn(dst, &dpar, src, &spar);
+		rdsrc = convfn(dst, &z->dpar, src, &z->spar, &ndrawbuf);
 		rddst = readptr;
 		rdmask = readfn(mask);
 		calc = boolcopyfn(dst, mask);
@@ -684,10 +695,10 @@ alphadraw(Memdrawparam *par)
 		 */
 		if(mask->flags&Falpha){
 			rdmask = readalphafn(mask);
-			mpar.alphaonly = 1;
+			z->mpar.alphaonly = 1;
 		}else{
-			mpar.greymaskcall = readfn(mask);
-			mpar.convgrey = 1;
+			z->mpar.greymaskcall = readfn(mask);
+			z->mpar.convgrey = 1;
 			rdmask = greymaskread;
 
 			/*
@@ -709,27 +720,34 @@ alphadraw(Memdrawparam *par)
 	 * If the image has a small enough repl rectangle,
 	 * we can just read each line once and cache them.
 	 */
-	if(spar.replcache){
-		spar.replcall = rdsrc;
+	if(z->spar.replcache){
+		z->spar.replcall = rdsrc;
 		rdsrc = replread;
 	}
-	if(mpar.replcache){
-		mpar.replcall = rdmask;
+	if(z->mpar.replcache){
+		z->mpar.replcall = rdmask;
 		rdmask = replread;
 	}
 
-	if(allocdrawbuf() < 0)
-		return 0;
+	if(z->n < ndrawbuf){
+		free(z->p);
+		if((z->p = mallocz(ndrawbuf, 0)) == nil){
+			z->inuse = 0;
+			return 0;
+		}
+		z->n = ndrawbuf;
+	}
+	drawbuf = z->p;
 
 	/*
 	 * Before we were saving only offsets from drawbuf in the parameter
 	 * structures; now that drawbuf has been grown to accomodate us,
 	 * we can fill in the pointers.
 	 */
-	spar.bufbase = drawbuf+spar.bufoff;
-	mpar.bufbase = drawbuf+mpar.bufoff;
-	dpar.bufbase = drawbuf+dpar.bufoff;
-	spar.convbuf = drawbuf+spar.convbufoff;
+	z->spar.bufbase = drawbuf+z->spar.bufoff;
+	z->mpar.bufbase = drawbuf+z->mpar.bufoff;
+	z->dpar.bufbase = drawbuf+z->dpar.bufoff;
+	z->spar.convbuf = drawbuf+z->spar.convbufoff;
 
 	if(dir == 1){
 		starty = 0;
@@ -757,18 +775,19 @@ alphadraw(Memdrawparam *par)
 		clipy(dst, &dsty);
 		clipy(mask, &masky);
 
-		bsrc = rdsrc(&spar, spar.bufbase, srcy);
+		bsrc = rdsrc(&z->spar, z->spar.bufbase, srcy);
 DBG print("[");
-		bmask = rdmask(&mpar, mpar.bufbase, masky);
+		bmask = rdmask(&z->mpar, z->mpar.bufbase, masky);
 DBG print("]\n");
-		bdst = rddst(&dpar, dpar.bufbase, dsty);
+		bdst = rddst(&z->dpar, z->dpar.bufbase, dsty);
 DBG		dumpbuf("src", bsrc, dx);
 DBG		dumpbuf("mask", bmask, dx);
 DBG		dumpbuf("dst", bdst, dx);
 		bdst = calc(bdst, bsrc, bmask, dx, isgrey, op);
-		wrdst(&dpar, dpar.bytermin+dsty*dpar.bwidth, bdst);
+		wrdst(&z->dpar, z->dpar.bytermin+dsty*z->dpar.bwidth, bdst);
 	}
 
+	z->inuse = 0;
 	return 1;
 }
 #undef DBG
@@ -1825,7 +1844,7 @@ genconv(Param *p, uchar *buf, int y)
 }
 
 static Readfn*
-convfn(Memimage *dst, Param *dpar, Memimage *src, Param *spar)
+convfn(Memimage *dst, Param *dpar, Memimage *src, Param *spar, int *ndrawbuf)
 {
 	if(dst->chan == src->chan && !(src->flags&Frepl)){
 //if(drawdebug) iprint("readptr...");
@@ -1843,8 +1862,8 @@ convfn(Memimage *dst, Param *dpar, Memimage *src, Param *spar)
 	spar->convdpar = dpar;
 
 	/* allocate a conversion buffer */
-	spar->convbufoff = ndrawbuf;
-	ndrawbuf += spar->dx*4;
+	spar->convbufoff = *ndrawbuf;
+	*ndrawbuf += spar->dx*4;
 
 	if(spar->dx > Dx(spar->img->r)){
 		spar->convdx = spar->dx;