diff mbox series

[RESEND,v3,05/26] video: Split out expression parts into variables

Message ID 20200702211204.RESEND.v3.5.If9aaebbcc4389b38b66478fc3dd0aaff49c3105e@changeid
State Superseded
Headers show
Series x86: video: Speed up the framebuffer | expand

Commit Message

Simon Glass July 3, 2020, 3:12 a.m. UTC
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 at chromium.org>
Reviewed-by: Anatolij Gustschin <agust at denx.de>
---

(no changes since v1)

 drivers/video/console_rotate.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
index b485255598..8bb05ae02c 100644
--- a/drivers/video/console_rotate.c
+++ b/drivers/video/console_rotate.c
@@ -59,9 +59,9 @@  static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
 			       uint count)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+	int pbytes = VNBYTES(vid_priv->bpix);
 	void *dst;
 	void *src;
-	int pbytes = VNBYTES(vid_priv->bpix);
 	int j;
 
 	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 udevice *vid = dev->parent;
 	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 i, col;
+	int i, col, x, linenum;
 	int mask = 0x80;
 	void *line;
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
 
-	line = vid_priv->fb + (VID_TO_PIXEL(x_frac) + 1) *
-			vid_priv->line_length - (y + 1) * pbytes;
+	linenum = VID_TO_PIXEL(x_frac) + 1;
+	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)
 		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 udevice *vid = dev->parent;
 	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;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
-
-	line = vid_priv->fb + (vid_priv->ysize - y - 1) *
-			vid_priv->line_length +
-			(vid_priv->xsize - VID_TO_PIXEL(x_frac) -
-			VIDEO_FONT_WIDTH - 1) * VNBYTES(vid_priv->bpix);
+	linenum = vid_priv->ysize - y - 1;
+	x = vid_priv->xsize - VID_TO_PIXEL(x_frac) - VIDEO_FONT_WIDTH - 1;
+	line = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
 
 	for (row = 0; row < 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)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+	int pbytes = VNBYTES(vid_priv->bpix);
 	void *dst;
 	void *src;
-	int pbytes = VNBYTES(vid_priv->bpix);
 	int j;
 
 	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 udevice *vid = dev->parent;
 	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 i, col;
+	int i, col, x;
 	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;
+	void *line;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		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++) {
 		switch (vid_priv->bpix) {