Module Name:    src
Committed By:   reinoud
Date:           Fri Dec 30 13:08:30 UTC 2011

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

Log Message:
Implement VNC's copyrect sending and let the copyrows use the new
vncfb_copyrecs()


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/usermode/dev/vncfb.c
cvs rdiff -u -r1.64 -r1.65 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.5 src/sys/arch/usermode/dev/vncfb.c:1.6
--- src/sys/arch/usermode/dev/vncfb.c:1.5	Fri Dec 30 12:54:41 2011
+++ src/sys/arch/usermode/dev/vncfb.c	Fri Dec 30 13:08:30 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: vncfb.c,v 1.5 2011/12/30 12:54:41 jmcneill Exp $ */
+/* $NetBSD: vncfb.c,v 1.6 2011/12/30 13:08:30 reinoud 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.5 2011/12/30 12:54:41 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vncfb.c,v 1.6 2011/12/30 13:08:30 reinoud Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -103,6 +103,7 @@ 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 int	vncfb_intr(void *);
 static void	vncfb_softintr(void *);
 
@@ -349,21 +350,21 @@ vncfb_copyrows(void *priv, int srcrow, i
 	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, srcx, srcy;
+	int fontheight;
 
 	ops->copyrows(ri, srcrow, dstrow, nrows);
 
+	fontheight = ri->ri_font->fontheight;
 	x = ri->ri_xorigin;
+	y = ri->ri_yorigin + dstrow * fontheight;
 	w = ri->ri_width;
-	if (srcrow < dstrow) {
-		y = ri->ri_yorigin + (srcrow * ri->ri_font->fontheight);
-		h = (nrows + (dstrow - srcrow)) * ri->ri_font->fontheight;
-	} else {
-		y = ri->ri_yorigin + (dstrow * ri->ri_font->fontheight);
-		h = (nrows + (srcrow - dstrow)) * ri->ri_font->fontheight;
-	}
+	h = nrows * fontheight;
 
-	vncfb_update(sc, x, y, w, h);
+	srcx = ri->ri_xorigin;
+	srcy = ri->ri_yorigin + srcrow * fontheight;
+
+	vncfb_copyrect(sc, x, y, w, h, srcx, srcy);
 }
 
 static void
@@ -456,6 +457,14 @@ vncfb_update(struct vncfb_softc *sc, int
 	softint_schedule(sc->sc_sih);
 }
 
+static void
+vncfb_copyrect(struct vncfb_softc *sc, int x, int y, int w, int h,
+	int srcx, int srcy)
+{
+	thunk_rfb_copyrect(&sc->sc_rfb, x, y, w, h, srcx, srcy);
+	softint_schedule(sc->sc_sih);
+}
+
 static int
 vncfb_intr(void *priv)
 {

Index: src/sys/arch/usermode/usermode/thunk.c
diff -u src/sys/arch/usermode/usermode/thunk.c:1.64 src/sys/arch/usermode/usermode/thunk.c:1.65
--- src/sys/arch/usermode/usermode/thunk.c:1.64	Fri Dec 30 12:54:42 2011
+++ src/sys/arch/usermode/usermode/thunk.c	Fri Dec 30 13:08:30 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.64 2011/12/30 12:54:42 jmcneill Exp $ */
+/* $NetBSD: thunk.c,v 1.65 2011/12/30 13:08:30 reinoud 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.64 2011/12/30 12:54:42 jmcneill Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.65 2011/12/30 13:08:30 reinoud Exp $");
 #endif
 
 #include <sys/types.h>
@@ -76,6 +76,8 @@ __RCSID("$NetBSD: thunk.c,v 1.64 2011/12
 #define MAP_ANON MAP_ANONYMOUS
 #endif
 
+//#define RFB_DEBUG
+
 extern int boothowto;
 
 void
@@ -989,7 +991,7 @@ static void
 thunk_rfb_send_pending(thunk_rfb_t *rfb)
 {
 	thunk_rfb_update_t *update;
-	uint8_t rfb_update[16];
+	uint8_t buf[32];
 	uint8_t *p;
 	unsigned int n;
 	unsigned int bytes_per_pixel;
@@ -1011,28 +1013,28 @@ thunk_rfb_send_pending(thunk_rfb_t *rfb)
 	fprintf(stdout, "rfb: sending %d updates\n", rfb->nupdates);
 #endif
 
-	p = rfb_update;
+	p = buf;
 	*(uint8_t *)p = 0;		p += 1;		/* FramebufferUpdate */
 	*(uint8_t *)p = 0;		p += 1;		/* padding */
 	*(uint16_t *)p = htons(rfb->nupdates);	p += 2;	/* # rects */
 
-	len = safe_send(rfb->clientfd, rfb_update, 4);
+	len = safe_send(rfb->clientfd, buf, 4);
 	if (len < 0)
 		goto disco;
 
 	bytes_per_pixel = rfb->depth / 8;
 	stride = rfb->width * bytes_per_pixel;
 	for (n = 0; n < rfb->nupdates; n++) {
-		p = rfb_update;
+		p = buf;
 		update = &rfb->update[n];
 		*(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;
-		*(uint32_t *)p = htonl(update->enc);	p += 4;	/* Raw enc */
+		*(uint32_t *)p = htonl(update->enc);	p += 4;	/* encoding */
 
 #ifdef RFB_DEBUG
-		fprintf(stdout, "rfb: [%u] enc %d, [%d, %d] - [%d, %d)",
+		fprintf(stdout, "rfb: [%u] enc %d, [%d, %d] - [%d, %d]",
 		    n, update->enc, update->x, update->y, update->w, update->h);
 		if (update->enc == THUNK_RFB_TYPE_COPYRECT)
 			fprintf(stdout, " from [%d, %d]",
@@ -1040,17 +1042,29 @@ thunk_rfb_send_pending(thunk_rfb_t *rfb)
 		fprintf(stdout, "\n");
 #endif
 
-		len = safe_send(rfb->clientfd, rfb_update, 12);
+		len = safe_send(rfb->clientfd, buf, 12);
 		if (len < 0)
 			goto disco;
 
-		p = rfb->framebuf + (update->y * stride) + (update->x * bytes_per_pixel);
-		line_len = update->w * bytes_per_pixel;
-		while (update->h-- > 0) {
-			len = safe_send(rfb->clientfd, p, line_len);
+		if (update->enc == THUNK_RFB_TYPE_COPYRECT) {
+			p = buf;
+			*(uint16_t *)p = htons(update->srcx);	p += 2;
+			*(uint16_t *)p = htons(update->srcy);	p += 2;
+			len = safe_send(rfb->clientfd, buf, 4);
 			if (len < 0)
 				goto disco;
-			p += stride;
+		}
+
+		if (update->enc == THUNK_RFB_TYPE_RAW) {
+			p = rfb->framebuf + (update->y * stride)
+				+ (update->x * bytes_per_pixel);
+			line_len = update->w * bytes_per_pixel;
+			while (update->h-- > 0) {
+				len = safe_send(rfb->clientfd, p, line_len);
+				if (len < 0)
+					goto disco;
+				p += stride;
+			}
 		}
 	}
 

Reply via email to