From: Thomas Zimmermann <tzimmermann@suse.de>
To: deller@gmx.de, gregkh@linuxfoundation.org, jirislaby@kernel.org,
simona@ffwll.ch
Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-serial@vger.kernel.org, sashiko-reviews@lists.linux.dev,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 4/5] lib/fonts: Add font_glyph_cursor() helper
Date: Fri, 11 Sep 2026 11:25:22 +0200 [thread overview]
Message-ID: <20260911094518.78093-5-tzimmermann@suse.de> (raw)
In-Reply-To: <20260911094518.78093-1-tzimmermann@suse.de>
The new helper font_glyph_cursor() fills a glyph with a cursor pattern.
As with the font_glyph_rotate_*() helpers, the caller has to provide the
output memory.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
include/linux/font.h | 4 +++
lib/fonts/Makefile | 3 ++-
lib/fonts/font_cursor.c | 56 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+), 1 deletion(-)
create mode 100644 lib/fonts/font_cursor.c
diff --git a/include/linux/font.h b/include/linux/font.h
index 5e1cf9830084..be1a26ff8ae9 100644
--- a/include/linux/font.h
+++ b/include/linux/font.h
@@ -109,6 +109,10 @@ const unsigned char *font_data_glyph_buf(font_data_t *fd,
bool font_data_is_equal(font_data_t *lhs, font_data_t *rhs);
int font_data_export(font_data_t *fd, struct console_font *font, unsigned int vpitch);
+/* font_cursor.c */
+void font_glyph_cursor(unsigned int width, unsigned int height,
+ unsigned int from, unsigned int to, unsigned char *out);
+
/* font_rotate.c */
void font_glyph_rotate_90(const unsigned char *glyph, unsigned int width, unsigned int height,
unsigned char *out);
diff --git a/lib/fonts/Makefile b/lib/fonts/Makefile
index 7202a70a56ef..bc08bf8ea3f8 100644
--- a/lib/fonts/Makefile
+++ b/lib/fonts/Makefile
@@ -1,7 +1,8 @@
# SPDX-License-Identifier: GPL-2.0
# Font handling
-font-y := fonts.o
+font-y := fonts.o \
+ font_cursor.o
font-$(CONFIG_FRAMEBUFFER_CONSOLE_ROTATION) += font_rotate.o
# Built-in fonts; sorted by Family-Size in ascending order
diff --git a/lib/fonts/font_cursor.c b/lib/fonts/font_cursor.c
new file mode 100644
index 000000000000..7f4d587669aa
--- /dev/null
+++ b/lib/fonts/font_cursor.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/bug.h>
+#include <linux/export.h>
+#include <linux/string.h>
+
+#include "font.h"
+
+/**
+ * font_glyph_cursor - Create a cursor glyph
+ * @width: The glyph width in bits per scanline
+ * @height: The number of scanlines in the glyph
+ * @start: The first scanline of the cursor block
+ * @end: The first scanline after the cursor block
+ * @out: The cursor-glyph bitmap
+ *
+ * The parameters @width and @height refer to the glyph size. The caller
+ * has to provide the output buffer @out of sufficient size to hold the
+ * cursor glyph. The arguments in @start and @end describe the number of
+ * scanlines occupied by the cursor block; counting from the top of the
+ * glyph. The helper fills these scanlines with a pattern and clears the
+ * remaining scanlines.
+ */
+void font_glyph_cursor(unsigned int width, unsigned int height,
+ unsigned int start, unsigned int end, unsigned char *out)
+{
+ unsigned int pitch = font_glyph_pitch(width);
+ const unsigned char *out_end = out + height * pitch;
+ unsigned int size;
+
+ if (WARN_ON_ONCE(start > height))
+ start = height;
+ if (WARN_ON_ONCE(end > height))
+ end = height;
+
+ if (end < start)
+ end = start;
+
+ /* clear scanlines before cursor block */
+ size = start * pitch;
+ memset(out, 0x00, size);
+ out += size;
+
+ /* set cursor block */
+ size = (end - start) * pitch;
+ memset(out, 0xff, size);
+ out += size;
+
+ /* clear scanlines below cursor block */
+ size = (height - end) * pitch;
+ memset(out, 0x00, size);
+ out += size;
+
+ WARN_ON_ONCE(out != out_end);
+}
+EXPORT_SYMBOL_GPL(font_glyph_cursor);
--
2.55.0
next prev parent reply other threads:[~2026-09-11 9:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 9:25 [PATCH 0/5] fbcon,vgacon,vt: Share helpers for text cursors Thomas Zimmermann
2026-09-11 9:25 ` [PATCH 1/5] vt: Add cursor-size helpers Thomas Zimmermann
2026-09-11 9:55 ` sashiko-bot
2026-09-12 19:01 ` Helge Deller
2026-09-11 9:25 ` [PATCH 2/5] vgacon: Remove trailing whitespaces Thomas Zimmermann
2026-09-11 9:46 ` sashiko-bot
2026-09-11 9:25 ` [PATCH 3/5] vgacon: Use vt_font_cursor_{start,end}() Thomas Zimmermann
2026-09-11 9:58 ` sashiko-bot
2026-09-11 9:25 ` Thomas Zimmermann [this message]
2026-09-11 9:52 ` [PATCH 4/5] lib/fonts: Add font_glyph_cursor() helper sashiko-bot
2026-09-11 9:25 ` [PATCH 5/5] fbcon: Replace fbcon_fill_cursor_mask() with fbcon_cursor_glyph() Thomas Zimmermann
2026-09-11 9:50 ` sashiko-bot
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=20260911094518.78093-5-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=simona@ffwll.ch \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.