Parcourir la source

Track VGA damage as a rect list instead of rows plus one x-span

The old model kept a dirty-row bitmap plus a single horizontal span over
all of it, so any pending damage widened the columns copied for every
dirty row: a keystroke in a window while the cursor sat on the desktop
copied ~1.25 MB instead of ~0.65 MB, and the cursor's own 16 rows got the
window's span too.

vga.c now keeps up to 16 damage rects:
- damage_add() clips, returns early when the new damage is contained
  (scanning backwards, so the per-pixel marks of one glyph or cursor draw
  cost one comparison each), otherwise merges with every rect it overlaps,
  touches or would barely waste space (merged area <= 2x the two areas),
  rescanning after each merge.  A full list extends whichever rect grows
  the least -- correct, just a few redundant pixels.
- shadow_copy_damage() copies each rect row by row (dword aligned, with a
  byte tail for 16/24 bpp widths that do not divide into dwords) and drops
  the rects it finishes.  A rect that fits the budget is copied whole even
  when that overshoots a little, so a window-sized repaint is never split;
  only a bigger rect (a full-screen redraw) is chunked, and its remaining
  rows move behind the newer damage so a cursor update never waits for a
  full repaint.

Supporting changes:
- wm_drag_shadow() marks only the moved window's new rect: the sliver
  repaints mark themselves exactly, so a small step still merges into the
  swept hull while a big jump no longer forces it.
- fbtext_draw_string_xy() marks the string's own span instead of
  full-width rows.
- vga_fb_mark_dirty_rect()/vga_fb_mark_dirty_rect_xy() cache the boot
  framebuffer info before touching vga_fb_w/vga_fb_h.
Johannes Zellner il y a 1 mois
Parent
commit
20150ee647
5 fichiers modifiés avec 193 ajouts et 115 suppressions
  1. 12 7
      AGENTS.md
  2. 1 1
      fbtext.c
  3. 169 92
      vga.c
  4. 6 5
      vga.h
  5. 5 10
      wm.c

+ 12 - 7
AGENTS.md

@@ -99,8 +99,13 @@ below the run area), so adding code no longer moves any address.
   `sys_gfx_reap`/`sys_gfx_collect` free the canvas after exit/crash.  `clock`
   `sys_gfx_reap`/`sys_gfx_collect` free the canvas after exit/crash.  `clock`
   and `colors` are its users.
   and `colors` are its users.
 - **Graphics**: `vga.c/h`, `vga_copy.S`, `gpu.c`, `ati.c`, `nvidia.c`, `nv50.c`,
 - **Graphics**: `vga.c/h`, `vga_copy.S`, `gpu.c`, `ati.c`, `nvidia.c`, `nv50.c`,
-  `pci.h` — VESA LFB + shadow buffer, damage-driven dirty-row flush (byte
-  budget per main-loop iteration, no fixed frame rate). ATI Mach64 CRTC
+  `pci.h` — VESA LFB + shadow buffer.  Drawing marks damage rectangles (a small
+  list that merges rects when they overlap or touch, so a keystroke's cells
+  collapse while unrelated damage stays apart); the main loop copies them to
+  VRAM on every iteration under a byte budget (`VGA_FLUSH_BUDGET_BYTES`), no
+  fixed frame rate.  A rect that fits the budget is copied whole, so a window
+  repaint never tears; only a bigger one (a full-screen redraw) is chunked, and
+  its remaining rows continue after the newer damage.  ATI Mach64 CRTC
   fixup; NVIDIA is VBE-only (never touch the legacy VGA CRTC). `nvidia.c`
   fixup; NVIDIA is VBE-only (never touch the legacy VGA CRTC). `nvidia.c`
   identifies the card, maps BAR0/BAR1/BAR3 and reads the MCP7x stolen-VRAM
   identifies the card, maps BAR0/BAR1/BAR3 and reads the MCP7x stolen-VRAM
   geometry; `nv50.c` probes the nv50-family display engine at boot (read-only,
   geometry; `nv50.c` probes the nv50-family display engine at boot (read-only,
@@ -632,11 +637,11 @@ Caveats:
   on the board while QEMU was fine.  Anything above `MM_MAX_PHYS` (128 MB) is
   on the board while QEMU was fine.  Anything above `MM_MAX_PHYS` (128 MB) is
   also *unmapped*, so a wild pointer there is an instant #PF.
   also *unmapped*, so a wild pointer there is an instant #PF.
 - **All drawing goes into the shadow buffer** (`vga_put_pixel_rgb` etc.); the
 - **All drawing goes into the shadow buffer** (`vga_put_pixel_rgb` etc.); the
-  main loop flushes dirty rows to VRAM on every iteration (byte budget, see
-  `VGA_FLUSH_BUDGET_BYTES`) so small updates (cursor, a keystroke) reach the
-  screen within a loop instead of waiting for a fixed tick. A window drag
-  flushes its swept band immediately (`wm_drag_shadow`) so each step is one
-  consistent frame. Full-screen programs call `vga_clear_rgb`.
+  main loop flushes the pending damage rects to VRAM on every iteration (byte
+  budget, see `VGA_FLUSH_BUDGET_BYTES`) so small updates (cursor, a keystroke)
+  reach the screen within a loop instead of waiting for a fixed tick. A window
+  drag flushes its rectangles immediately (`wm_drag_shadow`) so each step is
+  one consistent frame. Full-screen programs call `vga_clear_rgb`.
 - **FAT is read/write** — FAT12/16/32 read plus write/delete/mkdir/rmdir.
 - **FAT is read/write** — FAT12/16/32 read plus write/delete/mkdir/rmdir.
   FAT32 allocation uses an FSInfo-seeded free-cluster hint; the FSInfo
   FAT32 allocation uses an FSInfo-seeded free-cluster hint; the FSInfo
   free-count is not updated and a completely full FAT32 directory is not
   free-count is not updated and a completely full FAT32 directory is not

+ 1 - 1
fbtext.c

@@ -325,7 +325,7 @@ void fbtext_draw_string_xy(unsigned int x0, unsigned int y0, const char *str,
 		draw_glyph_at(x0 + i * 8, y0, (unsigned char)str[i], r_fg, g_fg, b_fg, 0, 0, 0, FONT_8X8_ROWS, transparent_bg);
 		draw_glyph_at(x0 + i * 8, y0, (unsigned char)str[i], r_fg, g_fg, b_fg, 0, 0, 0, FONT_8X8_ROWS, transparent_bg);
 		i++;
 		i++;
 	}
 	}
-	vga_fb_mark_dirty_rect(y0, FONT_8X8_ROWS);
+	vga_fb_mark_dirty_rect_xy(y0, FONT_8X8_ROWS, x0, x0 + i * 8);
 }
 }
 
 
 /* Like fbtext_draw_string_xy, but per-pixel clipped to (cx, cy, cw, ch): only
 /* Like fbtext_draw_string_xy, but per-pixel clipped to (cx, cy, cw, ch): only

+ 169 - 92
vga.c

@@ -1,4 +1,4 @@
-/* VGA: VESA LFB (from boot) with a shadow buffer and a damage-driven flush. */
+/* VGA: VESA LFB (from boot) with a shadow buffer and a damage-rect flush. */
 
 
 #include "vga.h"
 #include "vga.h"
 #include "pci.h"
 #include "pci.h"
@@ -16,69 +16,127 @@ static unsigned char *vga_shadow_buf;
 static unsigned int   vga_shadow_pitch;
 static unsigned int   vga_shadow_pitch;
 static unsigned int   vga_shadow_size;
 static unsigned int   vga_shadow_size;
 
 
