optimize rendering
This commit is contained in:
parent
b41cf78862
commit
129b842487
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
|
struct Drawcmd
|
||||||
{
|
{
|
||||||
Str pre;
|
Str pre;
|
||||||
Str kouho[Maxkouho];
|
Str kouho[Maxdisp];
|
||||||
int nkouho;
|
int nkouho;
|
||||||
int sel;
|
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)
|
putfont(u32int *buf, int w, int h, int px, int py, Rune r)
|
||||||
{
|
{
|
||||||
Glyph *g;
|
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;
|
u32int *p;
|
||||||
|
|
||||||
if(r >= Nglyphs)
|
if(r >= Nglyphs)
|
||||||
@ -116,17 +117,18 @@ putfont(u32int *buf, int w, int h, int px, int py, Rune r)
|
|||||||
if(g->bmp == nil)
|
if(g->bmp == nil)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(j = 0; j < g->h; j++){
|
|
||||||
y = py + j + g->oy + Fontsz - Fontbase;
|
y0 = py + g->oy + Fontsz - Fontbase;
|
||||||
if(y < 0 || y >= h)
|
j0 = y0 < 0 ? -y0 : 0;
|
||||||
continue;
|
j1 = y0 + g->h > h ? h - y0 : g->h;
|
||||||
for(i = 0; i < g->w; i++){
|
x0 = px + g->ox;
|
||||||
x = px + i + g->ox;
|
i0 = x0 < 0 ? -x0 : 0;
|
||||||
if(x < 0 || x >= w)
|
i1 = x0 + g->w > w ? w - x0 : g->w;
|
||||||
continue;
|
for(j = j0; j < j1; j++){
|
||||||
|
for(i = i0; i < i1; i++){
|
||||||
a = g->bmp[j * g->w + i];
|
a = g->bmp[j * g->w + i];
|
||||||
if(a > 0){
|
if(a > 0){
|
||||||
p = &buf[y * w + x];
|
p = &buf[(y0 + j) * w + x0 + i];
|
||||||
sel = (*p == Colsel) ? 1 : 0;
|
sel = (*p == Colsel) ? 1 : 0;
|
||||||
*p = blendtab[sel][a];
|
*p = blendtab[sel][a];
|
||||||
}
|
}
|
||||||
|
|||||||
2
main.c
2
main.c
@ -61,7 +61,7 @@ threadmain(int argc, char **argv)
|
|||||||
usage();
|
usage();
|
||||||
|
|
||||||
fontdir = argv[2];
|
fontdir = argv[2];
|
||||||
drawc = chancreate(sizeof(Drawcmd), 0);
|
drawc = chancreate(sizeof(Drawcmd), 4);
|
||||||
keyc = chancreate(sizeof(Keyreq), 0);
|
keyc = chancreate(sizeof(Keyreq), 0);
|
||||||
dictreqc = chancreate(sizeof(Dictreq), 4);
|
dictreqc = chancreate(sizeof(Dictreq), 4);
|
||||||
dictresc = chancreate(sizeof(Dictres), 0);
|
dictresc = chancreate(sizeof(Dictres), 0);
|
||||||
|
|||||||
13
strans.c
13
strans.c
@ -43,15 +43,18 @@ static void
|
|||||||
show(void)
|
show(void)
|
||||||
{
|
{
|
||||||
Drawcmd dc;
|
Drawcmd dc;
|
||||||
int i;
|
int i, first, n;
|
||||||
|
|
||||||
sclear(&dc.pre);
|
sclear(&dc.pre);
|
||||||
if(!mapget(im.l->map, &im.pre, &dc.pre))
|
if(!mapget(im.l->map, &im.pre, &dc.pre))
|
||||||
dc.pre = im.pre;
|
dc.pre = im.pre;
|
||||||
dc.nkouho = im.nkouho;
|
first = im.sel >= Maxdisp ? im.sel - Maxdisp + 1 : 0;
|
||||||
dc.sel = im.sel;
|
n = im.nkouho - first;
|
||||||
for(i = 0; i < dc.nkouho; i++)
|
if(n > Maxdisp) n = Maxdisp;
|
||||||
dc.kouho[i] = im.kouho[i];
|
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);
|
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));
|
memset(img, (uchar)Colbg, w * h * sizeof(u32int));
|
||||||
drawstr(img, 0, 0, dc->pre.r, dc->pre.n, w, h);
|
drawstr(img, 0, 0, dc->pre.r, dc->pre.n, w, h);
|
||||||
if(dc->sel >= 0){
|
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));
|
memset(img + sely * w, (uchar)Colsel, Fontsz * w * sizeof(u32int));
|
||||||
}
|
}
|
||||||
for(i = 0, y = Fontsz; i < n; i++, y += Fontsz){
|
for(i = 0, y = Fontsz; i < n; i++, y += Fontsz){
|
||||||
@ -101,17 +101,16 @@ winhide(void)
|
|||||||
static void
|
static void
|
||||||
winshow(Drawcmd *dc)
|
winshow(Drawcmd *dc)
|
||||||
{
|
{
|
||||||
int px, py, w, h, i, n, first, maxw;
|
int px, py, w, h, i, n, maxw;
|
||||||
u32int vals[4];
|
u32int vals[4];
|
||||||
xcb_query_pointer_reply_t *ptr;
|
xcb_query_pointer_reply_t *ptr;
|
||||||
xcb_query_pointer_cookie_t cookie;
|
xcb_query_pointer_cookie_t cookie;
|
||||||
|
|
||||||
cookie = xcb_query_pointer(conn, scr->root);
|
cookie = xcb_query_pointer(conn, scr->root);
|
||||||
first = dc->sel >= Maxdisp ? dc->sel - Maxdisp + 1 : 0;
|
n = dc->nkouho;
|
||||||
n = min(dc->nkouho - first, Maxdisp);
|
|
||||||
maxw = dc->pre.n;
|
maxw = dc->pre.n;
|
||||||
for(i = 0; i < n; i++)
|
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);
|
ptr = xcb_query_pointer_reply(conn, cookie, nil);
|
||||||
if(ptr == nil)
|
if(ptr == nil)
|
||||||
die("xcb_query_pointer");
|
die("xcb_query_pointer");
|
||||||
@ -127,7 +126,7 @@ winshow(Drawcmd *dc)
|
|||||||
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
||||||
vals);
|
vals);
|
||||||
xcb_map_window(conn, win);
|
xcb_map_window(conn, win);
|
||||||
drawkouho(dc, first, n, w, h);
|
drawkouho(dc, 0, n, w, h);
|
||||||
putimage(w, h);
|
putimage(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +138,8 @@ drawthread(void*)
|
|||||||
threadsetname("draw");
|
threadsetname("draw");
|
||||||
wininit();
|
wininit();
|
||||||
while(chanrecv(drawc, &dc) > 0){
|
while(chanrecv(drawc, &dc) > 0){
|
||||||
|
while(channbrecv(drawc, &dc) > 0)
|
||||||
|
;
|
||||||
if(dc.nkouho == 0 && dc.pre.n == 0)
|
if(dc.nkouho == 0 && dc.pre.n == 0)
|
||||||
winhide();
|
winhide();
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user