Module Name:    src
Committed By:   jmcneill
Date:           Fri Dec 30 14:20:34 UTC 2011

Modified Files:
        src/sys/arch/usermode/dev: vncfb.c
        src/sys/arch/usermode/include: thunk.h
        src/sys/arch/usermode/usermode: thunk.c

Log Message:
add a barrier before copyrows(), and add an RRE based fillrect functino,
use it for eraserows and erasecols


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/usermode/dev/vncfb.c
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/usermode/include/thunk.h
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/usermode/usermode/thunk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/usermode/dev/vncfb.c
diff -u src/sys/arch/usermode/dev/vncfb.c:1.6 src/sys/arch/usermode/dev/vncfb.c:1.7
--- src/sys/arch/usermode/dev/vncfb.c:1.6	Fri Dec 30 13:08:30 2011
+++ src/sys/arch/usermode/dev/vncfb.c	Fri Dec 30 14:20:33 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: vncfb.c,v 1.6 2011/12/30 13:08:30 reinoud Exp $ */
+/* $NetBSD: vncfb.c,v 1.7 2011/12/30 14:20:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcne...@invisible.ca>
@@ -35,7 +35,7 @@
 #include "opt_wsemul.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vncfb.c,v 1.6 2011/12/30 13:08:30 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vncfb.c,v 1.7 2011/12/30 14:20:33 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -103,7 +103,8 @@ static paddr_t	vncfb_mmap(void *, void *
 static void	vncfb_init_screen(void *, struct vcons_screen *, int, long *);
 
 static void	vncfb_update(struct vncfb_softc *, int, int, int, int);
-static void	vncfb_copyrect(struct vncfb_softc *sc, int, int, int, int, int, int);
+static void	vncfb_copyrect(struct vncfb_softc *, int, int, int, int, int, int);
+static void	vncfb_fillrect(struct vncfb_softc *, int, int, int, int, uint32_t);
 static int	vncfb_intr(void *);
 static void	vncfb_softintr(void *);
 
@@ -331,7 +332,7 @@ vncfb_erasecols(void *priv, int row, int
 	struct vcons_screen *scr = ri->ri_hw;
 	struct vncfb_softc *sc = scr->scr_cookie;
 	struct vncfb_fbops *ops = &sc->sc_ops;
-	int x, y, w, h;
+	int x, y, w, h, c;
 
 	ops->erasecols(ri, row, startcol, ncols, fillattr);
 
@@ -339,8 +340,9 @@ vncfb_erasecols(void *priv, int row, int
 	h = ri->ri_font->fontheight;
 	x = ri->ri_xorigin + (startcol * ri->ri_font->fontwidth);
 	w = ncols * ri->ri_font->fontwidth;
+	c = ri->ri_devcmap[(fillattr >> 16) & 0xf] & 0xffffff;
 
-	vncfb_update(sc, x, y, w, h);
+	vncfb_fillrect(sc, x, y, w, h, c);
 }
 
 static void
@@ -353,6 +355,10 @@ vncfb_copyrows(void *priv, int srcrow, i
 	int x, y, w, h, srcx, srcy;
 	int fontheight;
 
+	/* barrier */
+	while (sc->sc_rfb.nupdates > 0)
+		thunk_rfb_poll(&sc->sc_rfb, NULL);
+
 	ops->copyrows(ri, srcrow, dstrow, nrows);
 
 	fontheight = ri->ri_font->fontheight;
