From 765ff0130ab58c67e82a2ed17c64c577c6434d57 Mon Sep 17 00:00:00 2001 From: Karl Kurbjun Date: Sat, 7 Nov 2009 18:38:46 +0000 Subject: Add optional viewport clipping, can be enabled with HAVE_VIEWPORT_CLIP. A simulator check is also added to set_viewport that will show an error/note when DEBUGF is enabled. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23551 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/lcd-charcell.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'firmware/drivers/lcd-charcell.c') diff --git a/firmware/drivers/lcd-charcell.c b/firmware/drivers/lcd-charcell.c index d02c5eeaad..9fabeb4a22 100644 --- a/firmware/drivers/lcd-charcell.c +++ b/firmware/drivers/lcd-charcell.c @@ -84,6 +84,28 @@ void lcd_set_viewport(struct viewport* vp) current_vp = &default_vp; else current_vp = vp; + +#if defined(SIMULATOR) + /* Force the viewport to be within bounds. If this happens it should + * be considered an error - the viewport will not draw as it might be + * expected. + */ + if((unsigned) current_vp->x > (unsigned) LCD_WIDTH + || (unsigned) current_vp->y > (unsigned) LCD_HEIGHT + || current_vp->x + current_vp->width > LCD_WIDTH + || current_vp->y + current_vp->height > LCD_HEIGHT) + { +#if !defined(HAVE_VIEWPORT_CLIP) + DEBUGF("ERROR: " +#else + DEBUGF("NOTE: " +#endif + "set_viewport out of bounds: x: %d y: %d width: %d height:%d\n", + current_vp->x, current_vp->y, + current_vp->width, current_vp->height); + } + +#endif } void lcd_update_viewport(void) @@ -250,6 +272,11 @@ static void lcd_putxchar(int x, int y, int xchar) x += current_vp->x; y += current_vp->y; +#if defined(HAVE_VIEWPORT_CLIP) + if((unsigned)x > (unsigned)LCD_WIDTH || (unsigned)y > (unsigned)LCD_HEIGHT) + return; +#endif + lcd_char = lcd_charbuffer[y][x]; if (lcd_char < lcd_pattern_count) /* old char was soft */ -- cgit v1.2.3