-/* Dirty row bitmap: one bit per row. Max 2048 rows = 256 bytes. */
-#define MAX_DIRTY_ROWS 2048
-static unsigned char vga_shadow_dirty_rows[MAX_DIRTY_ROWS / 8];
-
-/* Horizontal span [x0, x1) of dirty pixels, so the flush copies only the
-   changed columns instead of whole rows. */
-static unsigned int vga_dirty_x0, vga_dirty_x1;
-
-static void mark_dirty_row(unsigned int y)
+/* Damage rect list.  Each entry is a half-open [x0,x1) x [y0,y1) region of
+ * the shadow buffer that has not been copied to VRAM yet.  Entries merge when
+ * they overlap, touch or would barely waste space, so related marks (the
+ * per-pixel writes of one glyph or cursor draw, the rectangles of one window
+ * repaint) collapse into a few rects, while unrelated damage (a window and the
+ * cursor on the other side of the screen) stays separate and the flush copies
+ * each row only over the columns that changed.  A rect that is only partially
+ * flushed keeps its remaining rows and moves behind the newer damage. */
+#define DAMAGE_SLOTS 16
+struct damage_rect {
+	unsigned int x0, y0, x1, y1;
+};
+static struct damage_rect damage_rects[DAMAGE_SLOTS];
+static unsigned int damage_count;
+
+static void damage_add(unsigned int x0, unsigned int y0,
+		       unsigned int x1, unsigned int y1)
 {
 {
-	if (y < MAX_DIRTY_ROWS)
-		vga_shadow_dirty_rows[y / 8] |= (1 << (y % 8));
-}
+	unsigned int i;
 
 
-static void expand_dirty_x(unsigned int x0, unsigned int x1)
-{
-	if (x0 > vga_fb_w)
-		x0 = vga_fb_w;
 	if (x1 > vga_fb_w)
 	if (x1 > vga_fb_w)
 		x1 = vga_fb_w;
 		x1 = vga_fb_w;
-	if (x0 < vga_dirty_x0)
-		vga_dirty_x0 = x0;
-	if (x1 > vga_dirty_x1)
-		vga_dirty_x1 = x1;
+	if (y1 > vga_fb_h)
+		y1 = vga_fb_h;
+	if (x0 >= x1 || y0 >= y1)
+		return;
+
+	/* Already covered?  Scanning backwards catches the repeated per-pixel
+	   marks of a glyph or cursor draw in one step. */
+	for (i = damage_count; i-- > 0; ) {
+		struct damage_rect *d = &damage_rects[i];
+
+		if (x0 >= d->x0 && y0 >= d->y0 && x1 <= d->x1 && y1 <= d->y1)
+			return;
+	}
+
+	/* Merge with every rect this one touches; a merge can bring another
+	   rect into reach, so restart the scan after each one. */
+	for (i = 0; i < damage_count; ) {
+		struct damage_rect *d = &damage_rects[i];
+		unsigned int nx0 = (x0 < d->x0) ? x0 : d->x0;
+		unsigned int ny0 = (y0 < d->y0) ? y0 : d->y0;
+		unsigned int nx1 = (x1 > d->x1) ? x1 : d->x1;
+		unsigned int ny1 = (y1 > d->y1) ? y1 : d->y1;
+		unsigned int merged_area = (nx1 - nx0) * (ny1 - ny0);
+		unsigned int area = (d->x1 - d->x0) * (d->y1 - d->y0) +
+				    (x1 - x0) * (y1 - y0);
+
+		if (nx0 <= d->x1 && d->x0 <= nx1 &&
+		    ny0 <= d->y1 && d->y0 <= ny1 &&
+		    merged_area <= 2 * area) {
+			x0 = nx0;
+			y0 = ny0;
+			x1 = nx1;
+			y1 = ny1;
+			damage_rects[i] = damage_rects[--damage_count];
+			i = 0;
+			continue;
+		}
+		i++;
+	}
+
+	if (damage_count < DAMAGE_SLOTS) {
+		damage_rects[damage_count].x0 = x0;
+		damage_rects[damage_count].y0 = y0;
+		damage_rects[damage_count].x1 = x1;
+		damage_rects[damage_count].y1 = y1;
+		damage_count++;
+		return;
+	}
+
+	/* List full: extend whichever rect grows the least (correct, just a
+	   few redundant pixels copied). */
+	{
+		unsigned int best = 0, best_grow = 0xFFFFFFFFu;
+
+		for (i = 0; i < DAMAGE_SLOTS; i++) {
+			struct damage_rect *d = &damage_rects[i];
+			unsigned int nx0 = (x0 < d->x0) ? x0 : d->x0;
+			unsigned int ny0 = (y0 < d->y0) ? y0 : d->y0;
+			unsigned int nx1 = (x1 > d->x1) ? x1 : d->x1;
+			unsigned int ny1 = (y1 > d->y1) ? y1 : d->y1;
+			unsigned int grow = (nx1 - nx0) * (ny1 - ny0) -
+					    (d->x1 - d->x0) * (d->y1 - d->y0);
+
+			if (grow < best_grow) {
+				best_grow = grow;
+				best = i;
+			}
+		}
+		{
+			struct damage_rect *d = &damage_rects[best];
+
+			if (x0 < d->x0) d->x0 = x0;
+			if (y0 < d->y0) d->y0 = y0;
+			if (x1 > d->x1) d->x1 = x1;
+			if (y1 > d->y1) d->y1 = y1;
+		}
+	}
 }
 }
 
 
