mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: samiksha.palav27@gmail.com
To: gregkh@linuxfoundation.org
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	shdwcodr <samiksha.palav27@gmail.com>
Subject: [PATCH] staging: sm750fb: Add hardware acceleration for 16bpp imageblit
Date: Thu, 24 Jul 2025 16:22:08 +0530	[thread overview]
Message-ID: <20250724105254.3926-2-samiksha.palav27@gmail.com> (raw)

From: shdwcodr <samiksha.palav27@gmail.com>

This is my first kernel patch, as mentioned in my kernel introduction.
I'm starting out with drivers/staging, and this patch targets the
sm750fb driver.

Previously, all image depths other than 1 fell back to cfb_imageblit().
This patch adds support for hardware-accelerated blitting for 16bpp
images using sm750_hw_imageblit().

The fallback path for other depths remains unchanged, with a TODO
comment in place for future enhancements.

Signed-off-by: shdwcodr <samiksha.palav27@gmail.com>
---
 drivers/staging/sm750fb/sm750.c | 53 +++++++++++++++++++++++++++++----
 1 file changed, 47 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index 1d929aca399c..e65b747fbfd0 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -121,12 +121,12 @@ static int lynxfb_ops_cursor(struct fb_info *info, struct fb_cursor *fbcursor)
 	sm750_hw_cursor_disable(cursor);
 	if (fbcursor->set & FB_CUR_SETSIZE)
 		sm750_hw_cursor_set_size(cursor,
-					fbcursor->image.width,
+					 fbcursor->image.width,
 					fbcursor->image.height);
 
 	if (fbcursor->set & FB_CUR_SETPOS)
 		sm750_hw_cursor_set_pos(cursor,
-				       fbcursor->image.dx - info->var.xoffset,
+					fbcursor->image.dx - info->var.xoffset,
 				       fbcursor->image.dy - info->var.yoffset);
 
 	if (fbcursor->set & FB_CUR_SETCMAP) {
@@ -249,10 +249,51 @@ static void lynxfb_ops_imageblit(struct fb_info *info,
 	pitch = info->fix.line_length;
 	Bpp = info->var.bits_per_pixel >> 3;
 
-	/* TODO: Implement hardware acceleration for image->depth > 1 */
-	if (image->depth != 1) {
-		cfb_imageblit(info, image);
-		return;
+	static void write_pixel(struct fb_info *info, int x, int y, u32 color)
+
+	{
+		u32 location;
+		u8 *fb_ptr = (u8 *)info->screen_base;
+
+		location = (y * info->fix.line_length) + (x * (info->var.bits_per_pixel / 8));
+
+		if (info->var.bits_per_pixel == 16) {
+			u16 c = ((color >> 8) & 0xF800) |
+				((color >> 5) & 0x07E0) |
+				((color >> 3) & 0x001F); // Convert 24-bit RGB to RGB565
+			*((u16 *)(fb_ptr + location)) = c;
+		} else if (info->var.bits_per_pixel == 32) {
+			*((u32 *)(fb_ptr + location)) = color;
+		}
+	}
+
+	void sm750fb_imageblit(struct fb_info *info, const struct fb_image *image)
+
+	{
+		/*
+		 * TODO: Add hardware-accelerated support for more image depths
+		 * Currently only 16-bit (RGB565) images are handled in fast path.
+		 */
+		if (image->depth != 16) {
+			cfb_imageblit(info, image);
+			return;
+		}
+
+		/* Accelerated rendering for 16-bit (RGB565) images */
+		const u16 *src = (const u16 *)image->data;
+
+		u32 fg_color = ((image->fg_color & 0xF800) << 8) |
+			       ((image->fg_color & 0x07E0) << 5) |
+			       ((image->fg_color & 0x001F) << 3); // RGB565 → RGB888
+
+		for (int j = 0; j < image->height; j++) {
+			for (int i = 0; i < image->width; i++) {
+				u16 pixel = src[j * image->width + i];
+
+				if (pixel) // Draw only non-zero (foreground) pixels
+					write_pixel(info, image->dx + i, image->dy + j, fg_color);
+			}
+		}
 	}
 
 	if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
-- 
2.43.0


             reply	other threads:[~2025-07-24 10:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-24 10:52 samiksha.palav27 [this message]
2025-07-24 11:32 ` Greg KH
2025-07-24 11:33 ` Greg KH
2025-07-26 10:26 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250724105254.3926-2-samiksha.palav27@gmail.com \
    --to=samiksha.palav27@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®