forked from len0rd/rockbox
lcd: Refactor viewport clipping functions
There's no need to generate separate copies of these functions for main and remote LCDs; we can just pass the viewport directly. Change-Id: I20aa04a58d327b479a942708e161068bd6a3357b
This commit is contained in:
parent
6acc8a81a7
commit
f737e5025d
9 changed files with 47 additions and 51 deletions
|
@ -135,7 +135,7 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
fb_data *dst, *dst_end;
|
||||
int len, step;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, NULL, NULL))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, NULL, NULL))
|
||||
return;
|
||||
|
||||
/* drawmode and optimisation */
|
||||
|
@ -216,7 +216,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
int width, int height)
|
||||
{
|
||||
struct viewport *vp = lcd_current_viewport;
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
/* move starting point */
|
||||
|
@ -424,7 +424,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
|
|||
unsigned dmask = 0x00000000;
|
||||
int drmode = vp->drawmode;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
/* initialize blending */
|
||||
|
|
|
@ -68,7 +68,7 @@ void lcd_hline(int x1, int x2, int y)
|
|||
|
||||
lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[vp->drawmode];
|
||||
|
||||
if (!lcd_clip_viewport_hline(&x1, &x2, &y))
|
||||
if (!clip_viewport_hline(vp, &x1, &x2, &y))
|
||||
return;
|
||||
|
||||
dst = FBADDR(x1, y);
|
||||
|
@ -92,7 +92,7 @@ void lcd_vline(int x, int y1, int y2)
|
|||
enum fill_opt fillopt = OPT_NONE;
|
||||
fb_data *dst, *dst_end;
|
||||
|
||||
if(!lcd_clip_viewport_vline(&x, &y1, &y2))
|
||||
if(!clip_viewport_vline(vp, &x, &y1, &y2))
|
||||
return;
|
||||
|
||||
height = y2 - y1 + 1;
|
||||
|
@ -153,7 +153,7 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
|||
fb_data *dst;
|
||||
int stride_dst;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * src_x + src_y; /* move starting point */
|
||||
|
@ -179,7 +179,7 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
|
|||
fb_data *dst, *dst_end;
|
||||
int stride_dst;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * src_x + src_y; /* move starting point */
|
||||
|
|
|
@ -68,7 +68,7 @@ void lcd_hline(int x1, int x2, int y)
|
|||
enum fill_opt fillopt = OPT_NONE;
|
||||
fb_data *dst, *dst_end;
|
||||
|
||||
if (!lcd_clip_viewport_hline(&x1, &x2, &y))
|
||||
if (!clip_viewport_hline(vp, &x1, &x2, &y))
|
||||
return;
|
||||
|
||||
width = x2 - x1 + 1;
|
||||
|
@ -128,7 +128,7 @@ void lcd_vline(int x, int y1, int y2)
|
|||
int stride_dst;
|
||||
lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[vp->drawmode];
|
||||
|
||||
if (!lcd_clip_viewport_vline(&x, &y1, &y2))
|
||||
if (!clip_viewport_vline(vp, &x, &y1, &y2))
|
||||
return;
|
||||
|
||||
dst = FBADDR(x, y1);
|
||||
|
@ -152,7 +152,7 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
|||
fb_data *dst;
|
||||
int stride_dst;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * src_y + src_x; /* move starting point */
|
||||
|
@ -178,7 +178,7 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
|
|||
unsigned fg = vp->fg_pattern;
|
||||
int stride_dst = vp->buffer->stride;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * src_y + src_x; /* move starting point */
|
||||
|
|
|
@ -243,7 +243,7 @@ void LCDFN(hline)(int x1, int x2, int y)
|
|||
unsigned mask;
|
||||
LCDFN(blockfunc_type) *bfunc;
|
||||
|
||||
if (!LCDFN(clip_viewport_hline)(&x1, &x2, &y))
|
||||
if (!clip_viewport_hline(vp, &x1, &x2, &y))
|
||||
return;
|
||||
|
||||
width = x2 - x1 + 1;
|
||||
|
@ -268,7 +268,7 @@ void LCDFN(vline)(int x, int y1, int y2)
|
|||
unsigned mask, mask_bottom;
|
||||
LCDFN(blockfunc_type) *bfunc;
|
||||
|
||||
if (!LCDFN(clip_viewport_vline)(&x, &y1, &y2))
|
||||
if (!clip_viewport_vline(vp, &x, &y1, &y2))
|
||||
return;
|
||||
|
||||
bfunc = LCDFN(blockfuncs)[vp->drawmode];
|
||||
|
@ -300,7 +300,7 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
|
|||
LCDFN(blockfunc_type) *bfunc;
|
||||
bool fillopt = false;
|
||||
|
||||
if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, NULL, NULL))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, NULL, NULL))
|
||||
return;
|
||||
|
||||
if (vp->drawmode & DRMODE_INVERSEVID)
|
||||
|
@ -378,7 +378,7 @@ void ICODE_ATTR LCDFN(bitmap_part)(const unsigned char *src, int src_x,
|
|||
unsigned mask, mask_bottom;
|
||||
LCDFN(blockfunc_type) *bfunc;
|
||||
|
||||
if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
|
|
|
@ -175,7 +175,7 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
fb_data bits;
|
||||
memset(&bits, 0, sizeof(fb_data));
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, NULL, NULL))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, NULL, NULL))
|
||||
return;
|
||||
|
||||
/* drawmode and optimisation */
|
||||
|
@ -268,7 +268,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
int drmode = vp->drawmode;
|
||||
int row;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
|
@ -450,7 +450,7 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
|
|||
unsigned dmask = 0x00000000;
|
||||
int drmode = vp->drawmode;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
/* the following drawmode combinations are possible:
|
||||
|
@ -698,7 +698,7 @@ void lcd_hline(int x1, int x2, int y)
|
|||
fb_data *dst, *dst_end;
|
||||
lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[vp->drawmode];
|
||||
|
||||
if (!lcd_clip_viewport_hline(&x1, &x2, &y))
|
||||
if (!clip_viewport_hline(vp, &x1, &x2, &y))
|
||||
return;
|
||||
|
||||
width = x2 - x1 + 1;
|
||||
|
@ -719,7 +719,7 @@ void lcd_vline(int x, int y1, int y2)
|
|||
fb_data *dst, *dst_end;
|
||||
lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[vp->drawmode];
|
||||
|
||||
if (!lcd_clip_viewport_vline(&x, &y1, &y2))
|
||||
if (!clip_viewport_vline(vp, &x, &y1, &y2))
|
||||
return;
|
||||
|
||||
dst = FBADDR(x, y1);
|
||||
|
@ -738,9 +738,10 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
|||
int stride, int x, int y, int width,
|
||||
int height)
|
||||
{
|
||||
struct viewport *vp = lcd_current_viewport;
|
||||
fb_data *dst;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * src_y + src_x; /* move starting point */
|
||||
|
@ -764,7 +765,7 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
|
|||
fb_data *dst;
|
||||
fb_data fg, transparent, replacewithfg;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * src_y + src_x; /* move starting point */
|
||||
|
|
|
@ -384,7 +384,7 @@ void lcd_hline(int x1, int x2, int y)
|
|||
unsigned mask, mask_right;
|
||||
lcd_blockfunc_type *bfunc;
|
||||
|
||||
if (!lcd_clip_viewport_hline(&x1, &x2, &y))
|
||||
if (!clip_viewport_hline(vp, &x1, &x2, &y))
|
||||
return;
|
||||
|
||||
bfunc = lcd_blockfuncs[vp->drawmode];
|
||||
|
@ -411,7 +411,7 @@ void lcd_vline(int x, int y1, int y2)
|
|||
unsigned mask;
|
||||
lcd_blockfunc_type *bfunc;
|
||||
|
||||
if (!lcd_clip_viewport_vline(&x, &y1, &y2))
|
||||
if (!clip_viewport_vline(vp, &x, &y1, &y2))
|
||||
return;
|
||||
|
||||
bfunc = lcd_blockfuncs[vp->drawmode];
|
||||
|
@ -438,7 +438,7 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
unsigned mask, mask_right;
|
||||
lcd_blockfunc_type *bfunc;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, NULL, NULL))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, NULL, NULL))
|
||||
return;
|
||||
|
||||
bfunc = lcd_blockfuncs[vp->drawmode];
|
||||
|
@ -496,7 +496,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
unsigned dst_mask;
|
||||
int drmode = vp->drawmode;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
|
@ -662,7 +662,7 @@ void ICODE_ATTR lcd_bitmap_part(const unsigned char *src, int src_x,
|
|||
int stride_dst;
|
||||
unsigned mask, mask_right;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
stride = LCD_FBSTRIDE(stride, 0); /* convert to no. of bytes */
|
||||
|
|
|
@ -386,7 +386,7 @@ void lcd_hline(int x1, int x2, int y)
|
|||
unsigned mask;
|
||||
lcd_blockfunc_type *bfunc;
|
||||
|
||||
if (!lcd_clip_viewport_hline(&x1, &x2, &y))
|
||||
if (!clip_viewport_hline(vp, &x1, &x2, &y))
|
||||
return;
|
||||
|
||||
width = x2 - x1 + 1;
|
||||
|
@ -411,7 +411,7 @@ void lcd_vline(int x, int y1, int y2)
|
|||
unsigned mask, mask_bottom;
|
||||
lcd_blockfunc_type *bfunc;
|
||||
|
||||
if (!lcd_clip_viewport_vline(&x, &y1, &y2))
|
||||
if (!clip_viewport_vline(vp, &x, &y1, &y2))
|
||||
return;
|
||||
|
||||
bfunc = lcd_blockfuncs[vp->drawmode];
|
||||
|
@ -443,7 +443,7 @@ void lcd_fillrect(int x, int y, int width, int height)
|
|||
lcd_blockfunc_type *bfunc;
|
||||
bool fillopt = false;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, NULL, NULL))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, NULL, NULL))
|
||||
return;
|
||||
|
||||
if (vp->drawmode & DRMODE_INVERSEVID)
|
||||
|
@ -522,7 +522,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
|
|||
unsigned mask, mask_bottom;
|
||||
lcd_blockfunc_type *bfunc;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
|
@ -672,7 +672,7 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
|
|||
int stride_dst;
|
||||
unsigned mask, mask_bottom;
|
||||
|
||||
if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * (src_y >> 2) + src_x; /* move starting point */
|
||||
|
|
|
@ -419,7 +419,7 @@ void LCDFN(hline)(int x1, int x2, int y)
|
|||
unsigned mask;
|
||||
LCDFN(blockfunc_type) *bfunc;
|
||||
|
||||
if (!LCDFN(clip_viewport_hline)(&x1, &x2, &y))
|
||||
if (!clip_viewport_hline(vp, &x1, &x2, &y))
|
||||
return;
|
||||
|
||||
width = x2 - x1 + 1;
|
||||
|
@ -444,7 +444,7 @@ void LCDFN(vline)(int x, int y1, int y2)
|
|||
unsigned mask, mask_bottom;
|
||||
LCDFN(blockfunc_type) *bfunc;
|
||||
|
||||
if (!LCDFN(clip_viewport_vline)(&x, &y1, &y2))
|
||||
if (!clip_viewport_vline(vp, &x, &y1, &y2))
|
||||
return;
|
||||
|
||||
bfunc = LCDFN(blockfuncs)[vp->drawmode];
|
||||
|
@ -478,7 +478,7 @@ void LCDFN(fillrect)(int x, int y, int width, int height)
|
|||
LCDFN(blockfunc_type) *bfunc;
|
||||
bool fillopt = false;
|
||||
|
||||
if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, NULL, NULL))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, NULL, NULL))
|
||||
return;
|
||||
|
||||
if (vp->drawmode & DRMODE_INVERSEVID)
|
||||
|
@ -559,7 +559,7 @@ void ICODE_ATTR LCDFN(mono_bitmap_part)(const unsigned char *src, int src_x,
|
|||
unsigned data, mask, mask_bottom;
|
||||
LCDFN(blockfunc_type) *bfunc;
|
||||
|
||||
if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
|
@ -680,7 +680,7 @@ void ICODE_ATTR LCDFN(bitmap_part)(const FBFN(data) *src, int src_x,
|
|||
int stride_dst;
|
||||
unsigned mask, mask_bottom;
|
||||
|
||||
if (!LCDFN(clip_viewport_rect)(&x, &y, &width, &height, &src_x, &src_y))
|
||||
if (!clip_viewport_rect(vp, &x, &y, &width, &height, &src_x, &src_y))
|
||||
return;
|
||||
|
||||
src += stride * (src_y >> 3) + src_x; /* move starting point */
|
||||
|
|
|
@ -58,15 +58,13 @@ extern void viewport_set_buffer(struct viewport *vp,
|
|||
* In-viewport clipping functions:
|
||||
*
|
||||
* These clip a primitive (pixel, line, rect) given in
|
||||
* viewport-relative coordinates to the current viewport,
|
||||
* viewport-relative coordinates to the specified viewport,
|
||||
* and translate it to screen coordinates. They return
|
||||
* false if the resulting primitive would be off-screen.
|
||||
*/
|
||||
|
||||
static bool LCDFN(clip_viewport_pixel)(int *x, int *y)
|
||||
static inline bool clip_viewport_pixel(struct viewport *vp, int *x, int *y)
|
||||
{
|
||||
struct viewport *vp = LCDFN(current_viewport);
|
||||
|
||||
if (*x < 0 || *x >= vp->width ||
|
||||
*y < 0 || *y >= vp->height)
|
||||
return false;
|
||||
|
@ -76,10 +74,9 @@ static bool LCDFN(clip_viewport_pixel)(int *x, int *y)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool LCDFN(clip_viewport_hline)(int *x1, int *x2, int *y)
|
||||
static inline bool clip_viewport_hline(struct viewport *vp,
|
||||
int *x1, int *x2, int *y)
|
||||
{
|
||||
struct viewport *vp = LCDFN(current_viewport);
|
||||
|
||||
if (*y < 0 || *y > vp->height)
|
||||
return false;
|
||||
|
||||
|
@ -105,10 +102,9 @@ static bool LCDFN(clip_viewport_hline)(int *x1, int *x2, int *y)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool LCDFN(clip_viewport_vline)(int *x, int *y1, int *y2)
|
||||
static inline bool clip_viewport_vline(struct viewport *vp,
|
||||
int *x, int *y1, int *y2)
|
||||
{
|
||||
struct viewport *vp = LCDFN(current_viewport);
|
||||
|
||||
if (*x < 0 || *x > vp->width)
|
||||
return false;
|
||||
|
||||
|
@ -134,11 +130,10 @@ static bool LCDFN(clip_viewport_vline)(int *x, int *y1, int *y2)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool LCDFN(clip_viewport_rect)(int *x, int *y, int *width, int *height,
|
||||
static inline bool clip_viewport_rect(struct viewport *vp,
|
||||
int *x, int *y, int *width, int *height,
|
||||
int *src_x, int *src_y)
|
||||
{
|
||||
struct viewport *vp = LCDFN(current_viewport);
|
||||
|
||||
if (*x < 0) {
|
||||
*width += *x;
|
||||
if (src_x)
|
||||
|
@ -844,7 +839,7 @@ void LCDFN(nine_segment_bmp)(const struct bitmap* bm, int x, int y,
|
|||
void LCDFN(drawpixel)(int x, int y)
|
||||
{
|
||||
struct viewport *vp = LCDFN(current_viewport);
|
||||
if (LCDFN(clip_viewport_pixel(&x, &y)))
|
||||
if (clip_viewport_pixel(vp, &x, &y))
|
||||
{
|
||||
#if LCDM(DEPTH) >= 8
|
||||
LCDFN(fastpixelfunc_type) *pfunc = LCDFN(fastpixelfuncs)[vp->drawmode];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue