Commit 510e3047 authored by deuce's avatar deuce
Browse files

Add a bitmap_movetext() implementation to speed up movetext() calls

(Which is used by the scroll functions)

Use movetext() rather than alloc()/gettext()/puttext() in cterm.c
parent e4c59ee1
......@@ -125,7 +125,7 @@ int bitmap_init_mode(int mode, int *width, int *height)
}
/* Initialize the damaged array */
newdamaged=(int *)malloc(sizeof(int)*vstat.rows);
if(newdamaged==NULL) {
pthread_mutex_unlock(&vstatlock);
......@@ -210,6 +210,47 @@ end:
/********************************************************/
/* Called from main thread only (Passes Event) */
int bitmap_movetext(int x, int y, int ex, int ey, int tox, int toy)
{
int direction=1;
int cy;
int sy;
int destoffset;
int sourcepos;
int width=ex-x+1;
int height=ey-y+1;
if( x<1
|| y<1
|| ex<1
|| ey<1
|| tox<1
|| toy<1
|| x>cio_textinfo.screenwidth
|| ex>cio_textinfo.screenwidth
|| tox>cio_textinfo.screenwidth
|| y>cio_textinfo.screenheight
|| ey>cio_textinfo.screenheight
|| toy>cio_textinfo.screenheight)
return(0);
if(toy > y)
direction=-1;
sourcepos=(y-1)*cio_textinfo.screenwidth+(x-1);
destoffset=(((toy-1)*cio_textinfo.screenwidth+(tox-1))-sourcepos);
pthread_mutex_lock(&vstatlock);
for(cy=(direction==-1?(height-1):0); cy<height && cy>=0; cy+=direction) {
damaged[toy+cy]=1;
sourcepos=((y-1)+cy)*cio_textinfo.screenwidth+(x-1);
memmove(&(vstat.vmem[sourcepos+destoffset]), &(vstat.vmem[sourcepos]), sizeof(vstat.vmem[0])*width);
}
pthread_mutex_unlock(&vstatlock);
return(1);
}
int bitmap_puttext(int sx, int sy, int ex, int ey, void *fill)
{
int x,y;
......@@ -675,6 +716,7 @@ static int update_rect(int sx, int sy, int width, int height, int force)
) {
last_vmem[pos] = vstat.vmem[pos];
bitmap_draw_one_char(sx+x,sy+y);
if(!redraw_cursor && sx+x==vstat.curs_col && sy+y==vstat.curs_row)
redraw_cursor=1;
......@@ -703,7 +745,6 @@ static int update_rect(int sx, int sy, int width, int height, int force)
send_rectangle(last_rect.x, last_rect.y, last_rect.width, last_rect.height, FALSE);
last_rect_used=0;
}
lastcharupdated=0;
}
pos++;
......
......@@ -21,5 +21,6 @@ void send_rectangle(int xoffset, int yoffset, int width, int height, int force);
int bitmap_init_mode(int mode, int *width, int *height);
int bitmap_init(void (*drawrect_cb) (int xpos, int ypos, int width, int height, unsigned char *data)
,void (*flush) (void));
int bitmap_movetext(int x, int y, int ex, int ey, int tox, int toy);
#endif
......@@ -128,6 +128,7 @@ int try_sdl_init(int mode)
cio_api.setfont=bitmap_setfont;
cio_api.getfont=bitmap_getfont;
cio_api.loadfont=bitmap_loadfont;
cio_api.movetext=bitmap_movetext;
cio_api.kbhit=sdl_kbhit;
cio_api.getch=sdl_getch;
......@@ -166,6 +167,7 @@ int try_x_init(int mode)
cio_api.getfont=bitmap_getfont;
cio_api.loadfont=bitmap_loadfont;
cio_api.beep=x_beep;
cio_api.movetext=bitmap_movetext;
cio_api.kbhit=x_kbhit;
cio_api.getch=x_getch;
......
......@@ -445,10 +445,9 @@ void scrolldown(void)
char *buf;
int i,j;
buf=(char *)alloca(cterm.width*(cterm.height-1)*2);
gettext(cterm.x,cterm.y,cterm.x+cterm.width-1,cterm.y+cterm.height-2,buf);
puttext(cterm.x,cterm.y+1,cterm.x+cterm.width-1,cterm.y+cterm.height-1,buf);
movetext(cterm.x,cterm.y,cterm.x+cterm.width-1,cterm.y+cterm.height-2,cterm.x,cterm.y+1);
j=0;
buf=(char *)alloca(cterm.width*2);
for(i=0;i<cterm.width;i++) {
if(cterm.emulation == CTERM_EMULATION_ATASCII)
buf[j++]=0;
......@@ -472,10 +471,9 @@ void scrollup(void)
}
gettext(cterm.x,cterm.y,cterm.x+cterm.width-1,cterm.y,cterm.scrollback+(cterm.backpos-1)*cterm.width*2);
}
buf=(char *)alloca(cterm.width*(cterm.height-1)*2);
gettext(cterm.x,cterm.y+1,cterm.x+cterm.width-1,cterm.y+cterm.height-1,buf);
puttext(cterm.x,cterm.y,cterm.x+cterm.width-1,cterm.y+cterm.height-2,buf);
movetext(cterm.x,cterm.y+1,cterm.x+cterm.width-1,cterm.y+cterm.height-1,cterm.x,cterm.y);
j=0;
buf=(char *)alloca(cterm.width*2);
for(i=0;i<cterm.width;i++) {
if(cterm.emulation == CTERM_EMULATION_ATASCII)
buf[j++]=0;
......@@ -495,11 +493,10 @@ void dellines(int lines)
if(lines<1)
return;
linestomove=cterm.height-wherey();
buf=(char *)alloca(cterm.width*(linestomove>lines?linestomove:lines)*2);
gettext(cterm.x,cterm.y+wherey()-1+lines,cterm.x+cterm.width-1,cterm.y+cterm.height-1,buf);
puttext(cterm.x,cterm.y+wherey()-1,cterm.x+cterm.width-1,cterm.y+cterm.height-1-lines,buf);
movetext(cterm.x,cterm.y+wherey()-1+lines,cterm.x+cterm.width-1,cterm.y+cterm.height-1,cterm.x,cterm.y+wherey()-1);
j=0;
k=cterm.width*lines;
buf=(char *)alloca(k*2);
for(i=0;i<k;i++) {
if(cterm.emulation == CTERM_EMULATION_ATASCII)
buf[j++]=0;
......@@ -818,14 +815,9 @@ void do_ansi(char *retbuf, size_t retsize, int *speed)
i=1;
if(i>cterm.height-wherey())
i=cterm.height-wherey();
if(i) {
p2=(char *)alloca((cterm.height-wherey()-i+1)*cterm.width*2);
gettext(cterm.x,cterm.y+wherey()-1,cterm.x+cterm.width-1,cterm.y+cterm.height-1-i,p2);
puttext(cterm.x,cterm.y+wherey()-1+i,cterm.x+cterm.width-1,cterm.y+cterm.height-1,p2);
}
else {
p2=(char *)alloca(cterm.width*2);
}
if(i)
movetext(cterm.x,cterm.y+wherey()-1,cterm.x+cterm.width-1,cterm.y+cterm.height-1-i,cterm.x,cterm.y+wherey()-1+i);
p2=(char *)alloca(cterm.width*2);
j=0;
for(k=0;k<cterm.width;k++) {
p2[j++]=' ';
......@@ -1586,14 +1578,9 @@ char *cterm_write(unsigned char *buf, int buflen, char *retbuf, size_t retsize,
dellines(1);
break;
case 157: /* Insert Line */
if(cterm.height-wherey()) {
p=(char *)alloca((cterm.height-wherey())*cterm.width*2);
gettext(cterm.x,cterm.y+wherey()-1,cterm.x+cterm.width-1,cterm.y+cterm.height-2,p);
puttext(cterm.x,cterm.y+wherey(),cterm.x+cterm.width-1,cterm.y+cterm.height-1,p);
}
else {
p=(char *)alloca(cterm.width*2);
}
if(cterm.height-wherey())
movetext(cterm.x,cterm.y+wherey()-1,cterm.x+cterm.width-1,cterm.y+cterm.height-2,cterm.x,cterm.y+wherey());
p=(char *)alloca(cterm.width*2);
for(k=0;k<cterm.width;k++) {
p[k*2]=0;
p[k*2+1]=cterm.attr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment