* [PATCH 1/5] graphic_utils: Clip to screen boundaries
2024-09-25 14:34 [PATCH 0/5] graphics updates Sascha Hauer
@ 2024-09-25 14:34 ` Sascha Hauer
2024-09-26 5:26 ` Ahmad Fatoum
2024-09-25 14:34 ` [PATCH 2/5] commands: splash: honour line_length Sascha Hauer
` (4 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Sascha Hauer @ 2024-09-25 14:34 UTC (permalink / raw)
To: open list:BAREBOX
Do not render the parts of the image that are outside the screen
boundaries to prevent memory corruptions.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
lib/gui/graphic_utils.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c
index d91a7f3550..93ef1214f9 100644
--- a/lib/gui/graphic_utils.c
+++ b/lib/gui/graphic_utils.c
@@ -229,6 +229,9 @@ void gu_rgba_blend(struct fb_info *info, struct image *img, void* buf, int heigh
line_length = info->line_length;
for (y = 0; y < height; y++) {
+ if (y + starty >= info->yres)
+ break;
+
adr = buf + (y + starty) * line_length +
startx * (info->bits_per_pixel >> 3);
image = img->data + (y * img->width *img_byte_per_pixel);
@@ -236,6 +239,9 @@ void gu_rgba_blend(struct fb_info *info, struct image *img, void* buf, int heigh
for (x = 0; x < width; x++) {
uint8_t *pixel = image;
+ if (x + startx >= info->xres)
+ break;
+
if (is_rgba)
gu_set_rgba_pixel(info, adr, pixel[0], pixel[1],
pixel[2], pixel[3]);
--
2.39.5
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/5] graphic_utils: Clip to screen boundaries
2024-09-25 14:34 ` [PATCH 1/5] graphic_utils: Clip to screen boundaries Sascha Hauer
@ 2024-09-26 5:26 ` Ahmad Fatoum
0 siblings, 0 replies; 14+ messages in thread
From: Ahmad Fatoum @ 2024-09-26 5:26 UTC (permalink / raw)
To: Sascha Hauer, open list:BAREBOX
On 25.09.24 16:34, Sascha Hauer wrote:
> Do not render the parts of the image that are outside the screen
> boundaries to prevent memory corruptions.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> lib/gui/graphic_utils.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c
> index d91a7f3550..93ef1214f9 100644
> --- a/lib/gui/graphic_utils.c
> +++ b/lib/gui/graphic_utils.c
> @@ -229,6 +229,9 @@ void gu_rgba_blend(struct fb_info *info, struct image *img, void* buf, int heigh
> line_length = info->line_length;
>
> for (y = 0; y < height; y++) {
> + if (y + starty >= info->yres)
> + break;
> +
> adr = buf + (y + starty) * line_length +
> startx * (info->bits_per_pixel >> 3);
> image = img->data + (y * img->width *img_byte_per_pixel);
> @@ -236,6 +239,9 @@ void gu_rgba_blend(struct fb_info *info, struct image *img, void* buf, int heigh
> for (x = 0; x < width; x++) {
> uint8_t *pixel = image;
>
> + if (x + startx >= info->xres)
> + break;
> +
> if (is_rgba)
> gu_set_rgba_pixel(info, adr, pixel[0], pixel[1],
> pixel[2], pixel[3]);
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 2/5] commands: splash: honour line_length
2024-09-25 14:34 [PATCH 0/5] graphics updates Sascha Hauer
2024-09-25 14:34 ` [PATCH 1/5] graphic_utils: Clip to screen boundaries Sascha Hauer
@ 2024-09-25 14:34 ` Sascha Hauer
2024-09-26 5:31 ` Ahmad Fatoum
2024-09-25 14:34 ` [PATCH 3/5] gui: fix alpha blend Sascha Hauer
` (3 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Sascha Hauer @ 2024-09-25 14:34 UTC (permalink / raw)
To: open list:BAREBOX
the splash command has an option for setting a background colour. This
doesn't always fill the whole screen as expected.
struct fb_info has a line_length field that specifies the length in
bytes of a single line. That length may be bigger than the actually
visible area as specified by xres. In this case filling the area as
calculated by xres*yres fills the invisible pixels between xres and
line_length, but it doesn't fill the whole visible area. Fix this by
iterating over the lines, filling the visible area of each line.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/splash.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/commands/splash.c b/commands/splash.c
index 2eb7c5dc39..74754392e2 100644
--- a/commands/splash.c
+++ b/commands/splash.c
@@ -62,9 +62,13 @@ static int do_splash(int argc, char *argv[])
buf = gui_screen_render_buffer(sc);
- if (do_bg)
- gu_memset_pixel(sc->info, buf, bg_color,
- sc->s.width * sc->s.height);
+ if (do_bg) {
+ int y;
+ for (y = 0; y < sc->s.height; y++) {
+ gu_memset_pixel(sc->info, buf + sc->info->line_length * y,
+ bg_color, sc->s.width);
+ }
+ }
ret = image_renderer_file(sc, &s, image_file);
if (ret > 0)
--
2.39.5
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/5] commands: splash: honour line_length
2024-09-25 14:34 ` [PATCH 2/5] commands: splash: honour line_length Sascha Hauer
@ 2024-09-26 5:31 ` Ahmad Fatoum
2024-09-26 6:48 ` Sascha Hauer
0 siblings, 1 reply; 14+ messages in thread
From: Ahmad Fatoum @ 2024-09-26 5:31 UTC (permalink / raw)
To: Sascha Hauer, open list:BAREBOX
On 25.09.24 16:34, Sascha Hauer wrote:
> the splash command has an option for setting a background colour. This
> doesn't always fill the whole screen as expected.
>
> struct fb_info has a line_length field that specifies the length in
> bytes of a single line. That length may be bigger than the actually
> visible area as specified by xres. In this case filling the area as
> calculated by xres*yres fills the invisible pixels between xres and
> line_length, but it doesn't fill the whole visible area. Fix this by
> iterating over the lines, filling the visible area of each line.
I have trouble understanding this. What is line_length if not
bytes per pixel multiplied by xres?
As gu_memset_pixel already takes bytes (bits) per pixel into account,
this looked correct to me before your change?
Thanks,
Ahmad
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> commands/splash.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/commands/splash.c b/commands/splash.c
> index 2eb7c5dc39..74754392e2 100644
> --- a/commands/splash.c
> +++ b/commands/splash.c
> @@ -62,9 +62,13 @@ static int do_splash(int argc, char *argv[])
>
> buf = gui_screen_render_buffer(sc);
>
> - if (do_bg)
> - gu_memset_pixel(sc->info, buf, bg_color,
> - sc->s.width * sc->s.height);
> + if (do_bg) {
> + int y;
> + for (y = 0; y < sc->s.height; y++) {
> + gu_memset_pixel(sc->info, buf + sc->info->line_length * y,
> + bg_color, sc->s.width);
> + }
> + }
>
> ret = image_renderer_file(sc, &s, image_file);
> if (ret > 0)
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/5] commands: splash: honour line_length
2024-09-26 5:31 ` Ahmad Fatoum
@ 2024-09-26 6:48 ` Sascha Hauer
0 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2024-09-26 6:48 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: open list:BAREBOX
On Thu, Sep 26, 2024 at 07:31:49AM +0200, Ahmad Fatoum wrote:
> On 25.09.24 16:34, Sascha Hauer wrote:
> > the splash command has an option for setting a background colour. This
> > doesn't always fill the whole screen as expected.
> >
> > struct fb_info has a line_length field that specifies the length in
> > bytes of a single line. That length may be bigger than the actually
> > visible area as specified by xres. In this case filling the area as
> > calculated by xres*yres fills the invisible pixels between xres and
> > line_length, but it doesn't fill the whole visible area. Fix this by
> > iterating over the lines, filling the visible area of each line.
>
> I have trouble understanding this. What is line_length if not
> bytes per pixel multiplied by xres?
Some hardware might have alignment restrictions on the address where the
new line starts. In that case line_length is longer than xres*bpp. Also
the picture in the framebuffer might be wider than the visible area.
In my case I allocate a framebuffer for the biggest resolution the
monitor supports. When changing the resolution to a smaller one I can
keep the framebuffer and still show something useful by keeping
line_length and just adjusting xres.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 3/5] gui: fix alpha blend
2024-09-25 14:34 [PATCH 0/5] graphics updates Sascha Hauer
2024-09-25 14:34 ` [PATCH 1/5] graphic_utils: Clip to screen boundaries Sascha Hauer
2024-09-25 14:34 ` [PATCH 2/5] commands: splash: honour line_length Sascha Hauer
@ 2024-09-25 14:34 ` Sascha Hauer
2024-09-26 5:33 ` Ahmad Fatoum
2024-09-25 14:34 ` [PATCH 4/5] fbconsole: make background pixels transparent Sascha Hauer
` (2 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Sascha Hauer @ 2024-09-25 14:34 UTC (permalink / raw)
To: open list:BAREBOX
gu_set_rgba_pixel() can work in two modes. When the plane does have an
alpha channel then it just sets the RGBA values. When the plane doesn't
have an alpha channel then it does pseudo alpha blending of the previous
pixel value.
At least this was the intention. The function sets the alpha value
correctly only when it's not fully opaque. Fix this by always setting
the alpha channel when it exists.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
lib/gui/graphic_utils.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c
index 93ef1214f9..d9f90f3d2e 100644
--- a/lib/gui/graphic_utils.c
+++ b/lib/gui/graphic_utils.c
@@ -187,24 +187,22 @@ void gu_set_rgba_pixel(struct fb_info *info, void *adr, u8 r, u8 g, u8 b, u8 a)
if (!a)
return;
- if (a != 0xff) {
- if (info->transp.length) {
- px |= (a >> (8 - info->transp.length)) << info->transp.offset;
- } else {
- u8 sr = 0;
- u8 sg = 0;
- u8 sb = 0;
+ if (info->transp.length) {
+ px |= (a >> (8 - info->transp.length)) << info->transp.offset;
+ } else if (a != 0xff) {
+ u8 sr = 0;
+ u8 sg = 0;
+ u8 sb = 0;
- get_rgb_pixel(info, adr, &sr, &sg, &sb);
+ get_rgb_pixel(info, adr, &sr, &sg, &sb);
- r = alpha_mux(sr, r, a);
- g = alpha_mux(sg, g, a);
- b = alpha_mux(sb, b, a);
+ r = alpha_mux(sr, r, a);
+ g = alpha_mux(sg, g, a);
+ b = alpha_mux(sb, b, a);
- gu_set_rgb_pixel(info, adr, r, g, b);
+ gu_set_rgb_pixel(info, adr, r, g, b);
- return;
- }
+ return;
}
px |= (r >> (8 - info->red.length)) << info->red.offset |
--
2.39.5
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 3/5] gui: fix alpha blend
2024-09-25 14:34 ` [PATCH 3/5] gui: fix alpha blend Sascha Hauer
@ 2024-09-26 5:33 ` Ahmad Fatoum
0 siblings, 0 replies; 14+ messages in thread
From: Ahmad Fatoum @ 2024-09-26 5:33 UTC (permalink / raw)
To: Sascha Hauer, open list:BAREBOX
On 25.09.24 16:34, Sascha Hauer wrote:
> gu_set_rgba_pixel() can work in two modes. When the plane does have an
> alpha channel then it just sets the RGBA values. When the plane doesn't
> have an alpha channel then it does pseudo alpha blending of the previous
> pixel value.
>
> At least this was the intention. The function sets the alpha value
> correctly only when it's not fully opaque. Fix this by always setting
> the alpha channel when it exists.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> lib/gui/graphic_utils.c | 26 ++++++++++++--------------
> 1 file changed, 12 insertions(+), 14 deletions(-)
>
> diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c
> index 93ef1214f9..d9f90f3d2e 100644
> --- a/lib/gui/graphic_utils.c
> +++ b/lib/gui/graphic_utils.c
> @@ -187,24 +187,22 @@ void gu_set_rgba_pixel(struct fb_info *info, void *adr, u8 r, u8 g, u8 b, u8 a)
> if (!a)
> return;
>
> - if (a != 0xff) {
> - if (info->transp.length) {
> - px |= (a >> (8 - info->transp.length)) << info->transp.offset;
> - } else {
> - u8 sr = 0;
> - u8 sg = 0;
> - u8 sb = 0;
> + if (info->transp.length) {
> + px |= (a >> (8 - info->transp.length)) << info->transp.offset;
> + } else if (a != 0xff) {
> + u8 sr = 0;
> + u8 sg = 0;
> + u8 sb = 0;
>
> - get_rgb_pixel(info, adr, &sr, &sg, &sb);
> + get_rgb_pixel(info, adr, &sr, &sg, &sb);
>
> - r = alpha_mux(sr, r, a);
> - g = alpha_mux(sg, g, a);
> - b = alpha_mux(sb, b, a);
> + r = alpha_mux(sr, r, a);
> + g = alpha_mux(sg, g, a);
> + b = alpha_mux(sb, b, a);
>
> - gu_set_rgb_pixel(info, adr, r, g, b);
> + gu_set_rgb_pixel(info, adr, r, g, b);
>
> - return;
> - }
> + return;
> }
>
> px |= (r >> (8 - info->red.length)) << info->red.offset |
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 4/5] fbconsole: make background pixels transparent
2024-09-25 14:34 [PATCH 0/5] graphics updates Sascha Hauer
` (2 preceding siblings ...)
2024-09-25 14:34 ` [PATCH 3/5] gui: fix alpha blend Sascha Hauer
@ 2024-09-25 14:34 ` Sascha Hauer
2024-09-26 5:38 ` Ahmad Fatoum
2024-09-25 14:34 ` [PATCH 5/5] fbconsole: actually store rows/cols Sascha Hauer
2024-09-27 10:38 ` [PATCH 0/5] graphics updates Sascha Hauer
5 siblings, 1 reply; 14+ messages in thread
From: Sascha Hauer @ 2024-09-25 14:34 UTC (permalink / raw)
To: open list:BAREBOX
When we have a background image we want the background to actually shine
through, so set the alpha value of the background to transparent and not
opaque.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/video/fbconsole.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index cec1afec56..d3615bc07f 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -139,7 +139,7 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
color = gu_rgb_to_pixel(priv->fb, rgb->r, rgb->g, rgb->b, 0xff);
rgb = &colors[bgcolor];
- bgcolor = gu_rgb_to_pixel(priv->fb, rgb->r, rgb->g, rgb->b, 0xff);
+ bgcolor = gu_rgb_to_pixel(priv->fb, rgb->r, rgb->g, rgb->b, 0x0);
for (i = 0; i < priv->font->height; i++) {
uint8_t mask = 0x80;
--
2.39.5
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/5] fbconsole: make background pixels transparent
2024-09-25 14:34 ` [PATCH 4/5] fbconsole: make background pixels transparent Sascha Hauer
@ 2024-09-26 5:38 ` Ahmad Fatoum
2024-09-26 7:02 ` Sascha Hauer
0 siblings, 1 reply; 14+ messages in thread
From: Ahmad Fatoum @ 2024-09-26 5:38 UTC (permalink / raw)
To: Sascha Hauer, open list:BAREBOX
On 25.09.24 16:34, Sascha Hauer wrote:
> When we have a background image we want the background to actually shine
> through, so set the alpha value of the background to transparent and not
> opaque.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
I wonder if this could cause a slow down for framebuffers with no alpha channel,
because it will read the framebuffer on every pixel write for alpha blending
purposes, even if ultimately unnecessary?
> ---
> drivers/video/fbconsole.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> index cec1afec56..d3615bc07f 100644
> --- a/drivers/video/fbconsole.c
> +++ b/drivers/video/fbconsole.c
> @@ -139,7 +139,7 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
> color = gu_rgb_to_pixel(priv->fb, rgb->r, rgb->g, rgb->b, 0xff);
>
> rgb = &colors[bgcolor];
> - bgcolor = gu_rgb_to_pixel(priv->fb, rgb->r, rgb->g, rgb->b, 0xff);
> + bgcolor = gu_rgb_to_pixel(priv->fb, rgb->r, rgb->g, rgb->b, 0x0);
>
> for (i = 0; i < priv->font->height; i++) {
> uint8_t mask = 0x80;
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/5] fbconsole: make background pixels transparent
2024-09-26 5:38 ` Ahmad Fatoum
@ 2024-09-26 7:02 ` Sascha Hauer
0 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2024-09-26 7:02 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: open list:BAREBOX
On Thu, Sep 26, 2024 at 07:38:23AM +0200, Ahmad Fatoum wrote:
> On 25.09.24 16:34, Sascha Hauer wrote:
> > When we have a background image we want the background to actually shine
> > through, so set the alpha value of the background to transparent and not
> > opaque.
> >
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>
> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>
> I wonder if this could cause a slow down for framebuffers with no alpha channel,
> because it will read the framebuffer on every pixel write for alpha blending
> purposes, even if ultimately unnecessary?
A pixel is drawn with gu_set_pixel() which doesn't read at all.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 5/5] fbconsole: actually store rows/cols
2024-09-25 14:34 [PATCH 0/5] graphics updates Sascha Hauer
` (3 preceding siblings ...)
2024-09-25 14:34 ` [PATCH 4/5] fbconsole: make background pixels transparent Sascha Hauer
@ 2024-09-25 14:34 ` Sascha Hauer
2024-09-26 5:39 ` Ahmad Fatoum
2024-09-27 10:38 ` [PATCH 0/5] graphics updates Sascha Hauer
5 siblings, 1 reply; 14+ messages in thread
From: Sascha Hauer @ 2024-09-25 14:34 UTC (permalink / raw)
To: open list:BAREBOX
struct fbc_priv has rows and cols fields, but they do not actually
store the rows and columns, but instead the actual values minus one.
Change this to make the code better understandable.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/video/fbconsole.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index d3615bc07f..01a091d07a 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -200,7 +200,7 @@ static void printchar(struct fbc_priv *priv, int c)
if (priv->x > 0) {
priv->x--;
} else if (priv->y > 0) {
- priv->x = priv->cols;
+ priv->x = priv->cols - 1;
priv->y--;
}
break;
@@ -226,26 +226,26 @@ static void printchar(struct fbc_priv *priv, int c)
priv->font->width, priv->font->height);
priv->x++;
- if (priv->x > priv->cols) {
+ if (priv->x >= priv->cols) {
priv->y++;
priv->x = 0;
}
}
- if (priv->y > priv->rows) {
+ if (priv->y >= priv->rows) {
void *buf;
void *adr;
u32 line_length = priv->fb->line_length;
int line_height = line_length * priv->font->height;
int width = priv->fb->xres - priv->margin.left - priv->margin.right;
- int height = (priv->rows + 1) * priv->font->height;
+ int height = priv->rows * priv->font->height;
buf = gui_screen_render_buffer(priv->sc);
adr = buf + priv->margin.top * line_length;
if (!priv->margin.left && !priv->margin.right) {
- memcpy(adr, adr + line_height, line_height * priv->rows);
- memset(adr + line_height * priv->rows, 0, line_height);
+ memcpy(adr, adr + line_height, line_height * (priv->rows - 1));
+ memset(adr + line_height * (priv->rows - 1), 0, line_height);
} else {
int bpp = priv->fb->bits_per_pixel >> 3;
int y;
@@ -264,7 +264,7 @@ static void printchar(struct fbc_priv *priv, int c)
gu_screen_blit_area(priv->sc, priv->margin.left, priv->margin.top,
width, height);
- priv->y = priv->rows;
+ priv->y = priv->rows - 1;
}
show_cursor(priv, priv->x, priv->y);
@@ -364,10 +364,10 @@ static void fbc_parse_csi(struct fbc_priv *priv)
show_cursor(priv, priv->x, priv->y);
pos = simple_strtoul(priv->csi, &end, 10);
- priv->y = clamp(pos - 1, 0, (int) priv->rows);
+ priv->y = clamp(pos - 1, 0, (int) priv->rows - 1);
pos = simple_strtoul(end + 1, NULL, 10);
- priv->x = clamp(pos - 1, 0, (int) priv->cols);
+ priv->x = clamp(pos - 1, 0, (int) priv->cols - 1);
show_cursor(priv, priv->x, priv->y);
case 'K':
@@ -469,8 +469,8 @@ static int setup_font(struct fbc_priv *priv)
priv->font = font;
- priv->rows = height / priv->font->height - 1;
- priv->cols = width / priv->font->width - 1;
+ priv->rows = height / priv->font->height;
+ priv->cols = width / priv->font->width;
return 0;
}
@@ -495,7 +495,7 @@ static int fbc_open(struct console_device *cdev)
priv->state = LIT;
dev_info(priv->cdev.dev, "framebuffer console %dx%d activated\n",
- priv->cols + 1, priv->rows + 1);
+ priv->cols, priv->rows);
priv->active = true;
--
2.39.5
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 5/5] fbconsole: actually store rows/cols
2024-09-25 14:34 ` [PATCH 5/5] fbconsole: actually store rows/cols Sascha Hauer
@ 2024-09-26 5:39 ` Ahmad Fatoum
0 siblings, 0 replies; 14+ messages in thread
From: Ahmad Fatoum @ 2024-09-26 5:39 UTC (permalink / raw)
To: Sascha Hauer, open list:BAREBOX
On 25.09.24 16:34, Sascha Hauer wrote:
> struct fbc_priv has rows and cols fields, but they do not actually
> store the rows and columns, but instead the actual values minus one.
> Change this to make the code better understandable.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/video/fbconsole.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> index d3615bc07f..01a091d07a 100644
> --- a/drivers/video/fbconsole.c
> +++ b/drivers/video/fbconsole.c
> @@ -200,7 +200,7 @@ static void printchar(struct fbc_priv *priv, int c)
> if (priv->x > 0) {
> priv->x--;
> } else if (priv->y > 0) {
> - priv->x = priv->cols;
> + priv->x = priv->cols - 1;
> priv->y--;
> }
> break;
> @@ -226,26 +226,26 @@ static void printchar(struct fbc_priv *priv, int c)
> priv->font->width, priv->font->height);
>
> priv->x++;
> - if (priv->x > priv->cols) {
> + if (priv->x >= priv->cols) {
> priv->y++;
> priv->x = 0;
> }
> }
>
> - if (priv->y > priv->rows) {
> + if (priv->y >= priv->rows) {
> void *buf;
> void *adr;
> u32 line_length = priv->fb->line_length;
> int line_height = line_length * priv->font->height;
> int width = priv->fb->xres - priv->margin.left - priv->margin.right;
> - int height = (priv->rows + 1) * priv->font->height;
> + int height = priv->rows * priv->font->height;
>
> buf = gui_screen_render_buffer(priv->sc);
> adr = buf + priv->margin.top * line_length;
>
> if (!priv->margin.left && !priv->margin.right) {
> - memcpy(adr, adr + line_height, line_height * priv->rows);
> - memset(adr + line_height * priv->rows, 0, line_height);
> + memcpy(adr, adr + line_height, line_height * (priv->rows - 1));
> + memset(adr + line_height * (priv->rows - 1), 0, line_height);
> } else {
> int bpp = priv->fb->bits_per_pixel >> 3;
> int y;
> @@ -264,7 +264,7 @@ static void printchar(struct fbc_priv *priv, int c)
>
> gu_screen_blit_area(priv->sc, priv->margin.left, priv->margin.top,
> width, height);
> - priv->y = priv->rows;
> + priv->y = priv->rows - 1;
> }
>
> show_cursor(priv, priv->x, priv->y);
> @@ -364,10 +364,10 @@ static void fbc_parse_csi(struct fbc_priv *priv)
> show_cursor(priv, priv->x, priv->y);
>
> pos = simple_strtoul(priv->csi, &end, 10);
> - priv->y = clamp(pos - 1, 0, (int) priv->rows);
> + priv->y = clamp(pos - 1, 0, (int) priv->rows - 1);
>
> pos = simple_strtoul(end + 1, NULL, 10);
> - priv->x = clamp(pos - 1, 0, (int) priv->cols);
> + priv->x = clamp(pos - 1, 0, (int) priv->cols - 1);
>
> show_cursor(priv, priv->x, priv->y);
> case 'K':
> @@ -469,8 +469,8 @@ static int setup_font(struct fbc_priv *priv)
>
> priv->font = font;
>
> - priv->rows = height / priv->font->height - 1;
> - priv->cols = width / priv->font->width - 1;
> + priv->rows = height / priv->font->height;
> + priv->cols = width / priv->font->width;
>
> return 0;
> }
> @@ -495,7 +495,7 @@ static int fbc_open(struct console_device *cdev)
> priv->state = LIT;
>
> dev_info(priv->cdev.dev, "framebuffer console %dx%d activated\n",
> - priv->cols + 1, priv->rows + 1);
> + priv->cols, priv->rows);
>
> priv->active = true;
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 0/5] graphics updates
2024-09-25 14:34 [PATCH 0/5] graphics updates Sascha Hauer
` (4 preceding siblings ...)
2024-09-25 14:34 ` [PATCH 5/5] fbconsole: actually store rows/cols Sascha Hauer
@ 2024-09-27 10:38 ` Sascha Hauer
5 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2024-09-27 10:38 UTC (permalink / raw)
To: open list:BAREBOX, Sascha Hauer
On Wed, 25 Sep 2024 16:34:48 +0200, Sascha Hauer wrote:
> This series fixes some bugs and oddities in the graphics routines I came
> across when testing the upcoming Rockchip VOP2 driver.
>
>
Applied, thanks!
[1/5] graphic_utils: Clip to screen boundaries
https://git.pengutronix.de/cgit/barebox/commit/?id=8214fb8caf3b (link may not be stable)
[2/5] commands: splash: honour line_length
https://git.pengutronix.de/cgit/barebox/commit/?id=697fe6f432c6 (link may not be stable)
[3/5] gui: fix alpha blend
https://git.pengutronix.de/cgit/barebox/commit/?id=602707db639f (link may not be stable)
[4/5] fbconsole: make background pixels transparent
https://git.pengutronix.de/cgit/barebox/commit/?id=b471540e6def (link may not be stable)
[5/5] fbconsole: actually store rows/cols
https://git.pengutronix.de/cgit/barebox/commit/?id=4f8f69ade14f (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 14+ messages in thread