forked from len0rd/rockbox
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
This commit is contained in:
parent
b1783c3c64
commit
765ff0130a
8 changed files with 1100 additions and 174 deletions
|
@ -92,6 +92,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)
|
||||
|
@ -312,8 +334,13 @@ void lcd_clear_display(void)
|
|||
/* Set a single pixel */
|
||||
void lcd_drawpixel(int x, int y)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) &&
|
||||
((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCD_WIDTH)
|
||||
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
|
||||
#endif
|
||||
)
|
||||
lcd_fastpixelfuncs[current_vp->drawmode](LCDADDR(current_vp->x+x, current_vp->y+y));
|
||||
}
|
||||
|
||||
|
@ -382,7 +409,13 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
|
|||
|
||||
for (i = 0; i < numpixels; i++)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) && ((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCD_WIDTH)
|
||||
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
|
||||
#endif
|
||||
)
|
||||
pfunc(LCDADDR(x + current_vp->x, y + current_vp->y));
|
||||
|
||||
if (d < 0)
|
||||
|
@ -415,19 +448,38 @@ void lcd_hline(int x1, int x2, int y)
|
|||
x2 = x;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned)current_vp->height) ||
|
||||
(x1 >= current_vp->width) ||
|
||||
(x2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= current_vp->width)
|
||||
x2 = current_vp->width-1;
|
||||
|
||||
dst = LCDADDR(x1 + current_vp->x, y + current_vp->y);
|
||||
/* Adjust x1 and y to viewport */
|
||||
x1 += current_vp->x;
|
||||
x2 += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned) LCD_HEIGHT) || (x1 >= LCD_WIDTH)
|
||||
|| (x2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= LCD_WIDTH)
|
||||
x2 = LCD_WIDTH-1;
|
||||
#endif
|
||||
|
||||
dst = LCDADDR(x1 , y );
|
||||
dst_end = dst + (x2 - x1) * LCD_HEIGHT;
|
||||
|
||||
do
|
||||
|
@ -454,12 +506,39 @@ void lcd_vline(int x, int y1, int y2)
|
|||
y2 = y;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)x >= (unsigned)current_vp->width) ||
|
||||
(y1 >= current_vp->height) ||
|
||||
(y2 < 0))
|
||||
return;
|
||||
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= current_vp->height)
|
||||
y2 = current_vp->height-1;
|
||||
|
||||
/* adjust for viewport */
|
||||
x += current_vp->x;
|
||||
y1 += current_vp->y;
|
||||
y2 += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (( (unsigned) x >= (unsigned)LCD_WIDTH) || (y1 >= LCD_HEIGHT)
|
||||
|| (y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= LCD_HEIGHT)
|
||||
y2 = LCD_HEIGHT-1;
|
||||
#endif
|
||||
|
||||
height = y2 - y1 + 1;
|
||||
|
||||
/* drawmode and optimisation */
|
||||
if (current_vp->drawmode & DRMODE_INVERSEVID)
|
||||
{
|
||||
|
@ -485,18 +564,6 @@ void lcd_vline(int x, int y1, int y2)
|
|||
if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= current_vp->height)
|
||||
y2 = current_vp->height-1;
|
||||
|
||||
height = y2 - y1 + 1;
|
||||
|
||||
/* Adjust y1 and x to viewport */
|
||||
y1 += current_vp->y;
|
||||
x += current_vp->x;
|
||||
|
||||
dst = LCDADDR(x, y1);
|
||||
|
||||
switch (fillopt)
|
||||
|
@ -541,11 +608,55 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
enum fill_opt fillopt = OPT_NONE;
|
||||
fb_data *dst, *dst_end;
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > current_vp->width)
|
||||
width = current_vp->width - x;
|
||||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
/* adjust for viewport */
|
||||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
/* drawmode and optimisation */
|
||||
if (current_vp->drawmode & DRMODE_INVERSEVID)
|
||||
{
|
||||
|
@ -571,23 +682,7 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > current_vp->width)
|
||||
width = current_vp->width - x;
|
||||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
dst = LCDADDR(current_vp->x + x, current_vp->y + y);
|
||||
dst = LCDADDR(x, y);
|
||||
dst_end = dst + width * LCD_HEIGHT;
|
||||
|
||||
do
|
||||
|
@ -641,12 +736,12 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
unsigned dmask = 0x100; /* bit 8 == sentinel */
|
||||
int drmode = current_vp->drawmode;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -664,10 +759,40 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
/* adjust for viewport */
|
||||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
src_y &= 7;
|
||||
src_end = src + width;
|
||||
dst = LCDADDR(current_vp->x + x, current_vp->y + y);
|
||||
dst = LCDADDR(x, y);
|
||||
dst_end = dst + height;
|
||||
|
||||
if (drmode & DRMODE_INVERSEVID)
|
||||
|
@ -793,12 +918,12 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
|||
{
|
||||
fb_data *dst, *dst_end;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -811,13 +936,44 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
|||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if (x + width > current_vp->width)
|
||||
width = current_vp->width - x;
|
||||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
/* adjust for viewport */
|
||||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
src += stride * src_x + src_y; /* move starting point */
|
||||
dst = LCDADDR(current_vp->x + x, current_vp->y + y);
|
||||
dst = LCDADDR(x, y);
|
||||
dst_end = dst + width * LCD_HEIGHT;
|
||||
|
||||
do
|
||||
|
@ -844,12 +1000,12 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
|
|||
{
|
||||
fb_data *dst, *dst_end;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -862,13 +1018,44 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
|
|||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if (x + width > current_vp->width)
|
||||
width = current_vp->width - x;
|
||||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
/* adjust for viewport */
|
||||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
src += stride * src_x + src_y; /* move starting point */
|
||||
dst = LCDADDR(current_vp->x + x, current_vp->y + y);
|
||||
dst = LCDADDR(x, y);
|
||||
dst_end = dst + width * LCD_HEIGHT;
|
||||
|
||||
do
|
||||
|
|
|
@ -85,6 +85,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)
|
||||
|
@ -305,8 +327,13 @@ void lcd_clear_display(void)
|
|||
/* Set a single pixel */
|
||||
void lcd_drawpixel(int x, int y)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) &&
|
||||
((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCD_WIDTH)
|
||||
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
|
||||
#endif
|
||||
)
|
||||
lcd_fastpixelfuncs[current_vp->drawmode](LCDADDR(current_vp->x+x, current_vp->y+y));
|
||||
}
|
||||
|
||||
|
@ -375,7 +402,13 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
|
|||
|
||||
for (i = 0; i < numpixels; i++)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) && ((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCD_WIDTH)
|
||||
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
|
||||
#endif
|
||||
)
|
||||
pfunc(LCDADDR(x + current_vp->x, y + current_vp->y));
|
||||
|
||||
if (d < 0)
|
||||
|
@ -409,12 +442,39 @@ void lcd_hline(int x1, int x2, int y)
|
|||
x2 = x;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned)current_vp->height) ||
|
||||
(x1 >= current_vp->width) ||
|
||||
(x2 < 0))
|
||||
return;
|
||||
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= current_vp->width)
|
||||
x2 = current_vp->width-1;
|
||||
|
||||
/* Adjust x1 and y to viewport */
|
||||
x1 += current_vp->x;
|
||||
x2 += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned) LCD_HEIGHT) || (x1 >= LCD_WIDTH)
|
||||
|| (x2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= LCD_WIDTH)
|
||||
x2 = LCD_WIDTH-1;
|
||||
#endif
|
||||
|
||||
width = x2 - x1 + 1;
|
||||
|
||||
/* drawmode and optimisation */
|
||||
if (current_vp->drawmode & DRMODE_INVERSEVID)
|
||||
{
|
||||
|
@ -440,18 +500,6 @@ void lcd_hline(int x1, int x2, int y)
|
|||
if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= current_vp->width)
|
||||
x2 = current_vp->width-1;
|
||||
|
||||
width = x2 - x1 + 1;
|
||||
|
||||
/* Adjust x1 and y to viewport */
|
||||
x1 += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
dst = LCDADDR(x1, y);
|
||||
|
||||
switch (fillopt)
|
||||
|
@ -489,19 +537,38 @@ void lcd_vline(int x, int y1, int y2)
|
|||
y2 = y;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)x >= (unsigned)current_vp->width) ||
|
||||
(y1 >= current_vp->height) ||
|
||||
(y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= current_vp->height)
|
||||
y2 = current_vp->height-1;
|
||||
|
||||
dst = LCDADDR(x + current_vp->x, y1 + current_vp->y);
|
||||
/* adjust for viewport */
|
||||
x += current_vp->x;
|
||||
y1 += current_vp->y;
|
||||
y2 += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (( (unsigned) x >= (unsigned)LCD_WIDTH) || (y1 >= LCD_HEIGHT)
|
||||
|| (y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= LCD_HEIGHT)
|
||||
y2 = LCD_HEIGHT-1;
|
||||
#endif
|
||||
|
||||
dst = LCDADDR(x , y1);
|
||||
dst_end = dst + (y2 - y1) * LCD_WIDTH;
|
||||
|
||||
do
|
||||
|
@ -534,11 +601,55 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
enum fill_opt fillopt = OPT_NONE;
|
||||
fb_data *dst, *dst_end;
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > current_vp->width)
|
||||
width = current_vp->width - x;
|
||||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
/* adjust for viewport */
|
||||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
/* drawmode and optimisation */
|
||||
if (current_vp->drawmode & DRMODE_INVERSEVID)
|
||||
{
|
||||
|
@ -564,23 +675,7 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
if (fillopt == OPT_NONE && current_vp->drawmode != DRMODE_COMPLEMENT)
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > current_vp->width)
|
||||
width = current_vp->width - x;
|
||||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
dst = LCDADDR(current_vp->x + x, current_vp->y + y);
|
||||
dst = LCDADDR(x, y);
|
||||
dst_end = dst + height * LCD_WIDTH;
|
||||
|
||||
do
|
||||
|
@ -634,12 +729,12 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
unsigned dmask = 0x100; /* bit 8 == sentinel */
|
||||
int drmode = current_vp->drawmode;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -657,10 +752,40 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
/* adjust for viewport */
|
||||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
src_y &= 7;
|
||||
src_end = src + width;
|
||||
dst = LCDADDR(current_vp->x + x, current_vp->y + y);
|
||||
dst = LCDADDR(x, y);
|
||||
dst_end = dst + height * LCD_WIDTH;
|
||||
|
||||
if (drmode & DRMODE_INVERSEVID)
|
||||
|
@ -784,34 +909,62 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
|||
{
|
||||
fb_data *dst;
|
||||
|
||||
if (x + width > current_vp->width)
|
||||
width = current_vp->width - x; /* Clip right */
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
if (x < 0) /* Clip left */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (width <= 0)
|
||||
return; /* nothing left to do */
|
||||
|
||||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y; /* Clip bottom */
|
||||
|
||||
if (y < 0) /* Clip top */
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if (height <= 0)
|
||||
return; /* nothing left to do */
|
||||
if (x + width > current_vp->width)
|
||||
width = current_vp->width - x;
|
||||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
/* adjust for viewport */
|
||||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
src += stride * src_y + src_x; /* move starting point */
|
||||
dst = LCDADDR(current_vp->x + x, current_vp->y + y);
|
||||
dst = LCDADDR(x, y);
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -836,34 +989,62 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
|
|||
fb_data *dst;
|
||||
unsigned fg = current_vp->fg_pattern;
|
||||
|
||||
if (x + width > current_vp->width)
|
||||
width = current_vp->width - x; /* Clip right */
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
if (x < 0) /* Clip left */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (width <= 0)
|
||||
return; /* nothing left to do */
|
||||
|
||||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y; /* Clip bottom */
|
||||
|
||||
if (y < 0) /* Clip top */
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if (height <= 0)
|
||||
return; /* nothing left to do */
|
||||
if (x + width > current_vp->width)
|
||||
width = current_vp->width - x;
|
||||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
/* adjust for viewport */
|
||||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
src += stride * src_y + src_x; /* move starting point */
|
||||
dst = LCDADDR(current_vp->x + x, current_vp->y + y);
|
||||
dst = LCDADDR(x, y);
|
||||
|
||||
#ifdef CPU_ARM
|
||||
{
|
||||
|
|
|
@ -66,6 +66,28 @@ void LCDFN(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) LCDM(WIDTH)
|
||||
|| (unsigned) current_vp->y > (unsigned) LCDM(HEIGHT)
|
||||
|| current_vp->x + current_vp->width > LCDM(WIDTH)
|
||||
|| current_vp->y + current_vp->height > LCDM(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 LCDFN(update_viewport)(void)
|
||||
|
@ -254,8 +276,13 @@ void LCDFN(clear_viewport)(void)
|
|||
/* Set a single pixel */
|
||||
void LCDFN(drawpixel)(int x, int y)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) &&
|
||||
((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCDM(WIDTH))
|
||||
&& ((unsigned)y < (unsigned)LCDM(HEIGHT))
|
||||
#endif
|
||||
)
|
||||
LCDFN(pixelfuncs)[current_vp->drawmode](current_vp->x + x, current_vp->y + y);
|
||||
}
|
||||
|
||||
|
@ -324,8 +351,13 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
|
|||
|
||||
for (i = 0; i < numpixels; i++)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCDM(WIDTH))
|
||||
&& ((unsigned)y < (unsigned)LCDM(HEIGHT))
|
||||
#endif
|
||||
)
|
||||
pfunc(current_vp->x + x, current_vp->y + y);
|
||||
|
||||
if (d < 0)
|
||||
|
@ -359,23 +391,39 @@ void LCDFN(hline)(int x1, int x2, int y)
|
|||
x2 = x;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width)
|
||||
|| (x2 < 0))
|
||||
return;
|
||||
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= current_vp->width)
|
||||
x2 = current_vp->width-1;
|
||||
|
||||
/* adjust to viewport */
|
||||
x1 += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
x2 += current_vp->x;
|
||||
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned) LCDM(HEIGHT)) || (x1 >= LCDM(WIDTH))
|
||||
|| (x2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= current_vp->width)
|
||||
x2 = current_vp->width-1;
|
||||
if (x2 >= LCDM(WIDTH))
|
||||
x2 = LCDM(WIDTH)-1;
|
||||
#endif
|
||||
|
||||
width = x2 - x1 + 1;
|
||||
|
||||
/* adjust to viewport */
|
||||
x1 += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
|
||||
dst = &LCDFN(framebuffer)[y>>3][x1];
|
||||
mask = BIT_N(y & 7);
|
||||
|
@ -402,12 +450,12 @@ void LCDFN(vline)(int x, int y1, int y2)
|
|||
y2 = ny;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height)
|
||||
|| (y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= current_vp->height)
|
||||
|
@ -418,6 +466,20 @@ void LCDFN(vline)(int x, int y1, int y2)
|
|||
y2 += current_vp->y;
|
||||
x += current_vp->x;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (( (unsigned) x >= (unsigned)LCDM(WIDTH)) || (y1 >= LCDM(HEIGHT))
|
||||
|| (y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= LCDM(HEIGHT))
|
||||
y2 = LCDM(HEIGHT)-1;
|
||||
#endif
|
||||
|
||||
bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
|
||||
dst = &LCDFN(framebuffer)[y1>>3][x];
|
||||
ny = y2 - (y1 & ~7);
|
||||
|
@ -459,12 +521,12 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
|
|||
LCDFN(blockfunc_type) *bfunc;
|
||||
bool fillopt = false;
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|
||||
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -484,6 +546,30 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
|
|||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCDM(WIDTH)) || (y >= LCDM(HEIGHT))
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCDM(WIDTH))
|
||||
width = LCDM(WIDTH) - x;
|
||||
if (y + height > LCDM(HEIGHT))
|
||||
height = LCDM(HEIGHT) - y;
|
||||
#endif
|
||||
|
||||
if (current_vp->drawmode & DRMODE_INVERSEVID)
|
||||
{
|
||||
if (current_vp->drawmode & DRMODE_BG)
|
||||
|
@ -556,12 +642,13 @@ void ICODE_ATTR LCDFN(bitmap_part)(const unsigned char *src, int src_x,
|
|||
unsigned mask, mask_bottom;
|
||||
LCDFN(blockfunc_type) *bfunc;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|
||||
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
/* clip image in viewport */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -583,6 +670,32 @@ void ICODE_ATTR LCDFN(bitmap_part)(const unsigned char *src, int src_x,
|
|||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCDM(WIDTH)) || (y >= LCDM(HEIGHT))
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCDM(WIDTH))
|
||||
width = LCDM(WIDTH) - x;
|
||||
if (y + height > LCDM(HEIGHT))
|
||||
height = LCDM(HEIGHT) - y;
|
||||
#endif
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
src_y &= 7;
|
||||
y -= src_y;
|
||||
|
|
|
@ -87,6 +87,28 @@ void lcd_set_viewport(struct viewport* vp)
|
|||
|
||||
fg_pattern = 0x55 * (~current_vp->fg_pattern & 3);
|
||||
bg_pattern = 0x55 * (~current_vp->bg_pattern & 3);
|
||||
|
||||
#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)
|
||||
|
@ -415,8 +437,13 @@ void lcd_clear_viewport(void)
|
|||
/* Set a single pixel */
|
||||
void lcd_drawpixel(int x, int y)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) &&
|
||||
((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCD_WIDTH)
|
||||
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
|
||||
#endif
|
||||
)
|
||||
lcd_pixelfuncs[current_vp->drawmode](current_vp->x + x, current_vp->y + y);
|
||||
}
|
||||
|
||||
|
@ -485,8 +512,13 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
|
|||
|
||||
for (i = 0; i < numpixels; i++)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) &&
|
||||
((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCD_WIDTH)
|
||||
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
|
||||
#endif
|
||||
)
|
||||
pfunc(current_vp->x + x, current_vp->y + y);
|
||||
|
||||
if (d < 0)
|
||||
|
@ -520,12 +552,12 @@ void lcd_hline(int x1, int x2, int y)
|
|||
x2 = nx;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width)
|
||||
|| (x2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= current_vp->width)
|
||||
|
@ -536,6 +568,20 @@ void lcd_hline(int x1, int x2, int y)
|
|||
x2 += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned) LCD_HEIGHT) || (x1 >= LCD_WIDTH)
|
||||
|| (x2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= LCD_WIDTH)
|
||||
x2 = LCD_WIDTH-1;
|
||||
#endif
|
||||
|
||||
bfunc = lcd_blockfuncs[current_vp->drawmode];
|
||||
dst = &lcd_framebuffer[y][x1>>2];
|
||||
nx = x2 - (x1 & ~3);
|
||||
|
@ -567,12 +613,12 @@ void lcd_vline(int x, int y1, int y2)
|
|||
y2 = y;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height)
|
||||
|| (y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= current_vp->height)
|
||||
|
@ -583,6 +629,20 @@ void lcd_vline(int x, int y1, int y2)
|
|||
y2 += current_vp->y;
|
||||
x += current_vp->x;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (( (unsigned) x >= (unsigned)LCD_WIDTH) || (y1 >= LCD_HEIGHT)
|
||||
|| (y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= LCD_HEIGHT)
|
||||
y2 = LCD_HEIGHT-1;
|
||||
#endif
|
||||
|
||||
bfunc = lcd_blockfuncs[current_vp->drawmode];
|
||||
dst = &lcd_framebuffer[y1][x>>2];
|
||||
mask = pixmask[x & 3];
|
||||
|
@ -619,12 +679,12 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
unsigned mask, mask_right;
|
||||
lcd_blockfunc_type *bfunc;
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) || (y >= current_vp->height)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -644,6 +704,30 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
bfunc = lcd_blockfuncs[current_vp->drawmode];
|
||||
dst = &lcd_framebuffer[y][x>>2];
|
||||
nx = width - 1 + (x & 3);
|
||||
|
@ -696,12 +780,12 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
unsigned dst_mask;
|
||||
int drmode = current_vp->drawmode;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -719,11 +803,40 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
if (y + height > current_vp->height)
|
||||
height = current_vp->height - y;
|
||||
|
||||
x += current_vp->x; /* adjust for viewport */
|
||||
y += current_vp->y; /* adjust for viewport */
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
src_y &= 7;
|
||||
src_end = src + width;
|
||||
x += current_vp->x; /* adjust for viewport */
|
||||
dst = &lcd_framebuffer[current_vp->y + y][x >> 2];
|
||||
|
||||
dst = &lcd_framebuffer[y][x >> 2];
|
||||
dst_end = dst + height * LCD_FBWIDTH;
|
||||
dst_mask = pixmask[x & 3];
|
||||
|
||||
|
@ -879,12 +992,12 @@ void ICODE_ATTR lcd_bitmap_part(const unsigned char *src, int src_x,
|
|||
unsigned char *dst, *dst_end;
|
||||
unsigned mask, mask_right;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -906,6 +1019,32 @@ void ICODE_ATTR lcd_bitmap_part(const unsigned char *src, int src_x,
|
|||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
stride = (stride + 3) >> 2; /* convert to no. of bytes */
|
||||
|
||||
src += stride * src_y + (src_x >> 2); /* move starting point */
|
||||
|
|
|
@ -89,6 +89,28 @@ void lcd_set_viewport(struct viewport* vp)
|
|||
|
||||
fg_pattern = 0x55 * (~current_vp->fg_pattern & 3);
|
||||
bg_pattern = 0x55 * (~current_vp->bg_pattern & 3);
|
||||
|
||||
#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)
|
||||
|
@ -418,8 +440,13 @@ void lcd_clear_viewport(void)
|
|||
/* Set a single pixel */
|
||||
void lcd_drawpixel(int x, int y)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) &&
|
||||
((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCD_WIDTH)
|
||||
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
|
||||
#endif
|
||||
)
|
||||
lcd_pixelfuncs[current_vp->drawmode](current_vp->x + x, current_vp->y + y);
|
||||
}
|
||||
|
||||
|
@ -488,8 +515,13 @@ void lcd_drawline(int x1, int y1, int x2, int y2)
|
|||
|
||||
for (i = 0; i < numpixels; i++)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) &&
|
||||
((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCD_WIDTH)
|
||||
&& ((unsigned)y < (unsigned)LCD_HEIGHT)
|
||||
#endif
|
||||
)
|
||||
pfunc(current_vp->x + x, current_vp->y + y);
|
||||
|
||||
if (d < 0)
|
||||
|
@ -524,23 +556,38 @@ void lcd_hline(int x1, int x2, int y)
|
|||
x2 = x;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width)
|
||||
|| (x2 < 0))
|
||||
return;
|
||||
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= current_vp->width)
|
||||
x2 = current_vp->width-1;
|
||||
|
||||
/* adjust x1 and y to viewport */
|
||||
x1 += current_vp->x;
|
||||
x2 += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned) LCD_HEIGHT) || (x1 >= LCD_WIDTH)
|
||||
|| (x2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= current_vp->width)
|
||||
x2 = current_vp->width-1;
|
||||
if (x2 >= LCD_WIDTH)
|
||||
x2 = LCD_WIDTH-1;
|
||||
#endif
|
||||
|
||||
width = x2 - x1 + 1;
|
||||
|
||||
/* adjust x1 and y to viewport */
|
||||
x1 += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
bfunc = lcd_blockfuncs[current_vp->drawmode];
|
||||
dst = &lcd_framebuffer[y>>2][x1];
|
||||
mask = pixmask[y & 3];
|
||||
|
@ -567,12 +614,12 @@ void lcd_vline(int x, int y1, int y2)
|
|||
y2 = ny;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height)
|
||||
|| (y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= current_vp->height)
|
||||
|
@ -583,6 +630,20 @@ void lcd_vline(int x, int y1, int y2)
|
|||
y2 += current_vp->y;
|
||||
x += current_vp->x;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (( (unsigned) x >= (unsigned)LCD_WIDTH) || (y1 >= LCD_HEIGHT)
|
||||
|| (y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= LCD_HEIGHT)
|
||||
y2 = LCD_HEIGHT-1;
|
||||
#endif
|
||||
|
||||
bfunc = lcd_blockfuncs[current_vp->drawmode];
|
||||
dst = &lcd_framebuffer[y1>>2][x];
|
||||
ny = y2 - (y1 & ~3);
|
||||
|
@ -624,12 +685,12 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
lcd_blockfunc_type *bfunc;
|
||||
bool fillopt = false;
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|
||||
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -649,6 +710,30 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
if (current_vp->drawmode & DRMODE_INVERSEVID)
|
||||
{
|
||||
if ((current_vp->drawmode & DRMODE_BG) && !lcd_backdrop)
|
||||
|
@ -722,12 +807,12 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
unsigned mask, mask_bottom;
|
||||
lcd_blockfunc_type *bfunc;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -749,6 +834,32 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
src_y &= 7;
|
||||
y -= src_y;
|
||||
|
@ -893,12 +1004,12 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
|||
fb_data *dst, *dst_end;
|
||||
unsigned mask, mask_bottom;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|
||||
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -920,6 +1031,32 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
|||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT)
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCD_WIDTH)
|
||||
width = LCD_WIDTH - x;
|
||||
if (y + height > LCD_HEIGHT)
|
||||
height = LCD_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
src += stride * (src_y >> 2) + src_x; /* move starting point */
|
||||
src_y &= 3;
|
||||
y -= src_y;
|
||||
|
|
|
@ -82,6 +82,28 @@ void LCDFN(set_viewport)(struct viewport* vp)
|
|||
|
||||
fg_pattern = patterns[current_vp->fg_pattern & 3];
|
||||
bg_pattern = patterns[current_vp->bg_pattern & 3];
|
||||
|
||||
#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) LCDM(WIDTH)
|
||||
|| (unsigned) current_vp->y > (unsigned) LCDM(HEIGHT)
|
||||
|| current_vp->x + current_vp->width > LCDM(WIDTH)
|
||||
|| current_vp->y + current_vp->height > LCDM(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 LCDFN(update_viewport)(void)
|
||||
|
@ -443,8 +465,13 @@ void LCDFN(clear_viewport)(void)
|
|||
/* Set a single pixel */
|
||||
void LCDFN(drawpixel)(int x, int y)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) &&
|
||||
((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCDM(WIDTH))
|
||||
&& ((unsigned)y < (unsigned)LCDM(HEIGHT))
|
||||
#endif
|
||||
)
|
||||
LCDFN(pixelfuncs)[current_vp->drawmode](current_vp->x+x, current_vp->y+y);
|
||||
}
|
||||
|
||||
|
@ -513,8 +540,13 @@ void LCDFN(drawline)(int x1, int y1, int x2, int y2)
|
|||
|
||||
for (i = 0; i < numpixels; i++)
|
||||
{
|
||||
if (((unsigned)x < (unsigned)current_vp->width) &&
|
||||
((unsigned)y < (unsigned)current_vp->height))
|
||||
if ( ((unsigned)x < (unsigned)current_vp->width)
|
||||
&& ((unsigned)y < (unsigned)current_vp->height)
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
&& ((unsigned)x < (unsigned)LCDM(WIDTH))
|
||||
&& ((unsigned)y < (unsigned)LCDM(HEIGHT))
|
||||
#endif
|
||||
)
|
||||
pfunc(current_vp->x + x, current_vp->y + y);
|
||||
|
||||
if (d < 0)
|
||||
|
@ -549,23 +581,39 @@ void LCDFN(hline)(int x1, int x2, int y)
|
|||
x2 = x;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned)current_vp->height) || (x1 >= current_vp->width)
|
||||
|| (x2 < 0))
|
||||
return;
|
||||
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= current_vp->width)
|
||||
x2 = current_vp->width-1;
|
||||
|
||||
/* adjust x1 and y to viewport */
|
||||
x1 += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
x2 += current_vp->x;
|
||||
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)y >= (unsigned) LCDM(HEIGHT)) || (x1 >= LCDM(WIDTH))
|
||||
|| (x2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x1 < 0)
|
||||
x1 = 0;
|
||||
if (x2 >= current_vp->width)
|
||||
x2 = current_vp->width-1;
|
||||
if (x2 >= LCDM(WIDTH))
|
||||
x2 = LCDM(WIDTH)-1;
|
||||
#endif
|
||||
|
||||
width = x2 - x1 + 1;
|
||||
|
||||
/* adjust x1 and y to viewport */
|
||||
x1 += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
|
||||
dst = &LCDFN(framebuffer)[y>>3][x1];
|
||||
mask = 0x0101 << (y & 7);
|
||||
|
@ -592,12 +640,12 @@ void LCDFN(vline)(int x, int y1, int y2)
|
|||
y2 = ny;
|
||||
}
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if (((unsigned)x >= (unsigned)current_vp->width) || (y1 >= current_vp->height)
|
||||
|| (y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= current_vp->height)
|
||||
|
@ -608,6 +656,20 @@ void LCDFN(vline)(int x, int y1, int y2)
|
|||
y2 += current_vp->y;
|
||||
x += current_vp->x;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if (( (unsigned) x >= (unsigned)LCDM(WIDTH)) || (y1 >= LCDM(HEIGHT))
|
||||
|| (y2 < 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (y1 < 0)
|
||||
y1 = 0;
|
||||
if (y2 >= LCDM(HEIGHT))
|
||||
y2 = LCDM(HEIGHT)-1;
|
||||
#endif
|
||||
|
||||
bfunc = LCDFN(blockfuncs)[current_vp->drawmode];
|
||||
dst = &LCDFN(framebuffer)[y1>>3][x];
|
||||
ny = y2 - (y1 & ~7);
|
||||
|
@ -651,12 +713,12 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
|
|||
LCDFN(blockfunc_type) *bfunc;
|
||||
bool fillopt = false;
|
||||
|
||||
/******************** In viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|
||||
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -676,6 +738,31 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
|
|||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCDM(WIDTH)) || (y >= LCDM(HEIGHT))
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCDM(WIDTH))
|
||||
width = LCDM(WIDTH) - x;
|
||||
if (y + height > LCDM(HEIGHT))
|
||||
height = LCDM(HEIGHT) - y;
|
||||
#endif
|
||||
|
||||
|
||||
if (current_vp->drawmode & DRMODE_INVERSEVID)
|
||||
{
|
||||
if ((current_vp->drawmode & DRMODE_BG) && !backdrop)
|
||||
|
@ -751,12 +838,12 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x,
|
|||
unsigned data, mask, mask_bottom;
|
||||
LCDFN(blockfunc_type) *bfunc;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width) ||
|
||||
(y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -778,6 +865,32 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x,
|
|||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCDM(WIDTH)) || (y >= LCDM(HEIGHT))
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCDM(WIDTH))
|
||||
width = LCDM(WIDTH) - x;
|
||||
if (y + height > LCDM(HEIGHT))
|
||||
height = LCDM(HEIGHT) - y;
|
||||
#endif
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
src_y &= 7;
|
||||
y -= src_y;
|
||||
|
@ -893,12 +1006,12 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x,
|
|||
FBFN(data) *dst, *dst_end;
|
||||
unsigned mask, mask_bottom;
|
||||
|
||||
/******************** Image in viewport clipping **********************/
|
||||
/* nothing to draw? */
|
||||
if ((width <= 0) || (height <= 0) || (x >= current_vp->width)
|
||||
|| (y >= current_vp->height) || (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clipping */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
|
@ -920,6 +1033,32 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x,
|
|||
x += current_vp->x;
|
||||
y += current_vp->y;
|
||||
|
||||
#if defined(HAVE_VIEWPORT_CLIP)
|
||||
/********************* Viewport on screen clipping ********************/
|
||||
/* nothing to draw? */
|
||||
if ((x >= LCDM(WIDTH)) || (y >= LCDM(HEIGHT))
|
||||
|| (x + width <= 0) || (y + height <= 0))
|
||||
return;
|
||||
|
||||
/* clip image in viewport in screen */
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
src_x -= x;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
src_y -= y;
|
||||
y = 0;
|
||||
}
|
||||
if (x + width > LCDM(WIDTH))
|
||||
width = LCDM(WIDTH) - x;
|
||||
if (y + height > LCDM(HEIGHT))
|
||||
height = LCDM(HEIGHT) - y;
|
||||
#endif
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
src_y &= 7;
|
||||
y -= src_y;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -65,6 +65,9 @@
|
|||
/* define this if the target has volume keys which can be used in the lists */
|
||||
#define HAVE_VOLUME_IN_LIST
|
||||
|
||||
/* define this if you want viewport clipping enabled for safe LCD functions */
|
||||
#define HAVE_VIEWPORT_CLIP
|
||||
|
||||
/* LCD dimensions */
|
||||
#define CONFIG_LCD LCD_MROBE500
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue