Ignore:
Timestamp:
05/19/09 02:51:47 (4 years ago)
Author:
sam
Message:

Change the dirty rectangle API so that it can handle several rectangles. The
inner implementation still only handles one dirty rectangle, but this way
we can prepare supporting applictions for the future.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/driver/x11.c

    r3468 r3470  
    294294    int width = caca_get_canvas_width(dp->cv); 
    295295    int height = caca_get_canvas_height(dp->cv); 
    296     int x, y, len; 
    297     int xmin, ymin, xmax, ymax; 
    298  
    299     caca_get_dirty_rectangle(dp->cv, &xmin, &ymin, &xmax, &ymax); 
    300     if(xmin > xmax || ymin > ymax) 
    301         return; 
    302  
    303     /* First draw the background colours. Splitting the process in two 
    304      * loops like this is actually slightly faster. */ 
    305     for(y = ymin; y <= ymax; y++) 
    306     { 
    307         for(x = xmin; x <= xmax; x += len) 
    308         { 
    309             uint32_t const *attrs = cvattrs + x + y * width; 
    310             uint16_t bg = caca_attr_to_rgb12_bg(*attrs); 
    311  
    312             len = 1; 
    313             while(x + len < width 
    314                    && caca_attr_to_rgb12_bg(attrs[len]) == bg) 
    315                 len++; 
    316  
    317             XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, 
    318                            dp->drv.p->colors[bg]); 
    319             XFillRectangle(dp->drv.p->dpy, dp->drv.p->pixmap, dp->drv.p->gc, 
    320                            x * dp->drv.p->font_width, 
    321                            y * dp->drv.p->font_height, 
    322                            len * dp->drv.p->font_width, 
    323                            dp->drv.p->font_height); 
    324         } 
    325     } 
    326  
    327     /* Then print the foreground characters */ 
    328     for(y = ymin; y <= ymax; y++) 
    329     { 
    330         int yoff = (y + 1) * dp->drv.p->font_height 
    331                                     - dp->drv.p->font_offset; 
    332         uint32_t const *chars = cvchars + y * width; 
    333         uint32_t const *attrs = cvattrs + y * width; 
    334  
    335         for(x = xmin; x <= xmax; x++, chars++, attrs++) 
    336         { 
    337             XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, 
     296    int x, y, i, len; 
     297 
     298    for(i = 0; i < caca_get_dirty_rectangle_count(dp->cv); i++) 
     299    { 
     300        int xmin, ymin, xmax, ymax; 
     301 
     302        caca_get_dirty_rectangle(dp->cv, i, &xmin, &ymin, &xmax, &ymax); 
     303 
     304        /* First draw the background colours. Splitting the process in two 
     305         * loops like this is actually slightly faster. */ 
     306        for(y = ymin; y <= ymax; y++) 
     307        { 
     308            for(x = xmin; x <= xmax; x += len) 
     309            { 
     310                uint32_t const *attrs = cvattrs + x + y * width; 
     311                uint16_t bg = caca_attr_to_rgb12_bg(*attrs); 
     312 
     313                len = 1; 
     314                while(x + len < width 
     315                       && caca_attr_to_rgb12_bg(attrs[len]) == bg) 
     316                    len++; 
     317 
     318                XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, 
     319                               dp->drv.p->colors[bg]); 
     320                XFillRectangle(dp->drv.p->dpy, dp->drv.p->pixmap, 
     321                               dp->drv.p->gc, 
     322                               x * dp->drv.p->font_width, 
     323                               y * dp->drv.p->font_height, 
     324                               len * dp->drv.p->font_width, 
     325                               dp->drv.p->font_height); 
     326            } 
     327        } 
     328 
     329        /* Then print the foreground characters */ 
     330        for(y = ymin; y <= ymax; y++) 
     331        { 
     332            int yoff = (y + 1) * dp->drv.p->font_height 
     333                                        - dp->drv.p->font_offset; 
     334            uint32_t const *chars = cvchars + y * width; 
     335            uint32_t const *attrs = cvattrs + y * width; 
     336 
     337            for(x = xmin; x <= xmax; x++, chars++, attrs++) 
     338            { 
     339                XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, 
    338340                           dp->drv.p->colors[caca_attr_to_rgb12_fg(*attrs)]); 
    339341 
    340             x11_put_glyph(dp, x * dp->drv.p->font_width, 
    341                           y * dp->drv.p->font_height, yoff, 
    342                           dp->drv.p->font_width, dp->drv.p->font_height, 
    343                           *attrs, *chars); 
    344         } 
    345     } 
    346  
    347     /* Print the cursor if necessary */ 
     342                x11_put_glyph(dp, x * dp->drv.p->font_width, 
     343                              y * dp->drv.p->font_height, yoff, 
     344                              dp->drv.p->font_width, dp->drv.p->font_height, 
     345                              *attrs, *chars); 
     346            } 
     347        } 
     348    } 
     349 
     350    /* Print the cursor if necessary. FIXME: handle dirty rectangles! */ 
    348351    if(dp->drv.p->cursor_flags) 
    349352    { 
Note: See TracChangeset for help on using the changeset viewer.