ref: 6543539a006eb655189d43bdcea467c9c9c2f37c
parent: ffc9934ccdba5b995ea087ad6f08c4e864b0bd4b
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 14 19:24:55 EST 2020
plan9: try to draw as many chars of the same style as possible in one call
--- a/plan9.c
+++ b/plan9.c
@@ -75,6 +75,7 @@
static int altdown;
static int mode = Minsert;
static long framedev; /* frame deviation >= 1ms */
+static Rune *linebuf;
static char *style[Numstyles] = {
[Sfancy] = "fancy",
@@ -304,20 +305,23 @@
redraw(void)
{
Point p, top, bot;
- int x, y, len, rx, ry;
- int bg, fg, attr, selected;
+ int x, y, len, rx, ry, i;
+ int oldbg, oldfg, bg, fg, attr, selected;
Rune c;
draw(screen, screen->r, color[Dback], nil, ZP);
- p = screen->r.min;
- p.x += Txtoff;
- p.y += Txtoff;
+ p = addpt(screen->r.min, Pt(Txtoff, Txtoff));
top = p;
bot.x = top.x;
bot.y = screen->r.max.y - Txtoff - charh*2;
+ bg = -1;
+ fg = -1;
for (y = 0; y < field.height && p.y < bot.y-charh; y++) {
- for (x = 0; x < field.width; x++) {
+ for (x = i = 0; x < field.width && x < screen->r.max.x-Txtoff; x++) {
+ oldbg = bg;
+ oldfg = fg;
+
c = field.buffer[field.width*y + x];
attr = mbuf.buffer[field.width*y + x];
@@ -360,10 +364,15 @@
fg = Dbmed;
}
}
- runestringnbg(screen, p, color[fg], ZP, font, &c, 1, color[bg], ZP);
- p.x += charw;
+
+ if (i > 0 && (bg != oldbg || fg != oldfg)) {
+ p = runestringnbg(screen, p, color[oldfg], ZP, font, linebuf, i, color[oldbg], ZP);
+ i = 0;
+ }
+ linebuf[i++] = c;
}
- p.y += font->height;
+ runestringnbg(screen, p, color[fg], ZP, font, linebuf, i, color[bg], ZP);
+ p.y += charh;
p.x = top.x;
}
@@ -742,6 +751,7 @@
case Cresize:
getwindow(display, Refnone);
+ linebuf = realloc(linebuf, sizeof(Rune)*Dx(screen->r)/charw);
break;
case Ckey: