Browse Source

Change the dirty rectangle API once again so that calling applications get

a more natural (x,y,w,h) 4-tuple to handle.
tags/v0.99.beta17
Sam Hocevar sam 15 years ago
parent
commit
ea99175a2f
13 changed files with 178 additions and 177 deletions
  1. +2
    -2
      caca/attr.c
  2. +8
    -8
      caca/caca.h
  3. +5
    -5
      caca/canvas.c
  4. +47
    -47
      caca/dirty.c
  5. +10
    -10
      caca/driver/ncurses.c
  6. +11
    -11
      caca/driver/slang.c
  7. +11
    -11
      caca/driver/vga.c
  8. +10
    -10
      caca/driver/x11.c
  9. +3
    -3
      caca/frame.c
  10. +2
    -2
      caca/graphics.c
  11. +7
    -6
      caca/string.c
  12. +9
    -9
      caca/transform.c
  13. +53
    -53
      tests/dirty.cpp

+ 2
- 2
caca/attr.c View File

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -156,7 +156,7 @@ int caca_put_attr(caca_canvas_t *cv, int x, int y, uint32_t attr)
xmax++; xmax++;
} }


caca_add_dirty_rectangle(cv, xmin, y, xmax, y);
caca_add_dirty_rect(cv, xmin, y, xmax - xmin + 1, 1);


return 0; return 0;
} }


+ 8
- 8
caca/caca.h View File

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -14,7 +14,7 @@


