Ignore:
Timestamp:
May 19, 2009, 2:51:47 AM (11 years ago)
Author:
Sam Hocevar
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/canvas.c

    r3450 r3470  
    297297{
    298298    return (uint8_t const *)cv->attrs;
    299 }
    300 
    301 /** \brief Get a canvas's dirty rectangle.
    302  *
    303  *  Get the canvas's dirty rectangle coordinates. The dirty rectangle is
    304  *  the smallest area containing all the cells that have changed since it
    305  *  was last reset.
    306  *
    307  *  The dirty rectangle is used internally by display drivers to optimise
    308  *  rendering by avoiding to redraw the whole screen. Once the display driver
    309  *  has rendered the canvas, it resets the dirty rectangle.
    310  *
    311  *  Values such that \b xmin > \b xmax or \b ymin > \b ymax indicate that
    312  *  the dirty rectangle is empty. It means that the canvas's contents have
    313  *  not changed since the dirty rectangle was last reset.
    314  *
    315  *  FIXME: having only one dirty rectangle instead of a list of rectangles
    316  *  is a severe limitation, but the potential gain does not yet look to be
    317  *  worth the implementation complexity of a multiple-rectangle scheme.
    318  *
    319  *  This function never fails.
    320  *
    321  *  \param cv A libcaca canvas.
    322  *  \param xmin A pointer to an integer where the leftmost edge of the
    323  *              dirty rectangle will be stored.
    324  *  \param ymin A pointer to an integer where the topmost edge of the
    325  *              dirty rectangle will be stored.
    326  *  \param xmax A pointer to an integer where the rightmost edge of the
    327  *              dirty rectangle will be stored.
    328  *  \param ymax A pointer to an integer where the bottommost edge of the
    329  *              dirty rectangle will be stored.
    330  *  \return This function always returns 0.
    331  */
    332 int caca_get_dirty_rectangle(caca_canvas_t *cv, int *xmin, int *ymin,
    333                              int *xmax, int *ymax)
    334 {
    335     *xmin = cv->dirty_xmin;
    336     *xmax = cv->dirty_xmax;
    337     *ymin = cv->dirty_ymin;
    338     *ymax = cv->dirty_ymax;
    339 
    340     return 0;
    341 }
    342 
    343 /** \brief Add a dirty rectangle to the canvas's dirty rectangle.
    344  *
    345  *  Add an invalidating zone to the canvas's dirty rectangle. For more
    346  *  information about the dirty rectangle, see caca_get_dirty_rectangle().
    347  *
    348  *  This function may be useful to force refresh of a given zone of the
    349  *  canvas even if the dirty rectangle tracking indicates that it is
    350  *  unchanged.
    351  *
    352  *  Values such that \b xmin > \b xmax or \b ymin > \b ymax indicate that
    353  *  the dirty rectangle is empty. They will be silently ignored.
    354  *
    355  *  This function never fails.
    356  *
    357  *  \param cv A libcaca canvas.
    358  *  \param xmin The leftmost edge of the additional dirty rectangle.
    359  *  \param ymin The topmost edge of the additional dirty rectangle.
    360  *  \param xmax The rightmost edge of the additional dirty rectangle.
    361  *  \param ymax The bottommost edge of the additional dirty rectangle.
    362  *  \return This function always returns 0.
    363  */
    364 int caca_add_dirty_rectangle(caca_canvas_t *cv, int xmin, int ymin,
    365                              int xmax, int ymax)
    366 {
    367     /* Ignore empty rectangles. */
    368     if(xmin > xmax || ymin > ymax)
    369         return 0;
    370 
    371     /* Ignore out-of-bounds rectangles. */
    372     if(xmax < 0 || xmin >= cv->width || ymax < 0 || ymin >= cv->height)
    373         return 0;
    374 
    375     if(xmin < cv->dirty_xmin)
    376         cv->dirty_xmin = xmin;
    377 
    378     if(xmax > cv->dirty_xmax)
    379         cv->dirty_xmax = xmax;
    380 
    381     if(ymin < cv->dirty_ymin)
    382         cv->dirty_ymin = ymin;
    383 
    384     if(ymax > cv->dirty_ymax)
    385         cv->dirty_ymax = ymax;
    386 
    387     return 0;
    388 }
    389 
    390 /** \brief Set a canvas's dirty rectangle.
    391  *
    392  *  Set the canvas's dirty rectangle coordinates. For more information
    393  *  about the dirty rectangle, see caca_get_dirty_rectangle().
    394  *
    395  *  Values such that \b xmin > \b xmax or \b ymin > \b ymax indicate that
    396  *  the dirty rectangle is empty.
    397  *
    398  *  This function never fails.
    399  *
    400  *  \param cv A libcaca canvas.
    401  *  \param xmin The leftmost edge of the desired dirty rectangle.
    402  *  \param ymin The topmost edge of the desired dirty rectangle.
    403  *  \param xmax The rightmost edge of the desired dirty rectangle.
    404  *  \param ymax The bottommost edge of the desired dirty rectangle.
    405  *  \return This function always returns 0.
    406  */
    407 int caca_set_dirty_rectangle(caca_canvas_t *cv, int xmin, int ymin,
    408                              int xmax, int ymax)
    409 {
    410     /* Normalise values indicating an empty or out-of-bounds rectangle. */
    411     if(xmin > xmax || ymin > ymax ||
    412         xmax < 0 || xmin >= cv->width || ymax < 0 || ymin >= cv->height)
    413     {
    414         xmin = cv->width;
    415         xmax = -1;
    416         ymin = cv->height;
    417         ymax = -1;
    418     }
    419 
    420     cv->dirty_xmin = xmin;
    421     cv->dirty_xmax = xmax;
    422     cv->dirty_ymin = ymin;
    423     cv->dirty_ymax = ymax;
    424 
    425     return 0;
    426299}
    427300
Note: See TracChangeset for help on using the changeset viewer.