video: Split out expression parts into variables

The functions in this file do similar things but not always in the same
way. To make the code easier to read and compare, use a separate 'linenum'
variable in every function. This is then multiplied by the line length to
get the offset within the frame buffer to modify. Also use an 'x' variable
to hold the pixel position within that line. This is multipled by the
pixel size and added to the offset.

Also move the pbytes declaration up a little with the other long lines.

A side effect of splitting out these variables is that they are promoted
to int, i.e. a signed type, from the unsigned short used in the
vidconsole_priv struct. This would be necessary should any of the
variables go negative. At present this can actually happen in
console_putc_xy_2(), if the display width is not a multiple of the
character size (see next patch).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Anatolij Gustschin <agust@denx.de>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
Simon Glass 2020-07-02 21:12:16 -06:00 committed by Bin Meng
parent 6a2ea434ea
commit a254d11dda

View File

@ -59,9 +59,9 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
uint count) uint count)
{ {
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
int pbytes = VNBYTES(vid_priv->bpix);
void *dst; void *dst;
void *src; void *src;
int pbytes = VNBYTES(vid_priv->bpix);
int j; int j;
dst = vid_priv->fb + vid_priv->line_length - dst = vid_priv->fb + vid_priv->line_length -
@ -83,14 +83,15 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent; struct udevice *vid = dev->parent;
struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct video_priv *vid_priv = dev_get_uclass_priv(vid);
uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
int pbytes = VNBYTES(vid_priv->bpix); int pbytes = VNBYTES(vid_priv->bpix);
int i, col; int i, col, x, linenum;
int mask = 0x80; int mask = 0x80;
void *line; void *line;
uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
line = vid_priv->fb + (VID_TO_PIXEL(x_frac) + 1) * linenum = VID_TO_PIXEL(x_frac) + 1;
vid_priv->line_length - (y + 1) * pbytes; x = y + 1;
line = vid_priv->fb + linenum * vid_priv->line_length - x * pbytes;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN; return -EAGAIN;
@ -204,16 +205,15 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent; struct udevice *vid = dev->parent;
struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct video_priv *vid_priv = dev_get_uclass_priv(vid);
int i, row; int pbytes = VNBYTES(vid_priv->bpix);
int i, row, x, linenum;
void *line; void *line;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN; return -EAGAIN;
linenum = vid_priv->ysize - y - 1;
line = vid_priv->fb + (vid_priv->ysize - y - 1) * x = vid_priv->xsize - VID_TO_PIXEL(x_frac) - VIDEO_FONT_WIDTH - 1;
vid_priv->line_length + line = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
(vid_priv->xsize - VID_TO_PIXEL(x_frac) -
VIDEO_FONT_WIDTH - 1) * VNBYTES(vid_priv->bpix);
for (row = 0; row < VIDEO_FONT_HEIGHT; row++) { for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row; unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
@ -312,9 +312,9 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
uint count) uint count)
{ {
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
int pbytes = VNBYTES(vid_priv->bpix);
void *dst; void *dst;
void *src; void *src;
int pbytes = VNBYTES(vid_priv->bpix);
int j; int j;
dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes; dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
@ -334,16 +334,16 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent; struct udevice *vid = dev->parent;
struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct video_priv *vid_priv = dev_get_uclass_priv(vid);
int pbytes = VNBYTES(vid_priv->bpix);
int i, col;
int mask = 0x80;
void *line = vid_priv->fb +
(vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1) *
vid_priv->line_length + y * pbytes;
uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT; uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
int pbytes = VNBYTES(vid_priv->bpix);
int i, col, x;
int mask = 0x80;
void *line;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN; return -EAGAIN;
x = vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1;
line = vid_priv->fb + x * vid_priv->line_length + y * pbytes;
for (col = 0; col < VIDEO_FONT_HEIGHT; col++) { for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
switch (vid_priv->bpix) { switch (vid_priv->bpix) {