/** \file caca.h /** \file caca.h
* \version \$Id$ * \version \$Id$
* \author Sam Hocevar <sam@zoy.org>
* \author Sam Hocevar <sam@hocevar.net>
* \brief The \e libcaca public header. * \brief The \e libcaca public header.
* *
* This header contains the public types and functions that applications * This header contains the public types and functions that applications
@@ -240,12 +240,12 @@ __extern int caca_set_canvas_boundaries(caca_canvas_t *, int, int, int, int);
* *
* These functions manipulate dirty rectangles for optimised blitting. * These functions manipulate dirty rectangles for optimised blitting.
* @{ */ * @{ */
__extern int caca_get_dirty_rectangle_count(caca_canvas_t *);
__extern int caca_get_dirty_rectangle(caca_canvas_t *, int, int *, int *,
int *, int *);
__extern int caca_add_dirty_rectangle(caca_canvas_t *, int, int, int, int);
__extern int caca_remove_dirty_rectangle(caca_canvas_t *, int, int, int, int);
__extern int caca_clear_dirty_rectangle_list(caca_canvas_t *);
__extern int caca_get_dirty_rect_count(caca_canvas_t *);
__extern int caca_get_dirty_rect(caca_canvas_t *, int, int *, int *,
int *, int *);
__extern int caca_add_dirty_rect(caca_canvas_t *, int, int, int, int);
__extern int caca_remove_dirty_rect(caca_canvas_t *, int, int, int, int);
__extern int caca_clear_dirty_rect_list(caca_canvas_t *);
/* @} */ /* @} */


/** \defgroup caca_transform libcaca canvas transformation /** \defgroup caca_transform libcaca canvas transformation


+ 5
- 5
caca/canvas.c View File

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -426,7 +426,7 @@ int caca_resize(caca_canvas_t *cv, int width, int height)
} }
} }


caca_add_dirty_rectangle(cv, old_width, 0, width - 1, old_height - 1);
caca_add_dirty_rect(cv, old_width, 0, width - old_width, old_height);
} }
else else
{ {
@@ -467,15 +467,15 @@ int caca_resize(caca_canvas_t *cv, int width, int height)
} }
} }


caca_add_dirty_rectangle(cv, 0, old_height, old_width - 1, height - 1);
caca_add_dirty_rect(cv, 0, old_height, old_width, height - old_height);
} }


/* XXX: technically we should not worry about the dirty rectangle in /* XXX: technically we should not worry about the dirty rectangle in
* the bottom-right corner, because we only handle one dirty rectangle, * the bottom-right corner, because we only handle one dirty rectangle,
* but in case the API changes later, we make sure this is handled. */ * but in case the API changes later, we make sure this is handled. */
if(width > old_width && height > old_height) if(width > old_width && height > old_height)
caca_add_dirty_rectangle(cv, old_width, old_height,
width - 1, height - 1);
caca_add_dirty_rect(cv, old_width, old_height,
width - old_width, height - old_height);


/* Step 4: if new area is smaller, resize memory area now. */ /* Step 4: if new area is smaller, resize memory area now. */
if(new_size < old_size) if(new_size < old_size)


+ 47
- 47
caca/dirty.c View File

@@ -41,7 +41,7 @@
* \param cv A libcaca canvas. * \param cv A libcaca canvas.
* \return The number of dirty rectangles in the given canvas. * \return The number of dirty rectangles in the given canvas.
*/ */
int caca_get_dirty_rectangle_count(caca_canvas_t *cv)
int caca_get_dirty_rect_count(caca_canvas_t *cv)
{ {
return cv->ndirty; return cv->ndirty;
} }
@@ -49,7 +49,7 @@ int caca_get_dirty_rectangle_count(caca_canvas_t *cv)
/** \brief Get a canvas's dirty rectangle. /** \brief Get a canvas's dirty rectangle.
* *
* Get the canvas's given dirty rectangle coordinates. The index must be * Get the canvas's given dirty rectangle coordinates. The index must be
* within the dirty rectangle count. See caca_get_dirty_rectangle_count()
* within the dirty rectangle count. See caca_get_dirty_rect_count()
* for how to compute this count. * for how to compute this count.
* *
* If an error occurs, no coordinates are written in the pointer arguments, * If an error occurs, no coordinates are written in the pointer arguments,
@@ -58,18 +58,18 @@ int caca_get_dirty_rectangle_count(caca_canvas_t *cv)
* *
* \param cv A libcaca canvas. * \param cv A libcaca canvas.
* \param r The requested rectangle index. * \param r The requested rectangle index.
* \param xmin A pointer to an integer where the leftmost edge of the
* dirty rectangle will be stored.
* \param ymin A pointer to an integer where the topmost edge of the
* dirty rectangle will be stored.
* \param xmax A pointer to an integer where the rightmost edge of the
* dirty rectangle will be stored.
* \param ymax A pointer to an integer where the bottommost edge of the
* dirty rectangle will be stored.
* \param x A pointer to an integer where the leftmost edge of the
* dirty rectangle will be stored.
* \param y A pointer to an integer where the topmost edge of the
* dirty rectangle will be stored.
* \param width A pointer to an integer where the width of the
* dirty rectangle will be stored.
* \param height A pointer to an integer where the height of the
* dirty rectangle will be stored.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int caca_get_dirty_rectangle(caca_canvas_t *cv, int r,
int *xmin, int *ymin, int *xmax, int *ymax)
int caca_get_dirty_rect(caca_canvas_t *cv, int r,
int *x, int *y, int *width, int *height)
{ {
if(r < 0 || r >= cv->ndirty) if(r < 0 || r >= cv->ndirty)
{ {
@@ -90,10 +90,10 @@ int caca_get_dirty_rectangle(caca_canvas_t *cv, int r,
if(cv->dirty_ymax > cv->height - 1) if(cv->dirty_ymax > cv->height - 1)
cv->dirty_ymax = cv->height - 1; cv->dirty_ymax = cv->height - 1;


*xmin = cv->dirty_xmin;
*xmax = cv->dirty_xmax;
*ymin = cv->dirty_ymin;
*ymax = cv->dirty_ymax;
*x = cv->dirty_xmin;
*y = cv->dirty_ymin;
*width = cv->dirty_xmax - cv->dirty_xmin + 1;
*height = cv->dirty_ymax - cv->dirty_ymin + 1;


return 0; return 0;
} }
@@ -101,7 +101,7 @@ int caca_get_dirty_rectangle(caca_canvas_t *cv, int r,
/** \brief Add an area to the canvas's dirty rectangle list. /** \brief Add an area to the canvas's dirty rectangle list.
* *
* Add an invalidating zone to the canvas's dirty rectangle list. For more * Add an invalidating zone to the canvas's dirty rectangle list. For more
* information about the dirty rectangles, see caca_get_dirty_rectangle().
* information about the dirty rectangles, see caca_get_dirty_rect().
* *
* This function may be useful to force refresh of a given zone of the * This function may be useful to force refresh of a given zone of the
* canvas even if the dirty rectangle tracking indicates that it is * canvas even if the dirty rectangle tracking indicates that it is
@@ -112,18 +112,18 @@ int caca_get_dirty_rectangle(caca_canvas_t *cv, int r,
* - \c EINVAL Specified rectangle coordinates are out of bounds. * - \c EINVAL Specified rectangle coordinates are out of bounds.
* *
* \param cv A libcaca canvas. * \param cv A libcaca canvas.
* \param xmin The leftmost edge of the additional dirty rectangle.
* \param ymin The topmost edge of the additional dirty rectangle.
* \param xmax The rightmost edge of the additional dirty rectangle.
* \param ymax The bottommost edge of the additional dirty rectangle.
* \param x The leftmost edge of the additional dirty rectangle.
* \param y The topmost edge of the additional dirty rectangle.
* \param width The width of the additional dirty rectangle.
* \param height The height of the additional dirty rectangle.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int caca_add_dirty_rectangle(caca_canvas_t *cv, int xmin, int ymin,
int xmax, int ymax)
int caca_add_dirty_rect(caca_canvas_t *cv, int x, int y,
int width, int height)
{ {
/* Ignore empty and out-of-bounds rectangles */ /* Ignore empty and out-of-bounds rectangles */
if(xmin > xmax || ymin > ymax
|| xmax < 0 || xmin >= cv->width || ymax < 0 || ymin >= cv->height)
if(width <= 0 || height <= 0 || x + width <= 0 || x >= cv->width
|| y + height <= 0 || y >= cv->height)
{ {
seterrno(EINVAL); seterrno(EINVAL);
return -1; return -1;
@@ -132,21 +132,21 @@ int caca_add_dirty_rectangle(caca_canvas_t *cv, int xmin, int ymin,
if(cv->ndirty == 0) if(cv->ndirty == 0)
{ {
cv->ndirty = 1; cv->ndirty = 1;
cv->dirty_xmin = xmin;
cv->dirty_xmax = xmax;
cv->dirty_ymin = ymin;
cv->dirty_ymax = ymax;
cv->dirty_xmin = x;
cv->dirty_xmax = x + width - 1;
cv->dirty_ymin = y;
cv->dirty_ymax = y + height - 1;
} }
else else
{ {
if(xmin < cv->dirty_xmin)
cv->dirty_xmin = xmin;
if(xmax > cv->dirty_xmax)
cv->dirty_xmax = xmax;
if(ymin < cv->dirty_ymin)
cv->dirty_ymin = ymin;
if(ymax > cv->dirty_ymax)
cv->dirty_ymax = ymax;
if(x < cv->dirty_xmin)
cv->dirty_xmin = x;
if(x + width - 1 > cv->dirty_xmax)
cv->dirty_xmax = x + width - 1;
if(y < cv->dirty_ymin)
cv->dirty_ymin = y;
if(y + height - 1 > cv->dirty_ymax)
cv->dirty_ymax = y + height - 1;
} }


return 0; return 0;
@@ -155,7 +155,7 @@ int caca_add_dirty_rectangle(caca_canvas_t *cv, int xmin, int ymin,
/** \brief Remove an area from the dirty rectangle list. /** \brief Remove an area from the dirty rectangle list.
* *
* Mark a cell area in the canvas as not dirty. For more information about * Mark a cell area in the canvas as not dirty. For more information about
* the dirty rectangles, see caca_get_dirty_rectangle().
* the dirty rectangles, see caca_get_dirty_rect().
* *
* Values such that \b xmin > \b xmax or \b ymin > \b ymax indicate that * Values such that \b xmin > \b xmax or \b ymin > \b ymax indicate that
* the dirty rectangle is empty. They will be silently ignored. * the dirty rectangle is empty. They will be silently ignored.
@@ -164,18 +164,18 @@ int caca_add_dirty_rectangle(caca_canvas_t *cv, int xmin, int ymin,
* - \c EINVAL Specified rectangle coordinates are out of bounds. * - \c EINVAL Specified rectangle coordinates are out of bounds.
* *
* \param cv A libcaca canvas. * \param cv A libcaca canvas.
* \param xmin The leftmost edge of the clean rectangle.
* \param ymin The topmost edge of the clean rectangle.
* \param xmax The rightmost edge of the clean rectangle.
* \param ymax The bottommost edge of the clean rectangle.
* \param x The leftmost edge of the clean rectangle.
* \param y The topmost edge of the clean rectangle.
* \param width The width of the clean rectangle.
* \param height The height of the clean rectangle.
* \return 0 in case of success, -1 if an error occurred. * \return 0 in case of success, -1 if an error occurred.
*/ */
int caca_remove_dirty_rectangle(caca_canvas_t *cv, int xmin, int ymin,
int xmax, int ymax)
int caca_remove_dirty_rect(caca_canvas_t *cv, int x, int y,
int width, int height)
{ {
/* Ignore empty and out-of-bounds rectangles */ /* Ignore empty and out-of-bounds rectangles */
if(xmin > xmax || ymin > ymax
|| xmax < 0 || xmin >= cv->width || ymax < 0 || ymin >= cv->height)
if(width <= 0 || height <= 0 || x + width <= 0 || x >= cv->width
|| y + height <= 0 || y >= cv->height)
{ {
seterrno(EINVAL); seterrno(EINVAL);
return -1; return -1;
@@ -197,7 +197,7 @@ int caca_remove_dirty_rectangle(caca_canvas_t *cv, int xmin, int ymin,
* \param cv A libcaca canvas. * \param cv A libcaca canvas.
* \return This function always returns 0. * \return This function always returns 0.
*/ */
int caca_clear_dirty_rectangle_list(caca_canvas_t *cv)
int caca_clear_dirty_rect_list(caca_canvas_t *cv)
{ {
cv->ndirty = 0; cv->ndirty = 0;




+ 10
- 10
caca/driver/ncurses.c View File

@@ -347,29 +347,29 @@ static void ncurses_display(caca_display_t *dp)
{ {
int x, y, i; int x, y, i;


for(i = 0; i < caca_get_dirty_rectangle_count(dp->cv); i++)
for(i = 0; i < caca_get_dirty_rect_count(dp->cv); i++)
{ {
uint32_t const *cvchars, *cvattrs; uint32_t const *cvchars, *cvattrs;
int xmin, ymin, xmax, ymax;
int dx, dy, dw, dh;


caca_get_dirty_rectangle(dp->cv, i, &xmin, &ymin, &xmax, &ymax);
caca_get_dirty_rect(dp->cv, i, &dx, &dy, &dw, &dh);


cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv) cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv)
+ xmin + ymin * dp->cv->width;
+ dx + dy * dp->cv->width;
cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv) cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv)
+ xmin + ymin * dp->cv->width;
+ dx + dy * dp->cv->width;


for(y = ymin; y <= ymax; y++)
for(y = dy; y < dy + dh; y++)
{ {
move(y, xmin);
for(x = xmin; x <= xmax; x++)
move(y, dx);
for(x = dx; x < dx + dw; x++)
{ {
attrset(dp->drv.p->attr[caca_attr_to_ansi(*cvattrs++)]); attrset(dp->drv.p->attr[caca_attr_to_ansi(*cvattrs++)]);
ncurses_write_utf32(*cvchars++); ncurses_write_utf32(*cvchars++);
} }


cvchars += dp->cv->width - (xmax - xmin) - 1;
cvattrs += dp->cv->width - (xmax - xmin) - 1;
cvchars += dp->cv->width - dw;
cvattrs += dp->cv->width - dw;
} }
} }




+ 11
- 11
caca/driver/slang.c View File

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -222,22 +222,22 @@ static void slang_display(caca_display_t *dp)
{ {
int x, y, i; int x, y, i;


for(i = 0; i < caca_get_dirty_rectangle_count(dp->cv); i++)
for(i = 0; i < caca_get_dirty_rect_count(dp->cv); i++)
{ {
uint32_t const *cvchars, *cvattrs; uint32_t const *cvchars, *cvattrs;
int xmin, ymin, xmax, ymax;
int dx, dy, dw, dh;


caca_get_dirty_rectangle(dp->cv, i, &xmin, &ymin, &xmax, &ymax);
caca_get_dirty_rect(dp->cv, i, &dx, &dy, &dw, &dh);


cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv) cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv)
+ xmin + ymin * dp->cv->width;
+ dx + dy * dp->cv->width;
cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv) cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv)
+ xmin + ymin * dp->cv->width;
+ dx + dy * dp->cv->width;


for(y = ymin; y <= ymax; y++)
for(y = dy; y < dy + dh; y++)
{ {
SLsmg_gotorc(y, xmin);
for(x = xmin; x <= xmax; x++)
SLsmg_gotorc(y, dx);
for(x = dx; x < dx + dw; x++)
{ {
uint32_t ch = *cvchars++; uint32_t ch = *cvchars++;


@@ -282,8 +282,8 @@ static void slang_display(caca_display_t *dp)
#endif #endif
} }


cvchars += dp->cv->width - (xmax - xmin) - 1;
cvattrs += dp->cv->width - (xmax - xmin) - 1;
cvchars += dp->cv->width - dw;
cvattrs += dp->cv->width - dw;
} }
} }
SLsmg_gotorc(caca_get_cursor_y(dp->cv), caca_get_cursor_x(dp->cv)); SLsmg_gotorc(caca_get_cursor_y(dp->cv), caca_get_cursor_x(dp->cv));


+ 11
- 11
caca/driver/vga.c View File

@@ -120,23 +120,23 @@ static void vga_display(caca_display_t *dp)
{ {
char *screen = (char *)(intptr_t)0x000b8000; char *screen = (char *)(intptr_t)0x000b8000;
uint32_t const *cvchars, *cvattrs; uint32_t const *cvchars, *cvattrs;
int xmin, ymin, xmax, ymax;
int dx, dy, dw, dh;


caca_get_dirty_rectangle(dp->cv, i, &xmin, &ymin, &xmax, &ymax);
caca_get_dirty_rect(dp->cv, i, &dx, &dy, &dw, &dh);


cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv) cvchars = (uint32_t const *)caca_get_canvas_chars(dp->cv)
+ xmin + ymin * dp->cv->width;
+ dx + dy * dp->cv->width;
cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv) cvattrs = (uint32_t const *)caca_get_canvas_attrs(dp->cv)
+ xmin + ymin * dp->cv->width;
+ dx + dy * dp->cv->width;


screen += ymin * dp->cv->width + xmin;
screen += dy * dp->cv->width + dx;


for(y = ymin; y <= ymax; y++)
for(y = dy; y < dy + dh; y++)
{ {
for(x = xmin; x <= xmax; x++)
for(x = dx; x < dx + dw; x++)
{ {
char ch = caca_utf32_to_cp437(*cvchars++); char ch = caca_utf32_to_cp437(*cvchars++);
if(x < xmax && *cvchars == CACA_MAGIC_FULLWIDTH)
if(x < dx + dw - 1 && *cvchars == CACA_MAGIC_FULLWIDTH)
{ {
*screen++ = '['; *screen++ = '[';
*screen++ = caca_attr_to_ansi(*cvattrs++); *screen++ = caca_attr_to_ansi(*cvattrs++);
@@ -148,9 +148,9 @@ static void vga_display(caca_display_t *dp)
*screen++ = caca_attr_to_ansi(*cvattrs++); *screen++ = caca_attr_to_ansi(*cvattrs++);
} }


cvchars += dp->cv->width - (xmax - xmin) - 1;
cvattrs += dp->cv->width - (xmax - xmin) - 1;
screen += 2 * (dp->cv->width - (xmax - xmin) - 1);
cvchars += dp->cv->width - dw;
cvattrs += dp->cv->width - dw;
screen += 2 * (dp->cv->width - dw);
} }
} }
} }


+ 10
- 10
caca/driver/x11.c View File

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2007 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* 2007 Ben Wiley Sittler <bsittler@gmail.com> * 2007 Ben Wiley Sittler <bsittler@gmail.com>
* All Rights Reserved * All Rights Reserved
* *
@@ -295,17 +295,17 @@ static void x11_display(caca_display_t *dp)
int height = caca_get_canvas_height(dp->cv); int height = caca_get_canvas_height(dp->cv);
int x, y, i, len; int x, y, i, len;


for(i = 0; i < caca_get_dirty_rectangle_count(dp->cv); i++)
for(i = 0; i < caca_get_dirty_rect_count(dp->cv); i++)
{ {
int xmin, ymin, xmax, ymax;
int dx, dy, dw, dh;


caca_get_dirty_rectangle(dp->cv, i, &xmin, &ymin, &xmax, &ymax);
caca_get_dirty_rect(dp->cv, i, &dx, &dy, &dw, &dh);


/* First draw the background colours. Splitting the process in two /* First draw the background colours. Splitting the process in two
* loops like this is actually slightly faster. */ * loops like this is actually slightly faster. */
for(y = ymin; y <= ymax; y++)
for(y = dy; y < dy + dh; y++)
{ {
for(x = xmin; x <= xmax; x += len)
for(x = dx; x < dx + dw; x += len)
{ {
uint32_t const *attrs = cvattrs + x + y * width; uint32_t const *attrs = cvattrs + x + y * width;
uint16_t bg = caca_attr_to_rgb12_bg(*attrs); uint16_t bg = caca_attr_to_rgb12_bg(*attrs);
@@ -327,14 +327,14 @@ static void x11_display(caca_display_t *dp)
} }


/* Then print the foreground characters */ /* Then print the foreground characters */
for(y = ymin; y <= ymax; y++)
for(y = dy; y < dy + dh; y++)
{ {
int yoff = (y + 1) * dp->drv.p->font_height int yoff = (y + 1) * dp->drv.p->font_height
- dp->drv.p->font_offset; - dp->drv.p->font_offset;
uint32_t const *chars = cvchars + xmin + y * width;
uint32_t const *attrs = cvattrs + xmin + y * width;
uint32_t const *chars = cvchars + dx + y * width;
uint32_t const *attrs = cvattrs + dx + y * width;


for(x = xmin; x <= xmax; x++, chars++, attrs++)
for(x = dx; x < dx + dw; x++, chars++, attrs++)
{ {
XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, XSetForeground(dp->drv.p->dpy, dp->drv.p->gc,
dp->drv.p->colors[caca_attr_to_rgb12_fg(*attrs)]); dp->drv.p->colors[caca_attr_to_rgb12_fg(*attrs)]);


+ 3
- 3
caca/frame.c View File

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -72,7 +72,7 @@ int caca_set_frame(caca_canvas_t *cv, int id)
cv->frame = id; cv->frame = id;
_caca_load_frame_info(cv); _caca_load_frame_info(cv);


caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }
@@ -236,7 +236,7 @@ int caca_free_frame(caca_canvas_t *cv, int id)
{ {
cv->frame = 0; cv->frame = 0;
_caca_load_frame_info(cv); _caca_load_frame_info(cv);
caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);
} }


return 0; return 0;


+ 2
- 2
caca/graphics.c View File

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -155,7 +155,7 @@ int caca_refresh_display(caca_display_t *dp)
dp->drv.display(dp); dp->drv.display(dp);


/* Invalidate the dirty rectangle */ /* Invalidate the dirty rectangle */
caca_clear_dirty_rectangle_list(dp->cv);
caca_clear_dirty_rect_list(dp->cv);


/* Once the display is finished, we can ack resizes */ /* Once the display is finished, we can ack resizes */
if(dp->resize.resized) if(dp->resize.resized)


+ 7
- 6
caca/string.c View File

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -176,7 +176,7 @@ int caca_put_char(caca_canvas_t *cv, int x, int y, uint32_t ch)
} }
} }


caca_add_dirty_rectangle(cv, xmin, y, xmax, y);
caca_add_dirty_rect(cv, xmin, y, xmax - xmin + 1, 1);


curchar[0] = ch; curchar[0] = ch;
curattr[0] = attr; curattr[0] = attr;
@@ -322,7 +322,7 @@ int caca_clear_canvas(caca_canvas_t *cv)
cv->attrs[n] = attr; cv->attrs[n] = attr;
} }


caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }
@@ -461,8 +461,9 @@ int caca_blit(caca_canvas_t *dst, int x, int y,
dst->chars[dstix + stride - 1] = ' '; dst->chars[dstix + stride - 1] = ' ';
} }


caca_add_dirty_rectangle(dst, starti + x - bleed_left, startj + y,
endi + x - 1 + bleed_right, endj + y - 1);
caca_add_dirty_rect(dst, starti + x - bleed_left, startj + y,
endi - starti + bleed_left + bleed_right,
endj - startj);


return 0; return 0;
} }
@@ -528,7 +529,7 @@ int caca_set_canvas_boundaries(caca_canvas_t *cv, int x, int y, int w, int h)
_caca_load_frame_info(cv); _caca_load_frame_info(cv);


/* FIXME: this may be optimised somewhat */ /* FIXME: this may be optimised somewhat */
caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }


