diff --git a/bench/perf.data b/bench/perf.data index 84a8914..59111df 100644 Binary files a/bench/perf.data and b/bench/perf.data differ diff --git a/bench/perf.data.old b/bench/perf.data.old new file mode 100644 index 0000000..84a8914 Binary files /dev/null and b/bench/perf.data.old differ diff --git a/dat.h b/dat.h index 9fe6a52..e6fa157 100644 --- a/dat.h +++ b/dat.h @@ -117,7 +117,7 @@ typedef struct Drawcmd Drawcmd; struct Drawcmd { Str pre; - Str kouho[Maxkouho]; + Str kouho[Maxdisp]; int nkouho; int sel; }; diff --git a/font.c b/font.c index b87cf88..0d0ad7e 100644 --- a/font.c +++ b/font.c @@ -99,7 +99,8 @@ void putfont(u32int *buf, int w, int h, int px, int py, Rune r) { Glyph *g; - int i, j, x, y, a, sel, f; + int i, j, a, sel, f; + int y0, j0, j1, x0, i0, i1; u32int *p; if(r >= Nglyphs) @@ -116,17 +117,18 @@ putfont(u32int *buf, int w, int h, int px, int py, Rune r) if(g->bmp == nil) return; } - for(j = 0; j < g->h; j++){ - y = py + j + g->oy + Fontsz - Fontbase; - if(y < 0 || y >= h) - continue; - for(i = 0; i < g->w; i++){ - x = px + i + g->ox; - if(x < 0 || x >= w) - continue; + + y0 = py + g->oy + Fontsz - Fontbase; + j0 = y0 < 0 ? -y0 : 0; + j1 = y0 + g->h > h ? h - y0 : g->h; + x0 = px + g->ox; + i0 = x0 < 0 ? -x0 : 0; + i1 = x0 + g->w > w ? w - x0 : g->w; + for(j = j0; j < j1; j++){ + for(i = i0; i < i1; i++){ a = g->bmp[j * g->w + i]; if(a > 0){ - p = &buf[y * w + x]; + p = &buf[(y0 + j) * w + x0 + i]; sel = (*p == Colsel) ? 1 : 0; *p = blendtab[sel][a]; } diff --git a/main.c b/main.c index 07ad5f0..cc6b9df 100644 --- a/main.c +++ b/main.c @@ -61,7 +61,7 @@ threadmain(int argc, char **argv) usage(); fontdir = argv[2]; - drawc = chancreate(sizeof(Drawcmd), 0); + drawc = chancreate(sizeof(Drawcmd), 4); keyc = chancreate(sizeof(Keyreq), 0); dictreqc = chancreate(sizeof(Dictreq), 4); dictresc = chancreate(sizeof(Dictres), 0); diff --git a/strans.c b/strans.c index c5bc950..85dd8cf 100644 --- a/strans.c +++ b/strans.c @@ -43,15 +43,18 @@ static void show(void) { Drawcmd dc; - int i; + int i, first, n; sclear(&dc.pre); if(!mapget(im.l->map, &im.pre, &dc.pre)) dc.pre = im.pre; - dc.nkouho = im.nkouho; - dc.sel = im.sel; - for(i = 0; i < dc.nkouho; i++) - dc.kouho[i] = im.kouho[i]; + first = im.sel >= Maxdisp ? im.sel - Maxdisp + 1 : 0; + n = im.nkouho - first; + if(n > Maxdisp) n = Maxdisp; + dc.nkouho = n; + dc.sel = im.sel >= 0 ? im.sel - first : -1; + for(i = 0; i < n; i++) + dc.kouho[i] = im.kouho[first + i]; chansend(drawc, &dc); } diff --git a/win.c b/win.c index fdc6e95..062ad6d 100644 --- a/win.c +++ b/win.c @@ -73,7 +73,7 @@ drawkouho(Drawcmd *dc, int first, int n, int w, int h) memset(img, (uchar)Colbg, w * h * sizeof(u32int)); drawstr(img, 0, 0, dc->pre.r, dc->pre.n, w, h); if(dc->sel >= 0){ - sely = Fontsz + (dc->sel - first) * Fontsz; + sely = Fontsz + dc->sel * Fontsz; memset(img + sely * w, (uchar)Colsel, Fontsz * w * sizeof(u32int)); } for(i = 0, y = Fontsz; i < n; i++, y += Fontsz){ @@ -101,17 +101,16 @@ winhide(void) static void winshow(Drawcmd *dc) { - int px, py, w, h, i, n, first, maxw; + int px, py, w, h, i, n, maxw; u32int vals[4]; xcb_query_pointer_reply_t *ptr; xcb_query_pointer_cookie_t cookie; cookie = xcb_query_pointer(conn, scr->root); - first = dc->sel >= Maxdisp ? dc->sel - Maxdisp + 1 : 0; - n = min(dc->nkouho - first, Maxdisp); + n = dc->nkouho; maxw = dc->pre.n; for(i = 0; i < n; i++) - maxw = max(maxw, dc->kouho[first+i].n); + maxw = max(maxw, dc->kouho[i].n); ptr = xcb_query_pointer_reply(conn, cookie, nil); if(ptr == nil) die("xcb_query_pointer"); @@ -127,7 +126,7 @@ winshow(Drawcmd *dc) XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, vals); xcb_map_window(conn, win); - drawkouho(dc, first, n, w, h); + drawkouho(dc, 0, n, w, h); putimage(w, h); } @@ -139,6 +138,8 @@ drawthread(void*) threadsetname("draw"); wininit(); while(chanrecv(drawc, &dc) > 0){ + while(channbrecv(drawc, &dc) > 0) + ; if(dc.nkouho == 0 && dc.pre.n == 0) winhide(); else