shithub: rd

Download patch

ref: 1025d6ab452ace62b65cf4a07f8bb2d8a46bc9fb
parent: f85425aad78787d12eb6f0941686b9fb5e114e62
author: Yaroslav Kolomiiets <[email protected]>
date: Tue Aug 9 11:31:41 EDT 2016

drawing cuts

--- a/dat.h
+++ b/dat.h
@@ -212,8 +212,7 @@
 	int	source;
 	int	shareid;
 	int	ncap;
-	int	nord;
-	int	nrect;
+	int	nr;
 	int	x;
 	int	y;
 	int	err;
@@ -261,7 +260,6 @@
 int	getimgupd(Imgupd*, uchar*, uint);
 int	getfupd(Imgupd*, uchar*, uint);
 
-void	loadmemimg(Rdp*, Imgupd*);
 void	drawmemimg(Rdp*, Imgupd*);
 
 
--- a/draw.c
+++ b/draw.c
@@ -1,7 +1,3 @@
-/*
- * depending on CanMemBlt servers will only do
- * either loadmeming+drawmemimg or drawimgupdate.
- */
 #include <u.h>
 #include <libc.h>
 #include <draw.h>
@@ -12,6 +8,7 @@
 static Image*	icache[3][600];
 
 static	void	drawupd(Rdp*,Imgupd*);
+static	void	padresize(Rdp*);
 
 /* 2.2.9.1.1.3.1.2.1 Bitmap Update Data (TS_UPDATE_BITMAP_DATA) */
 void