+ 9
- 9
caca/transform.c View File

@@ -1,6 +1,6 @@
/* /*
* libcaca Colour ASCII-Art library * libcaca Colour ASCII-Art library
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2002-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -54,7 +54,7 @@ int caca_invert(caca_canvas_t *cv)
attrs++; attrs++;
} }


caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }
@@ -115,7 +115,7 @@ int caca_flip(caca_canvas_t *cv)
} }
} }


caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }
@@ -162,7 +162,7 @@ int caca_flop(caca_canvas_t *cv)
*ctop = flopchar(*ctop); *ctop = flopchar(*ctop);
} }


caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }
@@ -221,7 +221,7 @@ int caca_rotate_180(caca_canvas_t *cv)
} }
} }


caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }
@@ -340,7 +340,7 @@ int caca_rotate_left(caca_canvas_t *cv)
/* Reset the current frame shortcuts */ /* Reset the current frame shortcuts */
_caca_load_frame_info(cv); _caca_load_frame_info(cv);


caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }
@@ -459,7 +459,7 @@ int caca_rotate_right(caca_canvas_t *cv)
/* Reset the current frame shortcuts */ /* Reset the current frame shortcuts */
_caca_load_frame_info(cv); _caca_load_frame_info(cv);


caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }
@@ -552,7 +552,7 @@ int caca_stretch_left(caca_canvas_t *cv)
/* Reset the current frame shortcuts */ /* Reset the current frame shortcuts */
_caca_load_frame_info(cv); _caca_load_frame_info(cv);


caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }
@@ -645,7 +645,7 @@ int caca_stretch_right(caca_canvas_t *cv)
/* Reset the current frame shortcuts */ /* Reset the current frame shortcuts */
_caca_load_frame_info(cv); _caca_load_frame_info(cv);


caca_add_dirty_rectangle(cv, 0, 0, cv->width - 1, cv->height - 1);
caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height);


return 0; return 0;
} }


+ 53
- 53
tests/dirty.cpp View File

@@ -1,6 +1,6 @@
/* /*
* caca-test testsuite program for libcaca * caca-test testsuite program for libcaca
* Copyright (c) 2009 Sam Hocevar <sam@zoy.org>
* Copyright (c) 2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved * All Rights Reserved
* *
* $Id$ * $Id$
@@ -38,23 +38,23 @@ public:
void test_create() void test_create()
{ {
caca_canvas_t *cv; caca_canvas_t *cv;
int i, xmin, xmax, ymin, ymax;
int i, dx, dy, dw, dh;


/* Check that the dirty rectangle contains the whole canvas /* Check that the dirty rectangle contains the whole canvas
* upon creation. */ * upon creation. */
cv = caca_create_canvas(WIDTH, HEIGHT); cv = caca_create_canvas(WIDTH, HEIGHT);
i = caca_get_dirty_rectangle_count(cv);
i = caca_get_dirty_rect_count(cv);
CPPUNIT_ASSERT_EQUAL(i, 1); CPPUNIT_ASSERT_EQUAL(i, 1);


caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
CPPUNIT_ASSERT_EQUAL(xmin, 0);
CPPUNIT_ASSERT_EQUAL(ymin, 0);
CPPUNIT_ASSERT_EQUAL(xmax, caca_get_canvas_width(cv) - 1);
CPPUNIT_ASSERT_EQUAL(ymax, caca_get_canvas_height(cv) - 1);
caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
CPPUNIT_ASSERT_EQUAL(dx, 0);
CPPUNIT_ASSERT_EQUAL(dy, 0);
CPPUNIT_ASSERT_EQUAL(dw, caca_get_canvas_width(cv));
CPPUNIT_ASSERT_EQUAL(dh, caca_get_canvas_height(cv));


/* Invalidate the dirty rectangle and check that it stays so. */ /* Invalidate the dirty rectangle and check that it stays so. */
caca_clear_dirty_rectangle_list(cv);
i = caca_get_dirty_rectangle_count(cv);
caca_clear_dirty_rect_list(cv);
i = caca_get_dirty_rect_count(cv);
CPPUNIT_ASSERT_EQUAL(i, 0); CPPUNIT_ASSERT_EQUAL(i, 0);


caca_free_canvas(cv); caca_free_canvas(cv);
@@ -63,78 +63,78 @@ public:
void test_put_char() void test_put_char()
{ {
caca_canvas_t *cv; caca_canvas_t *cv;
int i, xmin, xmax, ymin, ymax;
int i, dx, dy, dw, dh;


cv = caca_create_canvas(WIDTH, HEIGHT); cv = caca_create_canvas(WIDTH, HEIGHT);


caca_clear_dirty_rectangle_list(cv);
caca_clear_dirty_rect_list(cv);
caca_put_char(cv, 7, 3, 'x'); caca_put_char(cv, 7, 3, 'x');
i = caca_get_dirty_rectangle_count(cv);
i = caca_get_dirty_rect_count(cv);
CPPUNIT_ASSERT_EQUAL(i, 1); CPPUNIT_ASSERT_EQUAL(i, 1);
caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
CPPUNIT_ASSERT_EQUAL(xmin, 7);
CPPUNIT_ASSERT_EQUAL(ymin, 3);
CPPUNIT_ASSERT_EQUAL(xmax, 7);
CPPUNIT_ASSERT_EQUAL(ymax, 3);
caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
CPPUNIT_ASSERT_EQUAL(dx, 7);
CPPUNIT_ASSERT_EQUAL(dy, 3);
CPPUNIT_ASSERT_EQUAL(dw, 1);
CPPUNIT_ASSERT_EQUAL(dh, 1);


caca_clear_canvas(cv); caca_clear_canvas(cv);
caca_clear_dirty_rectangle_list(cv);
caca_clear_dirty_rect_list(cv);
caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */); caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
i = caca_get_dirty_rectangle_count(cv);
i = caca_get_dirty_rect_count(cv);
CPPUNIT_ASSERT_EQUAL(i, 1); CPPUNIT_ASSERT_EQUAL(i, 1);
caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
CPPUNIT_ASSERT_EQUAL(xmin, 7);
CPPUNIT_ASSERT_EQUAL(ymin, 3);
CPPUNIT_ASSERT_EQUAL(xmax, 8);
CPPUNIT_ASSERT_EQUAL(ymax, 3);
caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
CPPUNIT_ASSERT_EQUAL(dx, 7);
CPPUNIT_ASSERT_EQUAL(dy, 3);
CPPUNIT_ASSERT_EQUAL(dw, 2);
CPPUNIT_ASSERT_EQUAL(dh, 1);


caca_clear_canvas(cv); caca_clear_canvas(cv);
caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */); caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
caca_clear_dirty_rectangle_list(cv);
caca_clear_dirty_rect_list(cv);
caca_put_char(cv, 7, 3, 'x'); caca_put_char(cv, 7, 3, 'x');
i = caca_get_dirty_rectangle_count(cv);
i = caca_get_dirty_rect_count(cv);
CPPUNIT_ASSERT_EQUAL(i, 1); CPPUNIT_ASSERT_EQUAL(i, 1);
caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
CPPUNIT_ASSERT_EQUAL(xmin, 7);
CPPUNIT_ASSERT_EQUAL(ymin, 3);
CPPUNIT_ASSERT_EQUAL(xmax, 8);
CPPUNIT_ASSERT_EQUAL(ymax, 3);
caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
CPPUNIT_ASSERT_EQUAL(dx, 7);
CPPUNIT_ASSERT_EQUAL(dy, 3);
CPPUNIT_ASSERT_EQUAL(dw, 2);
CPPUNIT_ASSERT_EQUAL(dh, 1);


