|
|
@@ -5,6 +5,69 @@
|
|
|
|
|
|
#define SCREEN_ATTR 0x0A /* light green on black */
|
|
|
|
|
|
+/* ---- Damage tracking ----
|
|
|
+ *
|
|
|
+ * The WM repaints only the cell block that changed, so every mutation of the
|
|
|
+ * cell buffer -- or of the cursor, which is drawn as an overlay -- has to mark
|
|
|
+ * it: screen_damage_cell() grows the block around a cell, screen_damage_all()
|
|
|
+ * covers the whole grid (a scroll or a clear) and screen_damage_cursor() marks
|
|
|
+ * the cell the cursor sits in.
|
|
|
+ */
|
|
|
+static void screen_damage_cell(struct text_screen *s, unsigned int col, unsigned int row)
|
|
|
+{
|
|
|
+ if (!s->dirty) {
|
|
|
+ s->dirty = 1;
|
|
|
+ s->dmg_col0 = s->dmg_col1 = col;
|
|
|
+ s->dmg_row0 = s->dmg_row1 = row;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (col < s->dmg_col0)
|
|
|
+ s->dmg_col0 = col;
|
|
|
+ if (col > s->dmg_col1)
|
|
|
+ s->dmg_col1 = col;
|
|
|
+ if (row < s->dmg_row0)
|
|
|
+ s->dmg_row0 = row;
|
|
|
+ if (row > s->dmg_row1)
|
|
|
+ s->dmg_row1 = row;
|
|
|
+}
|
|
|
+
|
|
|
+static void screen_damage_all(struct text_screen *s)
|
|
|
+{
|
|
|
+ s->dirty = 1;
|
|
|
+ s->dmg_col0 = 0;
|
|
|
+ s->dmg_col1 = s->cols - 1;
|
|
|
+ s->dmg_row0 = 0;
|
|
|
+ s->dmg_row1 = s->rows - 1;
|
|
|
+}
|
|
|
+
|
|
|
+void screen_damage_cursor(struct text_screen *s)
|
|
|
+{
|
|
|
+ unsigned int pos = s->cursor;
|
|
|
+
|
|
|
+ if (pos >= s->cols * s->rows) {
|
|
|
+ screen_damage_all(s);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ screen_damage_cell(s, pos % s->cols, pos / s->cols);
|
|
|
+}
|
|
|
+
|
|
|
+int screen_damage_block(const struct text_screen *s, unsigned int *col0,
|
|
|
+ unsigned int *row0, unsigned int *cols, unsigned int *rows)
|
|
|
+{
|
|
|
+ if (!s->dirty)
|
|
|
+ return 0;
|
|
|
+ *col0 = s->dmg_col0;
|
|
|
+ *row0 = s->dmg_row0;
|
|
|
+ *cols = s->dmg_col1 - s->dmg_col0 + 1;
|
|
|
+ *rows = s->dmg_row1 - s->dmg_row0 + 1;
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+void screen_clear_damage(struct text_screen *s)
|
|
|
+{
|
|
|
+ s->dirty = 0;
|
|
|
+}
|
|
|
+
|
|
|
void screen_init(struct text_screen *s)
|
|
|
{
|
|
|
s->cols = SCREEN_COLS;
|
|
|
@@ -12,7 +75,6 @@ void screen_init(struct text_screen *s)
|
|
|
s->cursor = 0;
|
|
|
s->cursor_attr = (SCREEN_ATTR << 8);
|
|
|
s->cursor_visible = 0;
|
|
|
- s->dirty = 1;
|
|
|
s->scrolled = 0;
|
|
|
screen_clear(s);
|
|
|
}
|
|
|
@@ -23,7 +85,7 @@ void screen_clear(struct text_screen *s)
|
|
|
for (i = 0; i < n; i++)
|
|
|
s->cells[i] = (unsigned short)((SCREEN_ATTR << 8) | ' ');
|
|
|
s->cursor = 0;
|
|
|
- s->dirty = 1;
|
|
|
+ screen_damage_all(s);
|
|
|
s->scrolled = 0;
|
|
|
}
|
|
|
|
|
|
@@ -36,7 +98,7 @@ static void screen_scroll_up(struct text_screen *s)
|
|
|
s->cells[i] = s->cells[i + ncols];
|
|
|
for (; i < total; i++)
|
|
|
s->cells[i] = (unsigned short)((SCREEN_ATTR << 8) | ' ');
|
|
|
- s->dirty = 1;
|
|
|
+ screen_damage_all(s);
|
|
|
}
|
|
|
|
|
|
void screen_putchar(struct text_screen *s, char c)
|
|
|
@@ -47,6 +109,7 @@ void screen_putchar(struct text_screen *s, char c)
|
|
|
netlog_char(c); /* terminal text also goes to the netlog mirror */
|
|
|
|
|
|
if (c == '\n') {
|
|
|
+ screen_damage_cursor(s); /* the cursor leaves this cell */
|
|
|
s->cursor = (s->cursor / ncols + 1) * ncols;
|
|
|
if (s->cursor >= total) {
|
|
|
screen_scroll_up(s);
|
|
|
@@ -54,22 +117,24 @@ void screen_putchar(struct text_screen *s, char c)
|
|
|
s->scrolled = 1;
|
|
|
}
|
|
|
s->cursor_attr = (SCREEN_ATTR << 8);
|
|
|
- s->dirty = 1;
|
|
|
+ screen_damage_cursor(s);
|
|
|
return;
|
|
|
}
|
|
|
if (c == '\b') {
|
|
|
if (s->cursor > 0) {
|
|
|
+ screen_damage_cursor(s);
|
|
|
s->cursor--;
|
|
|
s->cells[s->cursor] = (unsigned short)((SCREEN_ATTR << 8) | ' ');
|
|
|
- s->dirty = 1;
|
|
|
+ screen_damage_cursor(s);
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
if (s->cursor < total) {
|
|
|
+ screen_damage_cursor(s); /* the written cell + the cursor */
|
|
|
s->cells[s->cursor] = (unsigned short)(s->cursor_attr | (unsigned char)c);
|
|
|
s->cursor++;
|
|
|
s->cursor_attr = (SCREEN_ATTR << 8);
|
|
|
- s->dirty = 1;
|
|
|
+ screen_damage_cursor(s); /* the cursor moved on */
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -101,15 +166,17 @@ void screen_set_cursor(struct text_screen *s, unsigned int pos)
|
|
|
{
|
|
|
if (pos >= s->cols * s->rows)
|
|
|
return;
|
|
|
+ screen_damage_cursor(s); /* erase the old cursor cell */
|
|
|
s->cursor = pos;
|
|
|
s->cursor_attr = (SCREEN_ATTR << 8);
|
|
|
+ screen_damage_cursor(s);
|
|
|
}
|
|
|
|
|
|
void screen_put_at(struct text_screen *s, unsigned int pos, unsigned short value)
|
|
|
{
|
|
|
if (pos < s->cols * s->rows) {
|
|
|
+ screen_damage_cell(s, pos % s->cols, pos / s->cols);
|
|
|
s->cells[pos] = value;
|
|
|
- s->dirty = 1;
|
|
|
}
|
|
|
}
|
|
|
|