PERFORCE change 154133 for review

Ed Schouten ed at FreeBSD.org
Fri Dec 5 11:10:12 PST 2008


http://perforce.freebsd.org/chv.cgi?CH=154133

Change 154133 by ed at ed_mekker on 2008/12/05 19:09:55

	Properly implement fill() and copy().
	
	People can now test this code without completely messing up
	their system... ;-)

Affected files ...

.. //depot/projects/mpsafetty/sys/dev/syscons/scterm-teken.c#9 edit

Differences ...

==== //depot/projects/mpsafetty/sys/dev/syscons/scterm-teken.c#9 (text+ko) ====

@@ -287,6 +287,7 @@
 {
 	scr_stat *scp = arg;
 	u_char *map;
+	u_char ch = c;
 	int attr, row;
 
 	attr = scteken_attr(a);
@@ -294,39 +295,81 @@
 
 	if (r->tr_begin.tp_col == 0 && r->tr_end.tp_col == scp->xsize) {
 		/* Single contiguous region to fill. */
-		vtb_erase(&scp->vtb, r->tr_begin.tp_row * scp->xsize,
+		sc_vtb_erase(&scp->vtb, r->tr_begin.tp_row * scp->xsize,
 		    (r->tr_end.tp_row - r->tr_begin.tp_row) * scp->xsize,
 		    map[ch], attr);
 	} else {
 		/* Fill display line by line. */
 		for (row = r->tr_begin.tp_row; row < r->tr_end.tp_row; row++) {
-			vtb_erase(&scp->vtb,
-			    r->tr_begin.tp_row * scp->xsize + r->tr_begin.tp_col,
-			    r->tr_end.tp_col - r->tr_begin.tp_col, map[ch], attr);
+			sc_vtb_erase(&scp->vtb, r->tr_begin.tp_row *
+			    scp->xsize + r->tr_begin.tp_col,
+			    r->tr_end.tp_col - r->tr_begin.tp_col,
+			    map[ch], attr);
 		}
 	}
 
-	/* XXX: bad! */
-	mark_for_update(scp, r->tr_begin.tp_row * scp->xsize + r->tr_begin.tp_col);
-	mark_for_update(scp, (r->tr_end.tp_row - 1) * scp->xsize + (r->tr_end.tp_col - 1));
+	/* Mark begin and end positions to be refreshed. */
+	mark_for_update(scp,
+	    r->tr_begin.tp_row * scp->xsize + r->tr_begin.tp_col);
+	mark_for_update(scp,
+	    (r->tr_end.tp_row - 1) * scp->xsize + (r->tr_end.tp_col - 1));
 }
 
 static void
 scteken_copy(void *arg, const teken_rect_t *r, const teken_pos_t *p)
 {
 	scr_stat *scp = arg;
-	int from, to, count;
+	unsigned int stride;
+	int src, dst, end;
+
+	if (r->tr_begin.tp_col == 0 && r->tr_end.tp_col == scp->xsize) {
+		/* Single contiguous region to copy. */
+		sc_vtb_move(&scp->vtb, r->tr_begin.tp_row * scp->xsize,
+		    p->tp_row * scp->xsize,
+		    (r->tr_end.tp_row - r->tr_begin.tp_row) * scp->xsize);
+	} else {
+		/* Copy line by line. */
+		stride = r->tr_end.tp_col - r->tr_begin.tp_col;
+
+		if (p->tp_row < r->tr_begin.tp_row) {
+			/* Copy from top to bottom. */
+			src = r->tr_begin.tp_row * scp->xsize +
+			    r->tr_begin.tp_col;
+			end = r->tr_end.tp_row * scp->xsize +
+			    r->tr_end.tp_col;
+			dst = p->tp_row * scp->xsize + p->tp_col;
 
-	/* XXX: only copy whole lines for now! */
-	from = r->tr_begin.tp_row * scp->xsize;
-	to = p->tp_row * scp->xsize;
-	count = (r->tr_end.tp_row - r->tr_begin.tp_row + 1) * scp->xsize - 1;
+			while (src < end) {
+				sc_vtb_move(&scp->vtb, src, dst, stride);
+			
+				src += stride;
+				dst += stride;
+			}
+		} else {
+			/* Copy from bottom to top. */
+			src = (r->tr_end.tp_row - 1) * scp->xsize +
+			    r->tr_begin.tp_col;
+			end = r->tr_begin.tp_row * scp->xsize +
+			    r->tr_begin.tp_col;
+			dst = (p->tp_row + r->tr_end.tp_row -
+			    r->tr_begin.tp_row - 1) * scp->xsize + p->tp_col;
 
-	if (count <= 0 || from == to)
-		return;
+			while (src >= end) {
+				sc_vtb_move(&scp->vtb, src, dst, stride);
+			
+				src -= stride;
+				dst -= stride;
+			}
+		}
+	}
 
-	sc_vtb_move(&scp->vtb, from, to, count);
-	mark_all(scp);
+	/* Mark begin and end positions to be refreshed. */
+	mark_for_update(scp,
+	    p->tp_row * scp->xsize + p->tp_col);
+	mark_for_update(scp,
+	    (p->tp_row + r->tr_end.tp_row - r->tr_begin.tp_row - 1) *
+	    scp->xsize +
+	    (p->tp_col + r->tr_end.tp_col - r->tr_begin.tp_col - 1));
 }
 
 static void


More information about the p4-projects mailing list