Changeset 3471 for libcaca/trunk


Ignore:
Timestamp:
May 19, 2009, 2:51:55 AM (11 years ago)
Author:
Sam Hocevar
Message:

Optimise the dirty rectangle handling by keeping track of the number of
currently dirty rectangles.

Location:
libcaca/trunk/caca
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/caca_internals.h

    r3448 r3471  
    5959    void *resize_data;
    6060
    61     /* Dirty rectangle */
     61    /* Dirty rectangles */
     62    int ndirty;
    6263    int dirty_xmin, dirty_xmax, dirty_ymin, dirty_ymax;
    6364
  • libcaca/trunk/caca/canvas.c

    r3470 r3471  
    9494    caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
    9595
    96     cv->dirty_xmin = 0;
    97     cv->dirty_xmax = -1;
    98     cv->dirty_ymin = 0;
    99     cv->dirty_ymax = -1;
    100 
     96    cv->ndirty = 0;
    10197    cv->ff = NULL;
    10298
  • libcaca/trunk/caca/dirty.c

    r3470 r3471  
    4444int caca_get_dirty_rectangle_count(caca_canvas_t *cv)
    4545{
    46     /* Ignore empty rectangles. */
    47     if(cv->dirty_xmin > cv->dirty_xmax || cv->dirty_ymin > cv->dirty_ymax)
    48         return 0;
    49 
    50     /* Ignore out-of-bounds rectangles. */
    51     if(cv->dirty_xmax < 0 || cv->dirty_xmin >= cv->width
    52         || cv->dirty_ymax < 0 || cv->dirty_ymin >= cv->height)
    53         return 0;
    54 
    55     return 1;
     46    return cv->ndirty;
    5647}
    5748
     
    8172                             int *xmin, int *ymin, int *xmax, int *ymax)
    8273{
    83     /* For now, index can only be zero, and if the dirty rectangle is
    84      * empty, we don't return anything. */
    85     if(index < 0 || index > 0
    86         || cv->dirty_xmin > cv->dirty_xmax || cv->dirty_ymin > cv->dirty_ymax
    87         || cv->dirty_xmax < 0 || cv->dirty_xmin >= cv->width
    88         || cv->dirty_ymax < 0 || cv->dirty_ymin >= cv->height)
     74    if(index < 0 || index >= cv->ndirty)
    8975    {
    9076        seterrno(EINVAL);
     
    144130    }
    145131
    146     if(xmin < cv->dirty_xmin)
     132    if(cv->ndirty == 0)
     133    {
     134        cv->ndirty = 1;
    147135        cv->dirty_xmin = xmin;
    148 
    149     if(xmax > cv->dirty_xmax)
    150136        cv->dirty_xmax = xmax;
    151 
    152     if(ymin < cv->dirty_ymin)
    153137        cv->dirty_ymin = ymin;
    154 
    155     if(ymax > cv->dirty_ymax)
    156138        cv->dirty_ymax = ymax;
     139    }
     140    else
     141    {
     142        if(xmin < cv->dirty_xmin)
     143            cv->dirty_xmin = xmin;
     144        if(xmax > cv->dirty_xmax)
     145            cv->dirty_xmax = xmax;
     146        if(ymin < cv->dirty_ymin)
     147            cv->dirty_ymin = ymin;
     148        if(ymax > cv->dirty_ymax)
     149            cv->dirty_ymax = ymax;
     150    }
    157151
    158152    return 0;
     
    206200int caca_clear_dirty_rectangle_list(caca_canvas_t *cv)
    207201{
    208     cv->dirty_xmin = cv->width;
    209     cv->dirty_xmax = -1;
    210     cv->dirty_ymin = cv->height;
    211     cv->dirty_ymax = -1;
    212 
    213     return 0;
    214 }
    215 
     202    cv->ndirty = 0;
     203
     204    return 0;
     205}
     206
Note: See TracChangeset for help on using the changeset viewer.