From ea99175a2fad3c4f1ec2de51b399f7e7209fb516 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 21 May 2009 20:55:13 +0000 Subject: [PATCH] Change the dirty rectangle API once again so that calling applications get a more natural (x,y,w,h) 4-tuple to handle. --- caca/attr.c | 4 +- caca/caca.h | 16 +++---- caca/canvas.c | 10 ++-- caca/dirty.c | 94 ++++++++++++++++++------------------- caca/driver/ncurses.c | 20 ++++---- caca/driver/slang.c | 22 ++++----- caca/driver/vga.c | 22 ++++----- caca/driver/x11.c | 20 ++++---- caca/frame.c | 6 +-- caca/graphics.c | 4 +- caca/string.c | 13 +++--- caca/transform.c | 18 +++---- tests/dirty.cpp | 106 +++++++++++++++++++++--------------------- 13 files changed, 178 insertions(+), 177 deletions(-) diff --git a/caca/attr.c b/caca/attr.c index a544efa..9b7208b 100644 --- a/caca/attr.c +++ b/caca/attr.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -156,7 +156,7 @@ int caca_put_attr(caca_canvas_t *cv, int x, int y, uint32_t attr) xmax++; } - caca_add_dirty_rectangle(cv, xmin, y, xmax, y); + caca_add_dirty_rect(cv, xmin, y, xmax - xmin + 1, 1); return 0; } diff --git a/caca/caca.h b/caca/caca.h index 1954ead..e7ba1a2 100644 --- a/caca/caca.h +++ b/caca/caca.h @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -14,7 +14,7 @@ /** \file caca.h * \version \$Id$ - * \author Sam Hocevar + * \author Sam Hocevar * \brief The \e libcaca public header. * * 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. * @{ */ -__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 diff --git a/caca/canvas.c b/caca/canvas.c index 8971d84..3f070a5 100644 --- a/caca/canvas.c +++ b/caca/canvas.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $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 { @@ -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 * the bottom-right corner, because we only handle one dirty rectangle, * but in case the API changes later, we make sure this is handled. */ 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. */ if(new_size < old_size) diff --git a/caca/dirty.c b/caca/dirty.c index 9b12728..d44ac88 100644 --- a/caca/dirty.c +++ b/caca/dirty.c @@ -41,7 +41,7 @@ * \param cv A libcaca 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; } @@ -49,7 +49,7 @@ int caca_get_dirty_rectangle_count(caca_canvas_t *cv) /** \brief Get a canvas's dirty rectangle. * * 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. * * 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 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. */ -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) { @@ -90,10 +90,10 @@ int caca_get_dirty_rectangle(caca_canvas_t *cv, int r, if(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; } @@ -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. * * 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 * 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. * * \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. */ -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 */ - 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); return -1; @@ -132,21 +132,21 @@ int caca_add_dirty_rectangle(caca_canvas_t *cv, int xmin, int ymin, if(cv->ndirty == 0) { 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 { - 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; @@ -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. * * 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 * 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. * * \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. */ -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 */ - 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); return -1; @@ -197,7 +197,7 @@ int caca_remove_dirty_rectangle(caca_canvas_t *cv, int xmin, int ymin, * \param cv A libcaca canvas. * \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; diff --git a/caca/driver/ncurses.c b/caca/driver/ncurses.c index 5382052..dd1a47d 100644 --- a/caca/driver/ncurses.c +++ b/caca/driver/ncurses.c @@ -347,29 +347,29 @@ static void ncurses_display(caca_display_t *dp) { 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; - 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) - + xmin + ymin * dp->cv->width; + + dx + dy * dp->cv->width; 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++)]); 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; } } diff --git a/caca/driver/slang.c b/caca/driver/slang.c index 99aa332..0002b27 100644 --- a/caca/driver/slang.c +++ b/caca/driver/slang.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -222,22 +222,22 @@ static void slang_display(caca_display_t *dp) { 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; - 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) - + xmin + ymin * dp->cv->width; + + dx + dy * dp->cv->width; 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++; @@ -282,8 +282,8 @@ static void slang_display(caca_display_t *dp) #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)); diff --git a/caca/driver/vga.c b/caca/driver/vga.c index d5fba66..dd3a78d 100644 --- a/caca/driver/vga.c +++ b/caca/driver/vga.c @@ -120,23 +120,23 @@ static void vga_display(caca_display_t *dp) { char *screen = (char *)(intptr_t)0x000b8000; 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) - + xmin + ymin * dp->cv->width; + + dx + dy * dp->cv->width; 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++); - if(x < xmax && *cvchars == CACA_MAGIC_FULLWIDTH) + if(x < dx + dw - 1 && *cvchars == CACA_MAGIC_FULLWIDTH) { *screen++ = '['; *screen++ = caca_attr_to_ansi(*cvattrs++); @@ -148,9 +148,9 @@ static void vga_display(caca_display_t *dp) *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); } } } diff --git a/caca/driver/x11.c b/caca/driver/x11.c index 5528f25..08319c3 100644 --- a/caca/driver/x11.c +++ b/caca/driver/x11.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2007 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * 2007 Ben Wiley Sittler * All Rights Reserved * @@ -295,17 +295,17 @@ static void x11_display(caca_display_t *dp) int height = caca_get_canvas_height(dp->cv); 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 * 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; 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 */ - for(y = ymin; y <= ymax; y++) + for(y = dy; y < dy + dh; y++) { int yoff = (y + 1) * dp->drv.p->font_height - 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, dp->drv.p->colors[caca_attr_to_rgb12_fg(*attrs)]); diff --git a/caca/frame.c b/caca/frame.c index 9566b7e..79c4189 100644 --- a/caca/frame.c +++ b/caca/frame.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -72,7 +72,7 @@ int caca_set_frame(caca_canvas_t *cv, int id) cv->frame = id; _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; } @@ -236,7 +236,7 @@ int caca_free_frame(caca_canvas_t *cv, int id) { cv->frame = 0; _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; diff --git a/caca/graphics.c b/caca/graphics.c index 6b36d85..450d4f0 100644 --- a/caca/graphics.c +++ b/caca/graphics.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -155,7 +155,7 @@ int caca_refresh_display(caca_display_t *dp) dp->drv.display(dp); /* 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 */ if(dp->resize.resized) diff --git a/caca/string.c b/caca/string.c index d276ce9..b6eb194 100644 --- a/caca/string.c +++ b/caca/string.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $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; curattr[0] = attr; @@ -322,7 +322,7 @@ int caca_clear_canvas(caca_canvas_t *cv) 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; } @@ -461,8 +461,9 @@ int caca_blit(caca_canvas_t *dst, int x, int y, 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; } @@ -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); /* 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; } diff --git a/caca/transform.c b/caca/transform.c index 3cecbb8..b39887d 100644 --- a/caca/transform.c +++ b/caca/transform.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2006 Sam Hocevar + * Copyright (c) 2002-2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -54,7 +54,7 @@ int caca_invert(caca_canvas_t *cv) 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; } @@ -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; } @@ -162,7 +162,7 @@ int caca_flop(caca_canvas_t *cv) *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; } @@ -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; } @@ -340,7 +340,7 @@ int caca_rotate_left(caca_canvas_t *cv) /* Reset the current frame shortcuts */ _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; } @@ -459,7 +459,7 @@ int caca_rotate_right(caca_canvas_t *cv) /* Reset the current frame shortcuts */ _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; } @@ -552,7 +552,7 @@ int caca_stretch_left(caca_canvas_t *cv) /* Reset the current frame shortcuts */ _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; } @@ -645,7 +645,7 @@ int caca_stretch_right(caca_canvas_t *cv) /* Reset the current frame shortcuts */ _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; } diff --git a/tests/dirty.cpp b/tests/dirty.cpp index 0311080..09915f8 100644 --- a/tests/dirty.cpp +++ b/tests/dirty.cpp @@ -1,6 +1,6 @@ /* * caca-test testsuite program for libcaca - * Copyright (c) 2009 Sam Hocevar + * Copyright (c) 2009 Sam Hocevar * All Rights Reserved * * $Id$ @@ -38,23 +38,23 @@ public: void test_create() { 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 * upon creation. */ 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); - 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. */ - 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); caca_free_canvas(cv); @@ -63,78 +63,78 @@ public: void test_put_char() { caca_canvas_t *cv; - int i, xmin, xmax, ymin, ymax; + int i, dx, dy, dw, dh; 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'); - i = caca_get_dirty_rectangle_count(cv); + i = caca_get_dirty_rect_count(cv); 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_dirty_rectangle_list(cv); + caca_clear_dirty_rect_list(cv); 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); - 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_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'); - i = caca_get_dirty_rectangle_count(cv); + i = caca_get_dirty_rect_count(cv); 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_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'); - i = caca_get_dirty_rectangle_count(cv); + i = caca_get_dirty_rect_count(cv); 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_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 /* ⼆ */); - i = caca_get_dirty_rectangle_count(cv); + i = caca_get_dirty_rect_count(cv); 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_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 /* ⼆ */); - i = caca_get_dirty_rectangle_count(cv); + i = caca_get_dirty_rect_count(cv); 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: