optimize rendering
This commit is contained in:
parent
b22bc95ad5
commit
b4fdc6e813
BIN
bench/perf.data
BIN
bench/perf.data
Binary file not shown.
BIN
bench/perf.data.old
Normal file
BIN
bench/perf.data.old
Normal file
Binary file not shown.
2
dat.h
2
dat.h
@ -117,7 +117,7 @@ typedef struct Drawcmd Drawcmd;
|
||||
struct Drawcmd
|
||||
{
|
||||
Str pre;
|
||||
Str kouho[Maxkouho];
|
||||
Str kouho[Maxdisp];
|
||||
int nkouho;
|
||||
int sel;
|
||||
};
|
||||
|
||||
22
font.c
22
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];
|
||||
}
|
||||
|
||||
2
main.c
2
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);
|
||||
|
||||
13
strans.c
13
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);
|
||||
}
|
||||
|
||||
|
||||
13
win.c
13
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user