caca_clear_canvas(cv); caca_clear_canvas(cv);
caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */); caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
caca_clear_dirty_rectangle_list(cv);
caca_clear_dirty_rect_list(cv);
caca_put_char(cv, 8, 3, 'x'); caca_put_char(cv, 8, 3, 'x');
i = caca_get_dirty_rectangle_count(cv);
i = caca_get_dirty_rect_count(cv);
CPPUNIT_ASSERT_EQUAL(i, 1); CPPUNIT_ASSERT_EQUAL(i, 1);
caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
CPPUNIT_ASSERT_EQUAL(xmin, 7);
CPPUNIT_ASSERT_EQUAL(ymin, 3);
CPPUNIT_ASSERT_EQUAL(xmax, 8);
CPPUNIT_ASSERT_EQUAL(ymax, 3);
caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
CPPUNIT_ASSERT_EQUAL(dx, 7);
CPPUNIT_ASSERT_EQUAL(dy, 3);
CPPUNIT_ASSERT_EQUAL(dw, 2);
CPPUNIT_ASSERT_EQUAL(dh, 1);


caca_clear_canvas(cv); caca_clear_canvas(cv);
caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */); caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
caca_clear_dirty_rectangle_list(cv);
caca_clear_dirty_rect_list(cv);
caca_put_char(cv, 6, 3, 0x2f06 /* ⼆ */); caca_put_char(cv, 6, 3, 0x2f06 /* ⼆ */);
i = caca_get_dirty_rectangle_count(cv);
i = caca_get_dirty_rect_count(cv);
CPPUNIT_ASSERT_EQUAL(i, 1); CPPUNIT_ASSERT_EQUAL(i, 1);
caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
CPPUNIT_ASSERT_EQUAL(xmin, 6);
CPPUNIT_ASSERT_EQUAL(ymin, 3);
CPPUNIT_ASSERT_EQUAL(xmax, 8);
CPPUNIT_ASSERT_EQUAL(ymax, 3);
caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
CPPUNIT_ASSERT_EQUAL(dx, 6);
CPPUNIT_ASSERT_EQUAL(dy, 3);
CPPUNIT_ASSERT_EQUAL(dw, 3);
CPPUNIT_ASSERT_EQUAL(dh, 1);


