Changeset 3579 for trunk

Show
Ignore:
Timestamp:
09/17/08 18:32:17 (2 months ago)
Author:
stepan
Message:

This patch adds damage detection to libpayload's tinycurses. This
significantly speeds up serial output with large windows.

It also adds the function curs_set to enable/disable the cursor (video console
only for now)

Also, use werase in one place to reduce code duplication.

Signed-off-by: Stefan Reinauer <stepan@…>
Acked-by: Jordan Crouse <jordan.crouse@…>

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/payloads/libpayload/curses/tinycurses.c

    r3578 r3579  
    44 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de> 
    55 * Copyright (C) 2008 Ulf Jordan <jordan@chalmers.se> 
     6 * Copyright (C) 2008 coresystems GmbH 
    67 * 
    78 * Redistribution and use in source and binary forms, with or without 
     
    194195/* D */ int clearok(WINDOW *win, bool flag) { win->_clear = flag; return OK; } 
    195196// int color_content(short color, short *r, short *g, short *b) {} 
    196 // int curs_set(int) {} 
     197int curs_set(int on) 
     198{ 
     199        if (curses_flags & F_ENABLE_SERIAL) { 
     200                // TODO 
     201        } 
     202 
     203        if (curses_flags & F_ENABLE_CONSOLE) { 
     204                video_console_cursor_enable(on); 
     205        } 
     206 
     207        return OK; 
     208} 
    197209// int def_prog_mode(void) {} 
    198210// int def_shell_mode(void) {} 
     
    253265        return win; 
    254266} 
    255 int doupdate(void) { /* TODO */ return(*(int *)0); } 
     267int doupdate(void) { /* TODO */ return(0); } 
    256268// WINDOW * dupwin (WINDOW *) {} 
    257269/* D */ int echo(void) { SP->_echo = TRUE; return OK; } 
     
    282294WINDOW *initscr(void) 
    283295{ 
    284         int x, y, i; 
     296        int i; 
    285297 
    286298        // newterm(name, stdout, stdin); 
     
    306318        // TODO: curscr, newscr? 
    307319 
    308         for (y = 0; y <= stdscr->_maxy; y++) { 
    309                 for (x = 0; x <= stdscr->_maxx; x++) { 
    310                         stdscr->_line[y].text[x].chars[0] = ' '; 
    311                         stdscr->_line[y].text[x].attr = A_NORMAL; 
    312                 } 
    313         } 
     320        werase(stdscr); 
    314321 
    315322        return stdscr; 
     
    474481} 
    475482// int vwscanw (WINDOW *, NCURSES_CONST char *,va_list) {} 
    476 // int waddch (WINDOW *, const chtype) {} 
    477483int waddch(WINDOW *win, const chtype ch) 
    478484{ 
     
    481487        // SetChar2(wch, ch); 
    482488 
     489        if (win->_line[win->_cury].firstchar == _NOCHANGE ||  
     490                        win->_line[win->_cury].firstchar > win->_curx) 
     491                win->_line[win->_cury].firstchar = win->_curx; 
     492 
    483493        win->_line[win->_cury].text[win->_curx].chars[0] = 
    484494                ((ch) & (chtype)A_CHARTEXT); 
     
    487497        win->_line[win->_cury].text[win->_curx].attr |= 
    488498                ((ch) & (chtype)A_ATTRIBUTES); 
     499 
     500        if (win->_line[win->_cury].lastchar == _NOCHANGE ||  
     501                        win->_line[win->_cury].lastchar < win->_curx) 
     502                win->_line[win->_cury].lastchar = win->_curx; 
     503 
    489504        win->_curx++;   // FIXME 
    490505 
     
    507522        if (n < 0) 
    508523                n = strlen(astr); 
     524 
     525        if (win->_line[win->_cury].firstchar == _NOCHANGE ||  
     526                        win->_line[win->_cury].firstchar > win->_curx) 
     527                win->_line[win->_cury].firstchar = win->_curx; 
    509528 
    510529        while ((n-- > 0) && (*str != '\0')) { 
     
    522541                // } 
    523542        } 
     543 
     544        if (win->_line[win->_cury].lastchar == _NOCHANGE ||  
     545                        win->_line[win->_cury].lastchar < win->_curx) 
     546                win->_line[win->_cury].lastchar = win->_curx; 
     547 
    524548        return code; 
    525549} 
     
    604628                        win->_line[y].text[x].attr = WINDOW_ATTRS(win); 
    605629                } 
     630                // Should we check instead? 
     631                win->_line[y].firstchar = 0; 
     632                win->_line[y].lastchar = win->_maxx; 
    606633        } 
    607634        return OK; 
     
    682709        for (y = 0; y <= win->_maxy; y++) { 
    683710 
     711                if (win->_line[y].firstchar == _NOCHANGE) 
     712                        continue; 
     713 
    684714                /* Position the serial cursor */ 
    685715 
    686716                if (curses_flags & F_ENABLE_SERIAL) 
    687                         serial_set_cursor(win->_begy + y, win->_begx); 
    688  
    689                 for (x = 0; x <= win->_maxx; x++) { 
     717                        serial_set_cursor(win->_begy + y, win->_begx + 
     718                                        win->_line[y].firstchar); 
     719 
     720                for (x = win->_line[y].firstchar; x <= win->_line[y].lastchar; x++) { 
    690721                        attr_t attr = win->_line[y].text[x].attr; 
    691722 
     
    735766 
    736767                                serial_putchar(ch); 
     768 
    737769                        } 
    738770 
     
    769801                        } 
    770802                } 
    771         } 
     803                win->_line[y].firstchar = _NOCHANGE; 
     804                win->_line[y].lastchar = _NOCHANGE; 
     805        } 
     806 
     807        if (curses_flags & F_ENABLE_SERIAL) 
     808                serial_set_cursor(win->_begy + win->_cury, win->_begx + win->_curx); 
     809 
     810        if (curses_flags & F_ENABLE_CONSOLE) 
     811                video_console_set_cursor(win->_begx + win->_curx, win->_begy + win->_cury); 
    772812 
    773813        return OK; 
     
    814854int wscrl(WINDOW *win, int n) 
    815855{ 
     856        int x, y; 
     857 
    816858        if (!win->_scroll) 
    817859                return ERR; 
    818860 
    819         if (n != 0) { 
    820                 int x, y; 
    821  
    822                 for (y = 0; y <= (win->_maxy - n); y++) { 
    823                         for (x = 0; x <= win->_maxx; x++) { 
     861        if (n == 0) 
     862                return OK; 
     863 
     864        for (y = 0; y <= (win->_maxy - n); y++) { 
     865                win->_line[y].firstchar = win->_line[y + n].firstchar; 
     866                win->_line[y].lastchar = win->_line[y + n].lastchar; 
     867                for (x = 0; x <= win->_maxx; x++) { 
     868                        if ((win->_line[y].text[x].chars[0] != win->_line[y + n].text[x].chars[0]) ||  
     869                                        (win->_line[y].text[x].attr != win->_line[y + n].text[x].attr)) { 
     870                                if (win->_line[y].firstchar == _NOCHANGE) 
     871                                        win->_line[y].firstchar = x; 
     872 
     873                                win->_line[y].lastchar = x; 
     874 
    824875                                win->_line[y].text[x].chars[0] = win->_line[y + n].text[x].chars[0]; 
    825876                                win->_line[y].text[x].attr = win->_line[y + n].text[x].attr; 
    826877                        } 
    827878                } 
    828  
    829                 for (y = (win->_maxy+1 - n); y <= win->_maxy; y++) { 
    830                         for (x = 0; x <= win->_maxx; x++) { 
     879        } 
     880 
     881        for (y = (win->_maxy+1 - n); y <= win->_maxy; y++) { 
     882                for (x = 0; x <= win->_maxx; x++) { 
     883                        if ((win->_line[y].text[x].chars[0] != ' ') ||  
     884                                        (win->_line[y].text[x].attr != A_NORMAL)) { 
     885                                if (win->_line[y].firstchar == _NOCHANGE) 
     886                                        win->_line[y].firstchar = x; 
     887 
     888                                win->_line[y].lastchar = x; 
     889 
    831890                                win->_line[y].text[x].chars[0] = ' '; 
    832891                                win->_line[y].text[x].attr = A_NORMAL; 
    833892                        } 
    834893                } 
    835  
    836                 // _nc_scroll_window(win, n, win->_regtop, win->_regbottom, win->_nc_bkgd); 
    837                 // _nc_synchook(win); 
    838         } 
     894        } 
     895 
     896        // _nc_scroll_window(win, n, win->_regtop, win->_regbottom, win->_nc_bkgd); 
     897        // _nc_synchook(win); 
     898 
    839899        return OK; 
    840900}