-static void mark_dirty_rect_xy(unsigned int y, unsigned int h,
-			       unsigned int x0, unsigned int x1)
+static int damage_any(void)
 {
 {
-	unsigned int i;
-	for (i = 0; i < h; i++)
-		mark_dirty_row(y + i);
-	expand_dirty_x(x0, x1);
+	return damage_count != 0;
 }
 }
 
 
-/* Full-width dirty rows (used where the x-extent isn't tracked). */
-static void mark_dirty_rect(unsigned int y, unsigned int h)
+static void damage_clear(void)
 {
 {
-	mark_dirty_rect_xy(y, h, 0, vga_fb_w);
+	damage_count = 0;
 }
 }
 
 
-static int any_dirty_rows(void)
+static void mark_dirty_rect_xy(unsigned int y, unsigned int h,
+			       unsigned int x0, unsigned int x1)
 {
 {
-	unsigned int i;
-	unsigned int max_row = vga_fb_h;
-	if (max_row > MAX_DIRTY_ROWS)
-		max_row = MAX_DIRTY_ROWS;
-	for (i = 0; i < (max_row + 7) / 8; i++)
-		if (vga_shadow_dirty_rows[i])
-			return 1;
-	return 0;
+	damage_add(x0, y, x1, y + h);
 }
 }
 
 
-static void clear_dirty_rows(void)
+/* Full-width dirty rows (used where the x-extent isn't tracked). */
+static void mark_dirty_rect(unsigned int y, unsigned int h)
 {
 {
-	unsigned int i;
-	unsigned int max_row = vga_fb_h;
-	if (max_row > MAX_DIRTY_ROWS)
-		max_row = MAX_DIRTY_ROWS;
-	for (i = 0; i < (max_row + 7) / 8; i++)
-		vga_shadow_dirty_rows[i] = 0;
-	vga_dirty_x0 = vga_fb_w;
-	vga_dirty_x1 = 0;
+	damage_add(0, y, vga_fb_w, y + h);
 }
 }
 
 
 /*
 /*
@@ -424,55 +482,77 @@ void vga_shadow_init(void)
 	vga_shadow_buf = (unsigned char *)VGA_SHADOW_BASE;
 	vga_shadow_buf = (unsigned char *)VGA_SHADOW_BASE;
 	vga_shadow_pitch = vga_fb_pitch_val;
 	vga_shadow_pitch = vga_fb_pitch_val;
 	vga_shadow_size = vga_fb_h * vga_shadow_pitch;
 	vga_shadow_size = vga_fb_h * vga_shadow_pitch;
-	clear_dirty_rows();
+	damage_clear();
 }
 }
 
 
-/* Copy dirty rows from shadow to VRAM, at most about `max_bytes` this call
- * (0 = no limit).  A row is cleared as it is copied, so the next call resumes
- * with whatever is left: a large repaint is spread over several main-loop
- * iterations instead of stalling input behind it. */
-static unsigned int shadow_copy_dirty_rows(unsigned int max_bytes)
+/* Copy damage rects from the shadow to VRAM, at most about `max_bytes` this
+ * call (0 = no limit), and drop the rects that are done.  A rect that fits
+ * the budget is copied whole even when that overshoots a little, so a
+ * window-sized repaint is never split across iterations; only a rect larger
+ * than the budget (a full-screen repaint) is chunked, and its remaining rows
+ * move to the back of the list so newer, smaller damage is flushed first. */
+static unsigned int shadow_copy_damage(unsigned int max_bytes)
 {
 {
-	unsigned int row, bytes = 0;
+	unsigned int i = 0, bytes = 0;
 	unsigned int pb = vga_pixel_bytes();
 	unsigned int pb = vga_pixel_bytes();
 	unsigned int align = (pb == 2) ? 2 : (pb == 3) ? 4 : 1;
 	unsigned int align = (pb == 2) ? 2 : (pb == 3) ? 4 : 1;
-	unsigned int x0 = vga_dirty_x0;
-	unsigned int x1 = vga_dirty_x1;
-	unsigned int dwords;
 	unsigned char *src = vga_shadow_buf;
 	unsigned char *src = vga_shadow_buf;
 	unsigned char *dst = (unsigned char *)vga_fb_lfb;
 	unsigned char *dst = (unsigned char *)vga_fb_lfb;
-	unsigned int max_row = vga_fb_h;
-	if (max_row > MAX_DIRTY_ROWS)
-		max_row = MAX_DIRTY_ROWS;
 
 
-	/* Clamp and dword-align the horizontal span so each row copy is an
-	   integral number of dwords starting on a dword boundary. */
-	if (x1 > vga_fb_w)
-		x1 = vga_fb_w;
-	x0 &= ~(align - 1);
-	x1 = (x1 + align - 1) & ~(align - 1);
-	if (x1 > vga_fb_w)
-		x1 = vga_fb_w;
-	if (x0 >= x1)
-		return 0;
-	dwords = ((x1 - x0) * pb) / 4;
-
-	for (row = 0; row < max_row; row++) {
-		if (vga_shadow_dirty_rows[row / 8] & (1 << (row % 8))) {
-			vga_shadow_dirty_rows[row / 8] &= ~(1 << (row % 8));
-			vga_fb_copy_row(
-				(void *)(dst + (unsigned long)row * vga_fb_pitch_val + x0 * pb),
-				(void *)(src + (unsigned long)row * vga_shadow_pitch + x0 * pb),
-				dwords);
-			bytes += dwords * 4;
-			if (max_bytes && bytes >= max_bytes)
+	while (i < damage_count) {
+		struct damage_rect *d = &damage_rects[i];
+		unsigned int rx0 = d->x0 & ~(align - 1);
+		unsigned int rx1 = (d->x1 + align - 1) & ~(align - 1);
+		unsigned int row_bytes, rect_bytes, dwords, tail, y;
+
+		if (rx1 > vga_fb_w)
+			rx1 = vga_fb_w;
+		if (rx0 >= rx1) {
+			damage_rects[i] = damage_rects[--damage_count];
+			continue;
+		}
+		row_bytes = (rx1 - rx0) * pb;
+		rect_bytes = row_bytes * (d->y1 - d->y0);
+		dwords = row_bytes / 4;
+		tail = row_bytes % 4;
+
+		/* The budget is spent and this rect is bigger than a whole
+		   call: leave it (rows already copied keep their progress). */
+		if (max_bytes && bytes > 0 && rect_bytes > max_bytes)
+			break;
+
+		for (y = d->y0; y < d->y1; y++) {
+			unsigned char *s = src + (unsigned long)y * vga_shadow_pitch + rx0 * pb;
+			unsigned char *t = dst + (unsigned long)y * vga_fb_pitch_val + rx0 * pb;
+
+			vga_fb_copy_row(t, s, dwords);
+			if (tail) {
+				unsigned int k;
+				for (k = dwords * 4; k < row_bytes; k++)
+					t[k] = s[k];
+			}
+			bytes += row_bytes;
+			if (max_bytes && rect_bytes > max_bytes && bytes >= max_bytes) {
+				d->y0 = y + 1;
 				break;
 				break;
+			}
 		}
 		}
+		if (y < d->y1) {
+			/* Chunked: keep the remaining rows, behind the rest. */
+			struct damage_rect rest = *d;
+
+			damage_rects[i] = damage_rects[--damage_count];
+			damage_rects[damage_count++] = rest;
+			return bytes;
+		}
+		damage_rects[i] = damage_rects[--damage_count];
+		if (max_bytes && bytes >= max_bytes)
+			break;
 	}
 	}
 	return bytes;
 	return bytes;
 }
 }
 
 
-/* Copy up to `max_bytes` of the dirty shadow rows to VRAM.  Called from the
+/* Copy up to `max_bytes` of the pending damage to VRAM.  Called from the
  * main loop on every iteration: small updates (a cursor move is ~1 KB) reach
  * main loop on every iteration: small updates (a cursor move is ~1 KB) reach
  * the screen within one loop instead of waiting for a fixed 30 Hz tick, while
  * the screen within one loop instead of waiting for a fixed 30 Hz tick, while
  * a full-screen repaint is chunked so it cannot stall input. */
  * a full-screen repaint is chunked so it cannot stall input. */
@@ -481,14 +561,9 @@ void vga_fb_flush_budget(unsigned int max_bytes)
 	vga_cache_boot_fb();
 	vga_cache_boot_fb();
 	if (!vga_shadow_buf || !vga_fb_lfb)
 	if (!vga_shadow_buf || !vga_fb_lfb)
 		return;
 		return;
-	if (!any_dirty_rows())
-		return;
-	if (shadow_copy_dirty_rows(max_bytes) == 0) {
-		clear_dirty_rows();          /* degenerate span: drop the marks */
+	if (!damage_any())
 		return;
 		return;
-	}
-	if (!any_dirty_rows())
-		clear_dirty_rows();          /* also resets the dirty x-span */
+	shadow_copy_damage(max_bytes);
 }
 }
 
 
 void vga_fb_flush(void)
 void vga_fb_flush(void)
@@ -503,17 +578,19 @@ int vga_shadow_is_active(void)
 
 
 void vga_fb_mark_dirty_rect(unsigned int y, unsigned int h)
 void vga_fb_mark_dirty_rect(unsigned int y, unsigned int h)
 {
 {
+	vga_cache_boot_fb();
 	mark_dirty_rect(y, h);
 	mark_dirty_rect(y, h);
 }
 }
 
 
-/* Mark rows dirty, limited to the horizontal span [x0, x1). */
+/* Mark a rectangle dirty, limited to the horizontal span [x0, x1). */
 void vga_fb_mark_dirty_rect_xy(unsigned int y, unsigned int h,
 void vga_fb_mark_dirty_rect_xy(unsigned int y, unsigned int h,
 			       unsigned int x0, unsigned int x1)
 			       unsigned int x0, unsigned int x1)
 {
 {
+	vga_cache_boot_fb();
 	mark_dirty_rect_xy(y, h, x0, x1);
 	mark_dirty_rect_xy(y, h, x0, x1);
 }
 }
 
 
 void vga_fb_clear_dirty(void)
 void vga_fb_clear_dirty(void)
 {
 {
-	clear_dirty_rows();
+	damage_clear();
 }
 }

+ 6 - 5
vga.h

@@ -1,5 +1,6 @@
-/* VGA: VESA LFB (from boot). Shadow buffer, damage-driven flush with a
- * per-iteration byte budget (no fixed frame rate). */
+/* VGA: VESA LFB (from boot). Shadow buffer; the main loop copies pending
+ * damage rectangles to VRAM on every iteration (byte budget, no fixed frame
+ * rate). */
 #ifndef VGA_H
 #ifndef VGA_H
 #define VGA_H
 #define VGA_H
 
 
@@ -51,7 +52,7 @@ void vga_shadow_init(void);
  * blocking redraws and at boot. */
  * blocking redraws and at boot. */
 void vga_fb_flush(void);
 void vga_fb_flush(void);
 
 
-/* Copy up to max_bytes of the dirty shadow rows to VRAM (0 = no limit).
+/* Copy up to max_bytes of the pending damage rects to VRAM (0 = no limit).
  * Called by the main loop every iteration: small updates reach the screen
  * Called by the main loop every iteration: small updates reach the screen
  * within one loop, large ones are chunked so they cannot stall input. */
  * within one loop, large ones are chunked so they cannot stall input. */
 void vga_fb_flush_budget(unsigned int max_bytes);
 void vga_fb_flush_budget(unsigned int max_bytes);
@@ -67,11 +68,11 @@ int vga_shadow_is_active(void);
 /* Mark rows dirty for direct buffer manipulators (e.g. fbtext_scroll). */
 /* Mark rows dirty for direct buffer manipulators (e.g. fbtext_scroll). */
 void vga_fb_mark_dirty_rect(unsigned int y, unsigned int h);
 void vga_fb_mark_dirty_rect(unsigned int y, unsigned int h);
 
 
-/* Mark rows dirty, limited to the horizontal span [x0, x1). */
+/* Mark a rectangle dirty, limited to the horizontal span [x0, x1). */
 void vga_fb_mark_dirty_rect_xy(unsigned int y, unsigned int h,
 void vga_fb_mark_dirty_rect_xy(unsigned int y, unsigned int h,
 			       unsigned int x0, unsigned int x1);
 			       unsigned int x0, unsigned int x1);
 
 
-/* Clear the dirty-row bitmap (so only explicitly re-marked rows get flushed). */
+/* Drop all pending damage (so only explicitly re-marked areas get flushed). */
 void vga_fb_clear_dirty(void);
 void vga_fb_clear_dirty(void);
 
 
 #endif
 #endif

+ 5 - 10
wm.c

@@ -350,8 +350,6 @@ static void wm_drag_shadow(struct window *w, unsigned int ox, unsigned int oy,
 {
 {
 	int dx = (int)nx - (int)ox;
 	int dx = (int)nx - (int)ox;
 	int dy = (int)ny - (int)oy;
 	int dy = (int)ny - (int)oy;
-	unsigned int y0 = (oy < ny) ? oy : ny;
-	unsigned int y1 = ((oy > ny) ? oy : ny) + w->ph;
 
 
 	mouse_cursor_erase();
 	mouse_cursor_erase();
 	wm_shadow_copy(ox, oy, nx, ny, w->pw, w->ph);
 	wm_shadow_copy(ox, oy, nx, ny, w->pw, w->ph);
@@ -365,14 +363,11 @@ static void wm_drag_shadow(struct window *w, unsigned int ox, unsigned int oy,
 	else if (dx < 0)
 	else if (dx < 0)
 		wm_redraw_rect(nx + w->pw, oy, (unsigned int)(-dx), w->ph);
 		wm_redraw_rect(nx + w->pw, oy, (unsigned int)(-dx), w->ph);
 
 
-	/* Mark the swept band so the flush copies the moved window + sliver.
-	   Limit the horizontal span to the window's swept x-range so the flush
-	   copies only ~pw columns instead of the full framebuffer width. */
-	{
-		unsigned int x0 = (ox < nx) ? ox : nx;
-		unsigned int x1 = ((ox > nx) ? ox : nx) + w->pw;
-		vga_fb_mark_dirty_rect_xy(y0, y1 - y0, x0, x1);
-	}
+	/* Only the moved window's new rect needs marking: the repaints above
+	   cover the exposed slivers exactly, and the cursor marks itself.  The
+	   damage list merges these when the step is small (the union is then
+	   the swept hull anyway) and keeps them apart after a big jump. */
+	vga_fb_mark_dirty_rect_xy(w->y, w->ph, w->x, w->x + w->pw);
 	mouse_redraw_cursor();
 	mouse_redraw_cursor();
 	vga_fb_flush();
 	vga_fb_flush();
 }
 }