Changeset 3583 for libcaca


Ignore:
Timestamp:
Jul 26, 2009, 9:17:35 PM (10 years ago)
Author:
Sam Hocevar
Message:

Allow to temporarily disable dirty rectangle handling. This allows for huge
speedups when the calling application knows the dirty rectangle covered by
a complex operation.

Location:
libcaca/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/attr.c

    r3494 r3583  
    157157    }
    158158
    159     caca_add_dirty_rect(cv, xmin, y, xmax - xmin + 1, 1);
     159    if(!cv->dirty_disabled)
     160        caca_add_dirty_rect(cv, xmin, y, xmax - xmin + 1, 1);
    160161
    161162    return 0;
  • libcaca/trunk/caca/caca.h

    r3495 r3583  
    241241 *  These functions manipulate dirty rectangles for optimised blitting.
    242242 *  @{ */
     243__extern int caca_disable_dirty_rect(caca_canvas_t *);
     244__extern int caca_enable_dirty_rect(caca_canvas_t *);
    243245__extern int caca_get_dirty_rect_count(caca_canvas_t *);
    244246__extern int caca_get_dirty_rect(caca_canvas_t *, int, int *, int *,
  • libcaca/trunk/caca/caca_internals.h

    r3580 r3583  
    6161
    6262    /* Dirty rectangles */
    63     int ndirty;
     63    int ndirty, dirty_disabled;
    6464    struct
    6565    {
  • libcaca/trunk/caca/canvas.c

    r3568 r3583  
    434434        }
    435435
    436         caca_add_dirty_rect(cv, old_width, 0, width - old_width, old_height);
     436        if(!cv->dirty_disabled)
     437            caca_add_dirty_rect(cv, old_width, 0,
     438                                width - old_width, old_height);
    437439    }
    438440    else
     
    475477        }
    476478
    477         caca_add_dirty_rect(cv, 0, old_height, old_width, height - old_height);
     479        if(!cv->dirty_disabled)
     480            caca_add_dirty_rect(cv, 0, old_height,
     481                                old_width, height - old_height);
    478482    }
    479483
    480484    /* If both width and height are larger, there is a new dirty rectangle
    481485     * that needs to be created in the lower right corner. */
    482     if(width > old_width && height > old_height)
     486    if(!cv->dirty_disabled &&
     487        width > old_width && height > old_height)
    483488        caca_add_dirty_rect(cv, old_width, old_height,
    484489                            width - old_width, height - old_height);
  • libcaca/trunk/caca/dirty.c

    r3580 r3583  
    3636
    3737static void merge_new_rect(caca_canvas_t *cv, int n);
     38
     39/** \brief Disable dirty rectangles.
     40 *
     41 *  Disable dirty rectangle handling for all \e libcaca graphic calls. This
     42 *  is handy when the calling application needs to do slow operations within
     43 *  a known area. Just call caca_add_dirty_rect() afterwards.
     44 *
     45 *  This function is recursive. Dirty rectangles are only reenabled when
     46 *  caca_enable_dirty_rect() is called as many times.
     47 *
     48 *  This function never fails.
     49 *
     50 *  \param cv A libcaca canvas.
     51 *  \return This function always returns 0.
     52 */
     53int caca_disable_dirty_rect(caca_canvas_t *cv)
     54{
     55    cv->dirty_disabled++;
     56
     57    return 0;
     58}
     59
     60/** \brief Enable dirty rectangles.
     61 *
     62 *  This function can only be called after caca_disable_dirty_rect() was
     63 *  called.
     64 *
     65 *  If an error occurs, -1 is returned and \b errno is set accordingly:
     66 *  - \c EINVAL Dirty rectangles were not disabled.
     67 *
     68 *  \param cv A libcaca canvas.
     69 *  \return 0 in case of success, -1 if an error occurred.
     70 */
     71int caca_enable_dirty_rect(caca_canvas_t *cv)
     72{
     73    if(cv->dirty_disabled <= 0)
     74    {
     75        seterrno(EINVAL);
     76        return -1;
     77    }
     78
     79    cv->dirty_disabled--;
     80
     81    return 0;
     82}
    3883
    3984/** \brief Get the number of dirty rectangles in the canvas.
  • libcaca/trunk/caca/frame.c

    r3494 r3583  
    7373    _caca_load_frame_info(cv);
    7474
    75     caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
     75    if(!cv->dirty_disabled)
     76        caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
    7677
    7778    return 0;
     
    237238        cv->frame = 0;
    238239        _caca_load_frame_info(cv);
    239         caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
     240        if(!cv->dirty_disabled)
     241            caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
    240242    }
    241243
  • libcaca/trunk/caca/string.c

    r3581 r3583  
    181181     * in the canvas, ie. if CACA_MAGIC_FULLWIDTH lies at illegal places,
    182182     * but it's the caller's responsibility not to corrupt the contents. */
    183     if(curchar[0] != ch || curattr[0] != attr)
     183    if(!cv->dirty_disabled
     184        && (curchar[0] != ch || curattr[0] != attr))
    184185        caca_add_dirty_rect(cv, xmin, y, xmax - xmin + 1, 1);
    185186
     
    328329    }
    329330
    330     caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
     331    if(!cv->dirty_disabled)
     332        caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
    331333
    332334    return 0;
     
    454456                    dst->chars[dstix + i] = src->chars[srcix + i];
    455457                    dst->attrs[dstix + i] = src->attrs[srcix + i];
    456                     caca_add_dirty_rect(dst, x + starti + i, y + j, 1, 1);
     458                    if(!dst->dirty_disabled)
     459                        caca_add_dirty_rect(dst, x + starti + i, y + j, 1, 1);
    457460                }
    458461            }
     
    466469                memcpy(dst->chars + dstix, src->chars + srcix, stride * 4);
    467470                memcpy(dst->attrs + dstix, src->attrs + srcix, stride * 4);
    468                 caca_add_dirty_rect(dst, x + starti, y + j, stride, 1);
     471                if(!dst->dirty_disabled)
     472                    caca_add_dirty_rect(dst, x + starti, y + j, stride, 1);
    469473            }
    470474        }
     
    543547
    544548    /* FIXME: this may be optimised somewhat */
    545     caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
     549    if(!cv->dirty_disabled)
     550        caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
    546551
    547552    return 0;
  • libcaca/trunk/caca/transform.c

    r3542 r3583  
    5555    }
    5656
    57     caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
     57    if(!cv->dirty_disabled)
     58        caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
    5859
    5960    return 0;
     
    116117    }
    117118
    118     caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
     119    if(!cv->dirty_disabled)
     120        caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
    119121
    120122    return 0;
     
    163165    }
    164166
    165     caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
     167    if(!cv->dirty_disabled)
     168        caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
    166169
    167170    return 0;
     
    222225    }
    223226
    224     caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
     227    if(!cv->dirty_disabled)
     228        caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
    225229
    226230    return 0;
     
    341345    _caca_load_frame_info(cv);
    342346
    343     caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
     347    if(!cv->dirty_disabled)
     348        caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
    344349
    345350    return 0;
     
    460465    _caca_load_frame_info(cv);
    461466
    462     caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
     467    if(!cv->dirty_disabled)
     468        caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
    463469
    464470    return 0;
  • libcaca/trunk/tests/.gitignore

    r2824 r3583  
     1bench
     2caca-test
    13simple
    2 caca-test
  • libcaca/trunk/tests/bench.c

    r3582 r3583  
    4848}
    4949
    50 static void putchars(void)
     50static void putchars(int optim)
    5151{
    5252    caca_canvas_t *cv;
    5353    int i;
    5454    cv = caca_create_canvas(40, 40);
     55    if(optim)
     56        caca_disable_dirty_rect(cv);
    5557    for (i = 0; i < PUTCHAR_LOOPS; i++)
    5658    {
    5759        caca_put_char(cv, 1, 1, 'x');
    5860        caca_put_char(cv, 1, 1, 'o');
     61    }
     62    if(optim)
     63    {
     64        caca_enable_dirty_rect(cv);
     65        caca_add_dirty_rect(cv, 1, 1, 1, 1);
    5966    }
    6067    caca_free_canvas(cv);
     
    6774    TIME("blit mask, no clear", blit(1, 0));
    6875    TIME("blit mask, clear", blit(1, 1));
    69     TIME("putchars", putchars());
     76    TIME("putchars, no optim", putchars(0));
     77    TIME("putchars, optim", putchars(1));
    7078    return 0;
    7179}
Note: See TracChangeset for help on using the changeset viewer.