Changeset e92aabf in mainline


Ignore:
Timestamp:
2006-06-08T22:44:44Z (18 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bd02038
Parents:
8bd0316
Message:

Fast uspace scrolling using double buffering.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • console/console.c

    r8bd0316 re92aabf  
    473473        /* Synchronize, the gcons can have something in queue */
    474474        async_req(fb_info.phone, FB_FLUSH, 0, NULL);
    475 
     475        /* Enable double buffering */
     476        async_msg_2(fb_info.phone, FB_VIEWPORT_DB, (sysarg_t)-1, 1);
    476477       
    477478        async_req_2(fb_info.phone, FB_GET_CSIZE, 0, 0, &(fb_info.rows), &(fb_info.cols));
  • fb/fb.c

    r8bd0316 re92aabf  
    9595        int cursor_active, cur_col, cur_row;
    9696        int cursor_shown;
     97        /* Double buffering */
     98        __u8 *dbdata;
     99        unsigned int dboffset;
     100        unsigned int paused;
    97101} viewport_t;
    98102
     
    213217        int dx = viewports[vp].x + x;
    214218        int dy = viewports[vp].y + y;
    215         (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)],color);
    216 }
     219
     220        if (! viewports[vp].paused)
     221                (*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)],color);
     222
     223        if (viewports[vp].dbdata) {
     224                int dline = (y + viewports[vp].dboffset) % viewports[vp].height;
     225                int doffset = screen.pixelbytes * (dline * viewports[vp].width + x);
     226                (*screen.rgb2scr)(&viewports[vp].dbdata[doffset],color);
     227        }
     228}
     229
    217230/** Get pixel from viewport */
    218231static int getpixel(int vp, unsigned int x, unsigned int y)
     
    244257                putpixel_mem(tmpline, x, 0, color);
    245258
    246         /* Recompute to screen coords */
    247         sx += viewports[vp].x;
    248         sy += viewports[vp].y;
    249         /* Copy the rest */
    250         for (y = sy;y < sy+height; y++)
    251                 memcpy(&screen.fbaddress[POINTPOS(sx,y)], tmpline,
    252                        screen.pixelbytes * width);
     259        if (!viewports[vp].paused) {
     260                /* Recompute to screen coords */
     261                sx += viewports[vp].x;
     262                sy += viewports[vp].y;
     263                /* Copy the rest */
     264                for (y = sy;y < sy+height; y++)
     265                        memcpy(&screen.fbaddress[POINTPOS(sx,y)], tmpline,
     266                               screen.pixelbytes * width);
     267        }
     268        if (viewports[vp].dbdata) {
     269                for (y=sy;y < sy+height; y++) {
     270                        int rline = (y + viewports[vp].dboffset) % viewports[vp].height;
     271                        int rpos = (rline * viewports[vp].width + sx) * screen.pixelbytes;
     272                        memcpy(&viewports[vp].dbdata[rpos], tmpline, screen.pixelbytes * width);
     273                }
     274        }
    253275
    254276}
     
    262284}
    263285
    264 /** Scroll port up/down
     286/** Scroll unbuffered viewport up/down
    265287 *
    266288 * @param vp Viewport to scroll
    267289 * @param rows Positive number - scroll up, negative - scroll down
    268290 */
    269 static void scroll_port(int vp, int rows)
     291static void scroll_port_nodb(int vp, int lines)
    270292{
    271293        int y;
     
    273295        int endline;
    274296        viewport_t *vport = &viewports[vp];
    275        
    276         if (rows > 0) {
    277                 for (y=vport->y; y < vport->y+vport->height - rows*FONT_SCANLINES; y++)
     297
     298        if (lines > 0) {
     299                for (y=vport->y; y < vport->y+vport->height - lines; y++)
    278300                        memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
    279                                &screen.fbaddress[POINTPOS(vport->x,y + rows*FONT_SCANLINES)],
     301                               &screen.fbaddress[POINTPOS(vport->x,y + lines)],
    280302                               screen.pixelbytes * vport->width);
    281                 draw_rectangle(vp, 0, FONT_SCANLINES*(vport->rows - 1),
    282                                vport->width, FONT_SCANLINES, vport->style.bg_color);
    283         } else if (rows < 0) {
    284                 rows = -rows;
    285                 for (y=vport->y + vport->height-1; y >= vport->y + rows*FONT_SCANLINES; y--)
     303                draw_rectangle(vp, 0, vport->height - lines,
     304                               vport->width, lines, vport->style.bg_color);
     305        } else if (lines < 0) {
     306                lines = -lines;
     307                for (y=vport->y + vport->height-1; y >= vport->y + lines; y--)
    286308                        memcpy(&screen.fbaddress[POINTPOS(vport->x,y)],
    287                                 &screen.fbaddress[POINTPOS(vport->x,y - rows*FONT_SCANLINES)],
    288                                 screen.pixelbytes * vport->width);
    289                 draw_rectangle(vp, 0, 0, vport->width, FONT_SCANLINES, vport->style.bg_color);
    290         }
     309                               &screen.fbaddress[POINTPOS(vport->x,y - lines)],
     310                               screen.pixelbytes * vport->width);
     311                draw_rectangle(vp, 0, 0, vport->width, lines, vport->style.bg_color);
     312        }
     313}
     314
     315/** Refresh given viewport from double buffer */
     316static void refresh_viewport_db(int vp)
     317{
     318        unsigned int y, srcy, srcoff, dsty, dstx;
     319
     320        for (y = 0; y < viewports[vp].height; y++) {
     321                srcy = (y + viewports[vp].dboffset) % viewports[vp].height;
     322                srcoff = (viewports[vp].width * srcy) * screen.pixelbytes;
     323
     324                dstx = viewports[vp].x;
     325                dsty = viewports[vp].y + y;
     326
     327                memcpy(&screen.fbaddress[POINTPOS(dstx,dsty)],
     328                       &viewports[vp].dbdata[srcoff],
     329                       viewports[vp].width*screen.pixelbytes);
     330        }
     331}
     332
     333/** Scroll viewport that has double buffering enabled */
     334static void scroll_port_db(int vp, int lines)
     335{
     336        ++viewports[vp].paused;
     337        if (lines > 0) {
     338                draw_rectangle(vp, 0, 0, viewports[vp].width, lines,
     339                               viewports[vp].style.bg_color);
     340                viewports[vp].dboffset += lines;
     341                viewports[vp].dboffset %= viewports[vp].height;
     342        } else if (lines < 0) {
     343                lines = -lines;
     344                draw_rectangle(vp, 0, viewports[vp].height-lines,
     345                               viewports[vp].width, lines,
     346                               viewports[vp].style.bg_color);
     347
     348                if (viewports[vp].dboffset < lines)
     349                        viewports[vp].dboffset += viewports[vp].height;
     350                viewports[vp].dboffset -= lines;
     351        }
     352       
     353        --viewports[vp].paused;
     354       
     355        refresh_viewport_db(vp);
     356       
     357}
     358
     359/** Scrolls viewport given number of lines */
     360static void scroll_port(int vp, int lines)
     361{
     362        if (viewports[vp].dbdata)
     363                scroll_port_db(vp, lines);
     364        else
     365                scroll_port_nodb(vp, lines);
     366       
    291367}
    292368
     
    9861062                        }
    9871063                        cursor_hide(vp);
    988                         scroll_port(vp, i);
     1064                        scroll_port(vp, i*FONT_SCANLINES);
    9891065                        cursor_print(vp);
     1066                        retval = 0;
     1067                        break;
     1068                case FB_VIEWPORT_DB:
     1069                        /* Enable double buffering */
     1070                        i = IPC_GET_ARG1(call);
     1071                        if (i == -1)
     1072                                i = vp;
     1073                        if (i < 0 || i >= MAX_VIEWPORTS) {
     1074                                retval = EINVAL;
     1075                                break;
     1076                        }
     1077                        if (! viewports[i].initialized ) {
     1078                                while (1)
     1079                                        ;
     1080                                retval = EADDRNOTAVAIL;
     1081                                break;
     1082                        }
     1083                        viewports[i].dboffset = 0;
     1084                        if (IPC_GET_ARG2(call) == 1 && !viewports[i].dbdata)
     1085                                viewports[i].dbdata = malloc(screen.pixelbytes*viewports[i].width * viewports[i].height);
     1086                        else if (IPC_GET_ARG2(call) == 0 && viewports[i].dbdata) {
     1087                                free(viewports[i].dbdata);
     1088                                viewports[i].dbdata = NULL;
     1089                        }
    9901090                        retval = 0;
    9911091                        break;
     
    10231123                        }
    10241124                        viewports[i].initialized = 0;
     1125                        if (viewports[i].dbdata) {
     1126                                free(viewports[i].dbdata);
     1127                                viewports[i].dbdata = NULL;
     1128                        }
    10251129                        retval = 0;
    10261130                        break;
  • libc/include/ipc/fb.h

    r8bd0316 re92aabf  
    5252#define FB_DRAW_TEXT_DATA    1036
    5353#define FB_FLUSH             1037
     54#define FB_VIEWPORT_DB       1038
    5455
    55 #define FB_DRAW_PPM          1038
    56 #define FB_PREPARE_SHM       1039
    57 #define FB_DROP_SHM          1040
    58 #define FB_SHM2PIXMAP        1041
     56#define FB_DRAW_PPM          1100
     57#define FB_PREPARE_SHM       1101
     58#define FB_DROP_SHM          1102
     59#define FB_SHM2PIXMAP        1103
    5960
    60 #define FB_VP_DRAW_PIXMAP    1042
    61 #define FB_VP2PIXMAP         1043
    62 #define FB_DROP_PIXMAP       1044
     61#define FB_VP_DRAW_PIXMAP    1104
     62#define FB_VP2PIXMAP         1105
     63#define FB_DROP_PIXMAP       1106
     64#define FB_TRANS_PUTCHAR     1107
    6365
    64 #define FB_TRANS_PUTCHAR     1045
    65 
    66 #define FB_ANIM_CREATE       1046
    67 #define FB_ANIM_DROP         1047
    68 #define FB_ANIM_ADDPIXMAP    1048
    69 #define FB_ANIM_CHGVP        1049
    70 #define FB_ANIM_START        1050
    71 #define FB_ANIM_STOP         1051
     66#define FB_ANIM_CREATE       1200
     67#define FB_ANIM_DROP         1201
     68#define FB_ANIM_ADDPIXMAP    1202
     69#define FB_ANIM_CHGVP        1203
     70#define FB_ANIM_START        1204
     71#define FB_ANIM_STOP         1205
    7272
    7373#endif
Note: See TracChangeset for help on using the changeset viewer.