summaryrefslogtreecommitdiff
path: root/src/user/app/init
diff options
context:
space:
mode:
authordzwdz2022-08-02 12:15:56 +0200
committerdzwdz2022-08-02 12:15:56 +0200
commitee3152b239c78ca8888a95b308eb6f0a4aaabe2f (patch)
tree4f561add342ba1f9d57d2c9a87b15a69d1a6edb0 /src/user/app/init
parent341961b59eb08bfbbb1cc2a43704b8916142a5b2 (diff)
user/ansiterm: only write() the part of the framebuffer that changed
Diffstat (limited to 'src/user/app/init')
-rw-r--r--src/user/app/init/driver/ansiterm.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/user/app/init/driver/ansiterm.c b/src/user/app/init/driver/ansiterm.c
index 7d842a5..b59d0b8 100644
--- a/src/user/app/init/driver/ansiterm.c
+++ b/src/user/app/init/driver/ansiterm.c
@@ -22,7 +22,8 @@ struct psf {
static handle_t fb_fd;
static struct {int x, y;} cursor = {0};
-static bool dirty = false;
+
+static size_t dirty_low = ~0, dirty_high = 0;
// TODO don't hardcode size
static const size_t fb_len = 640 * 480 * 4;
@@ -36,10 +37,17 @@ static void *font_data;
static void flush(void) {
- size_t off = 0;
- while (off < fb_len)
- off += _syscall_write(fb_fd, fb + off, fb_len - off, off, 0);
- dirty = false;
+ if (dirty_high == 0) return;
+
+ if (dirty_high > fb_len) // shouldn't happen
+ dirty_high = fb_len;
+
+ // still not optimal, copies 80 characters instead of 1
+ while (dirty_low < dirty_high)
+ dirty_low += _syscall_write(fb_fd, fb + dirty_low, dirty_high - dirty_low, dirty_low, 0);
+
+ dirty_low = ~0;
+ dirty_high = 0;
}
static void scroll(void) {
@@ -48,11 +56,19 @@ static void scroll(void) {
memcpy(fb, fb + row_len, fb_len - row_len);
memset(fb + fb_len - row_len, 0, row_len);
cursor.y--;
+ dirty_low = 0; dirty_high = ~0;
}
static void font_blit(size_t glyph, int x, int y) {
if (glyph >= font.glyph_amt) glyph = 0;
+ size_t low = fb_pitch * ( y * font.h) + 4 * ( x * font.w);
+ size_t high = fb_pitch * ((y+1) * font.h) + 4 * ((x+1) * font.w) + 3;
+ if (dirty_low > low)
+ dirty_low = low;
+ if (dirty_high < high)
+ dirty_high = high;
+
char *bitmap = font_data + font.glyph_size * glyph;
for (size_t i = 0; i < font.w; i++) {
for (size_t j = 0; j < font.h; j++) {
@@ -84,7 +100,6 @@ static void in_char(char c) {
cursor.y++;
}
while (cursor.y * font.h >= fb_height) scroll();
- dirty = true;
}
static void font_load(void) {