caca_clear_canvas(cv); caca_clear_canvas(cv);
caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */); caca_put_char(cv, 7, 3, 0x2f06 /* ⼆ */);
caca_clear_dirty_rectangle_list(cv);
caca_clear_dirty_rect_list(cv);
caca_put_char(cv, 8, 3, 0x2f06 /* ⼆ */); caca_put_char(cv, 8, 3, 0x2f06 /* ⼆ */);
i = caca_get_dirty_rectangle_count(cv);
i = caca_get_dirty_rect_count(cv);
CPPUNIT_ASSERT_EQUAL(i, 1); CPPUNIT_ASSERT_EQUAL(i, 1);
caca_get_dirty_rectangle(cv, 0, &xmin, &ymin, &xmax, &ymax);
CPPUNIT_ASSERT_EQUAL(xmin, 7);
CPPUNIT_ASSERT_EQUAL(ymin, 3);
CPPUNIT_ASSERT_EQUAL(xmax, 9);
CPPUNIT_ASSERT_EQUAL(ymax, 3);
caca_get_dirty_rect(cv, 0, &dx, &dy, &dw, &dh);
CPPUNIT_ASSERT_EQUAL(dx, 7);
CPPUNIT_ASSERT_EQUAL(dy, 3);
CPPUNIT_ASSERT_EQUAL(dw, 3);
CPPUNIT_ASSERT_EQUAL(dh, 1);
} }


private: private:


Loading…
Cancel
Save