@@ -374,7 +380,7 @@ vncfb_eraserows(void *priv, int row, int
 	struct vcons_screen *scr = ri->ri_hw;
 	struct vncfb_softc *sc = scr->scr_cookie;
 	struct vncfb_fbops *ops = &sc->sc_ops;
-	int x, y, w, h;
+	int x, y, w, h, c;
 
 	ops->eraserows(ri, row, nrows, fillattr);
 
@@ -382,8 +388,9 @@ vncfb_eraserows(void *priv, int row, int
 	h = nrows * ri->ri_font->fontheight;
 	x = ri->ri_xorigin;
 	w = ri->ri_width;
+	c = ri->ri_devcmap[(fillattr >> 16) & 0xf] & 0xffffff;
 
-	vncfb_update(sc, x, y, w, h);
+	vncfb_fillrect(sc, x, y, w, h, c);
 }
 
 static void
@@ -465,6 +472,14 @@ vncfb_copyrect(struct vncfb_softc *sc, i
 	softint_schedule(sc->sc_sih);
 }
 
+static void
+vncfb_fillrect(struct vncfb_softc *sc, int x, int y, int w, int h, uint32_t c)
+{
+
+	thunk_rfb_fillrect(&sc->sc_rfb, x, y, w, h, (uint8_t *)&c);
+	softint_schedule(sc->sc_sih);
+}
+
 static int
 vncfb_intr(void *priv)
 {

Index: src/sys/arch/usermode/include/thunk.h
diff -u src/sys/arch/usermode/include/thunk.h:1.51 src/sys/arch/usermode/include/thunk.h:1.52
--- src/sys/arch/usermode/include/thunk.h:1.51	Fri Dec 30 12:54:41 2011
+++ src/sys/arch/usermode/include/thunk.h	Fri Dec 30 14:20:34 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.h,v 1.51 2011/12/30 12:54:41 jmcneill Exp $ */
+/* $NetBSD: thunk.h,v 1.52 2011/12/30 14:20:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcne...@invisible.ca>
@@ -195,7 +195,7 @@ typedef struct {
 	uint8_t			enc;
 	uint16_t		x, y, w, h;
 	uint16_t		srcx, srcy;
-	uint32_t		colour;		/* for RRE clear */
+	uint8_t			pixel[4];
 } thunk_rfb_update_t;
 #define THUNK_RFB_TYPE_RAW	0
 #define THUNK_RFB_TYPE_COPYRECT	1
@@ -227,5 +227,6 @@ int	thunk_rfb_poll(thunk_rfb_t *, thunk_
 void	thunk_rfb_bell(thunk_rfb_t *);
 void	thunk_rfb_update(thunk_rfb_t *, int, int, int, int);
 void	thunk_rfb_copyrect(thunk_rfb_t *, int, int, int, int, int, int);
+void	thunk_rfb_fillrect(thunk_rfb_t *, int, int, int, int, uint8_t *);
 
 #endif /* !_ARCH_USERMODE_INCLUDE_THUNK_H */

Index: src/sys/arch/usermode/usermode/thunk.c
diff -u src/sys/arch/usermode/usermode/thunk.c:1.65 src/sys/arch/usermode/usermode/thunk.c:1.66
--- src/sys/arch/usermode/usermode/thunk.c:1.65	Fri Dec 30 13:08:30 2011
+++ src/sys/arch/usermode/usermode/thunk.c	Fri Dec 30 14:20:34 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.65 2011/12/30 13:08:30 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.66 2011/12/30 14:20:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcne...@invisible.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.65 2011/12/30 13:08:30 reinoud Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.66 2011/12/30 14:20:34 jmcneill Exp $");
 #endif
 
 #include <sys/types.h>
@@ -1003,6 +1003,7 @@ thunk_rfb_send_pending(thunk_rfb_t *rfb)
 	/* If we have too many updates queued, just send a single update */
 	if (rfb->nupdates >= __arraycount(rfb->update)) {
 		rfb->nupdates = 1;
+		rfb->update[0].enc = THUNK_RFB_TYPE_RAW;
 		rfb->update[0].x = 0;
 		rfb->update[0].y = 0;
 		rfb->update[0].w = rfb->width;
@@ -1039,6 +1040,10 @@ thunk_rfb_send_pending(thunk_rfb_t *rfb)
 		if (update->enc == THUNK_RFB_TYPE_COPYRECT)
 			fprintf(stdout, " from [%d, %d]",
 			    update->srcx, update->srcy);
+		if (update->enc == THUNK_RFB_TYPE_RRE)
+			fprintf(stdout, " pixel [%02x %02x %02x %02x]",
+			    update->pixel[0], update->pixel[1],
+			    update->pixel[2], update->pixel[3]);
 		fprintf(stdout, "\n");
 #endif
 
@@ -1055,6 +1060,24 @@ thunk_rfb_send_pending(thunk_rfb_t *rfb)
 				goto disco;
 		}
 
+		if (update->enc == THUNK_RFB_TYPE_RRE) {
+			p = buf;
+
+			/* header */
+			*(uint32_t *)p = htonl(1);		p += 4;
+			memcpy(p, update->pixel, 4);		p += 4;
+			/* subrectangle */
+			memcpy(p, update->pixel, 4);		p += 4;
+			*(uint16_t *)p = htons(update->x);	p += 2;
+			*(uint16_t *)p = htons(update->y);	p += 2;
+			*(uint16_t *)p = htons(update->w);	p += 2;
+			*(uint16_t *)p = htons(update->h);	p += 2;
+			/* send it */
+			len = safe_send(rfb->clientfd, buf, 20);
+			if (len < 0)
+				goto disco;
+		}
+
 		if (update->enc == THUNK_RFB_TYPE_RAW) {
 			p = rfb->framebuf + (update->y * stride)
 				+ (update->x * bytes_per_pixel);
@@ -1146,6 +1169,9 @@ thunk_rfb_poll(thunk_rfb_t *rfb, thunk_r
 	if (rfb->clientfd == -1)
 		return -1;
 
+	if (event == NULL)
+		return 0;
+
 	if (rfb->schedule_bell) {
 		uint8_t msg_type = 2;	/* bell */
 		safe_send(rfb->clientfd, &msg_type, sizeof(msg_type));
@@ -1277,5 +1303,31 @@ thunk_rfb_copyrect(thunk_rfb_t *rfb, int
 	update->srcx = srcx;
 	update->srcy = srcy;
 
-	rfb->first_mergable = rfb->nupdates+1;
+	rfb->first_mergable = rfb->nupdates;
+}
+
+void
+thunk_rfb_fillrect(thunk_rfb_t *rfb, int x, int y, int w, int h, uint8_t *pixel)
+{
+	thunk_rfb_update_t *update = NULL;
+
+	/* if the queue is full, just return */
+	if (rfb->nupdates >= __arraycount(rfb->update))
+		return;
+
+#ifdef RFB_DEBUG
+	fprintf(stdout, "rfb: fillrect queue slot %d, x=%d y=%d w=%d h=%d\n",
+	    rfb->nupdates, x, y, w, h);
+#endif
+
+	/* add the update request to the queue */
+	update = &rfb->update[rfb->nupdates++];
+	update->enc = THUNK_RFB_TYPE_RRE;
+	update->x = x;
+	update->y = y;
+	update->w = w;
+	update->h = h;
+	memcpy(update->pixel, pixel, 4);
+
+	rfb->first_mergable = rfb->nupdates;
 }

Reply via email to