@@ -19,24 +16,16 @@
 {
 	uchar* p, *ep;
 	int n, nr;
-	Rectangle rs;
 	Imgupd u;
 
 	assert(s->type == ShUimg);
 	p = s->data;
 	ep = s->data + s->ndata;
-	nr = s->nrect;
+	nr = s->nr;
 
 	if(display->locking)
 		lockdisplay(display);
 
-	rs = rectaddpt(Rpt(ZP, Pt(c->xsz+4, c->ysz+4)), screen->r.min);
-	if(pad==nil || eqrect(pad->r, rs) == 0){
-		freeimage(pad);
-		pad = allocimage(display, rs, c->chan, 0, DNofill);
-		if(pad==nil)
-			sysfatal("drawimgupdate: %r");
-	}
 	while(p<ep && nr>0){
 		if((n = getimgupd(&u, p, ep-p)) < 0)
 			sysfatal("getimgupd: %r");
@@ -57,10 +46,12 @@
 	uchar *p, *ep;
 	Imgupd u;
 
-	count = as->nord;
+	count = as->nr;
 	p = as->data;
 	ep = as->data + as->ndata;
 
+	if(display->locking)
+		lockdisplay(display);
 	while(count> 0 && p<ep){
 		n = getfupd(&u, p, ep-p);
 		drawupd(c, &u);
@@ -67,51 +58,46 @@
 		p += n;
 		count--;
 	}
-	if(display->locking)
-		lockdisplay(display);
 	flushimage(display, 1);
 	if(display->locking)
 		unlockdisplay(display);
 }
 
-void
-scroll(Display* d, Rectangle r, Rectangle sr)
+static void
+padresize(Rdp* c)
 {
-	if(d && d->locking)
-		lockdisplay(d);
-	if(d)
-		draw(d->screenimage, r, d->screenimage, nil, sr.min);
-	if(d && d->locking)
-		unlockdisplay(d);
+	Rectangle rs;
+
+	rs = rectaddpt(Rpt(ZP, Pt(c->xsz+4, c->ysz+4)), screen->r.min);
+	if(pad==nil || eqrect(pad->r, rs) == 0){
+		freeimage(pad);
+		pad = allocimage(display, rs, c->chan, 0, DNofill);
+		if(pad==nil)
+			sysfatal("drawimgupdate: %r");
+	}
 }
 
-void
-loadmemimg(Rdp* c, Imgupd* iu)
+static void
+imgupd(Rdp* c, Imgupd* up)
 {
-	int (*loadfn)(Image*,Rectangle,uchar*,int,uchar*);
-	Image* img;
 	Rectangle r;
+	int (*loadfn)(Image*,Rectangle,uchar*,int,uchar*);
 
+	padresize(c);	// BUG call elsewhere - whenever c->xsz changes
+
+	if(up->depth != pad->depth)
+		sysfatal("bad image depth");
+
 	loadfn = loadbmp;
-	if(iu->iscompr)
+	if(up->iscompr)
 		loadfn = loadrle;
 
-	r = Rect(0, 0, iu->xsz, iu->ysz);
+	r = rectaddpt(Rect(up->x, up->y, up->x+up->xsz, up->y+up->ysz), screen->r.min);
+	if(loadfn(pad, r, up->bytes, up->nbytes, c->cmap) < 0)
+		sysfatal("drawimgupdate: %r");
 
-	if(iu->cid >= nelem(icache) || iu->coff >= nelem(*icache))
-		sysfatal("cacheimage2: bad cache spec [%d %d]", iu->cid, iu->coff);
-
-	img = icache[iu->cid][iu->coff];
-	if(img==nil || eqrect(img->r, r)==0){
-		freeimage(img);
-		img = allocimage(display, r, c->chan, 0, DNofill);
-		if(img == nil)
-			sysfatal("cacheimage2: %r");
-		icache[iu->cid][iu->coff] = img;
-	}
-
-	if(loadfn(img, r, iu->bytes, iu->nbytes, c->cmap) < 0)
-		sysfatal("loadmemimg: %r");
+	r = rectaddpt(Rect(up->x, up->y, up->xm+1, up->ym+1), screen->r.min);
+	draw(screen, r, pad, nil, r.min);
 }
 
 void
@@ -141,57 +127,54 @@
 
 
 static void
-imgupd(Rdp* c, Imgupd* up)
+scrblt(Rdp*, Imgupd* up)
 {
 	Rectangle r;
-	int (*loadfn)(Image*,Rectangle,uchar*,int,uchar*);
+	Point p;
 
-	if(up->depth != pad->depth)
-		sysfatal("bad image depth");
-
-	loadfn = loadbmp;
-	if(up->iscompr)
-		loadfn = loadrle;
-
 	r = rectaddpt(Rect(up->x, up->y, up->x+up->xsz, up->y+up->ysz), screen->r.min);
-	if(loadfn(pad, r, up->bytes, up->nbytes, c->cmap) < 0)
-		sysfatal("drawimgupdate: %r");
-
-	r = rectaddpt(Rect(up->x, up->y, up->xm+1, up->ym+1), screen->r.min);
-	draw(screen, r, pad, nil, r.min);
+	p = addpt(Pt(up->sx, up->sy), screen->r.min);
+	draw(screen, r, screen, nil, p);
 }
 
 static void
-scrblt(Rdp*, Imgupd* up)
-{
-	Rectangle r, sr;
-
-	r = rectaddpt(Rect(up->x, up->y, up->x+up->xsz, up->y+up->ysz), screen->r.min);
-	sr = rectaddpt(Rpt(Pt(up->sx, up->sy), Pt(Dx(r), Dy(r))), screen->r.min);
-	scroll(display, r, sr);
-}
-
-static void
 memblt(Rdp* c, Imgupd* up)
 {
-	if(display->locking)
-		lockdisplay(display);
 	if(up->clipped)
 		replclipr(screen, screen->repl, rectaddpt(up->clipr, screen->r.min));
 	drawmemimg(c, up);
 	if(up->clipped)
 		replclipr(screen, screen->repl, screen->r);
-	if(display->locking)
-		unlockdisplay(display);
 }
 
-
 static void
 cacheimage2(Rdp* c, Imgupd* up)
 {
-	loadmemimg(c, up);
-}
+	int (*loadfn)(Image*,Rectangle,uchar*,int,uchar*);
+	Image* img;
+	Rectangle r;
 
+	loadfn = loadbmp;
+	if(up->iscompr)
+		loadfn = loadrle;
+
+	r = Rect(0, 0, up->xsz, up->ysz);
+
+	if(up->cid >= nelem(icache) || up->coff >= nelem(*icache))
+		sysfatal("cacheimage2: bad cache spec [%d %d]", up->cid, up->coff);
+
+	img = icache[up->cid][up->coff];
+	if(img==nil || eqrect(img->r, r)==0){
+		freeimage(img);
+		img = allocimage(display, r, c->chan, 0, DNofill);
+		if(img == nil)
+			sysfatal("cacheimage2: %r");
+		icache[up->cid][up->coff] = img;
+	}
+
+	if(loadfn(img, r, up->bytes, up->nbytes, c->cmap) < 0)
+		sysfatal("loadmemimg: %r");
+}
 
 static void
 cachecmap(Rdp*, Imgupd*)
--- a/fns.h
+++ b/fns.h
@@ -53,5 +53,3 @@
 void		pbshort(uchar*,int);
 
 uchar*	putsdh(uchar*,uchar*,int,int,int,int);
-
-void		scroll(Display*, Rectangle, Rectangle);
--- a/mpas.c
+++ b/mpas.c
@@ -106,7 +106,7 @@
 			return -1;
 		}
 		as->type = ShUorders;
-		as->nord = GSHORT(p);
+		as->nr = GSHORT(p);
 		as->data = p+2;
 		as->ndata = ep-(p+2);
 		break;
@@ -116,7 +116,7 @@
 			return -1;
 		}
 		as->type = ShUimg;
-		as->nrect = GSHORT(p+2);
+		as->nr = GSHORT(p+2);
 		as->data = p+4;
 		as->ndata = ep-(p+4);
 		break;
@@ -259,7 +259,7 @@
 					return -1;
 				}
 				as->type = ShUorders;
-				as->nord = GSHORT(p+4);
+				as->nr = GSHORT(p+4);
 				as->data = p+8;
 				as->ndata = ep-(p+8);
 				break;
@@ -269,7 +269,7 @@
 					return -1;
 				}
 				as->type = ShUimg;
-				as->nrect = GSHORT(p+2);
+				as->nr = GSHORT(p+2);
 				as->data = p+4;
 				as->ndata = ep-(p+4);
 				break;