fbcon: Clean up glyph handling on redraws
Subsystems (3)
Thomas Zimmermann
maintainerv3 cover fbcon: Clean up glyph handling on redraws
Fbcon's drawing functions open-code much of the glyph handling. Use font helpers instead. Makes fbcon more consistent and easier to understand.
Patch 1 updates fbcon to use unsigned char for glyph buffers. This is consistent with the font code and font_data_t.
Patches 2 and 3 update font rotation to return rotated glyphs as font_data_t. A rotated font can now use the same interfaces as the unrotated source font. Fbcon uses this to ref count the rotated font's buffer.
Patches 4 to 6 update various parts of fbcon to use font helpers instead of open-coding access to font_data_t. Having the rotated font as font_data_t makes this convenient.
Tested with fbcon on DRM's bochs driver (qemu).
v3:
- replace remaining instances of kfree() with font_data_put()
- upcast vc_font.data to font_data_t for glyph lookup
- fix fallback in ccw_cursor()
v2:
- resolve merge conflicts in fbcon
- fix typos in commit descriptions
Thomas Zimmermann (6):
fbcon: Use unsigned char for glyph data
lib/fonts: Provide internal helpers for allocating font_data_t lib/fonts, fbcon: Use font_data_t for rotated fonts
fbcon: Refactor size calculation for cursor buffers
fbcon: Look up glyphs using the font interface
fbcon: Handle characters with no glyph defined in a consistent way
drivers/video/fbdev/core/bitblit.c | 83 +++++++++++++++---------- drivers/video/fbdev/core/fbcon.c | 12 ++-- drivers/video/fbdev/core/fbcon.h | 5 +- drivers/video/fbdev/core/fbcon_ccw.c | 56 +++++++++++------ drivers/video/fbdev/core/fbcon_cw.c | 57 ++++++++++------- drivers/video/fbdev/core/fbcon_rotate.c | 19 +++--- drivers/video/fbdev/core/fbcon_ud.c | 77 +++++++++++++++-------- include/linux/font.h | 5 +- lib/fonts/font.h | 12 ++++ lib/fonts/font_rotate.c | 39 +++++------- lib/fonts/fonts.c | 63 ++++++++++++------- 11 files changed, 263 insertions(+), 165 deletions(-)
base-commit: 579369fbe7227f6b00acc883ac90606a5266932a
prerequisite-patch-id: c67e5d886a47b7d0266d81100837557fda34cb24
prerequisite-patch-id: a5a973e527c88a5b47053d7a72aefe0b550197cb
prerequisite-patch-id: b9adc9622920a3e70168e672c2c92795b3e3a106
prerequisite-patch-id: 5030de433a01c2e99056cadb676a8e2ba35f055a
Signature · 1 line
2.56.1
Thomas Zimmermann
maintainerPATCH v3 1/6 fbcon: Use unsigned char for glyph data
Represent glyph data as unsigned char, as done by font_data_t. Convert all related code. Also declare source buffers with glyph data as const because internal fonts reside in read-only memory. Avoid writing them.
We still use char for glyph data in struct fb_image. The type is part of the kernel uAPI and therefore cannot be changed. Fall back to type casting in this case.
Destination buffers for font drawing are still u8. This is framebuffer memory provided by graphics hardware.
--- drivers/video/fbdev/core/bitblit.c | 25 ++++++++++++++----------- drivers/video/fbdev/core/fbcon.h | 4 ++-- drivers/video/fbdev/core/fbcon_ccw.c | 22 ++++++++++++---------- drivers/video/fbdev/core/fbcon_cw.c | 22 ++++++++++++---------- drivers/video/fbdev/core/fbcon_ud.c | 28 +++++++++++++++------------- 5 files changed, 55 insertions(+), 46 deletions(-)
drivers/video/fbdev/core/bitblit.c +14 -11
@@ -23,12 +23,13 @@/* * Accelerated handlers. */ -static void update_attr (u8 *dst,const u8 *src,int attribute,struct vc_data *vc) +static void update_attr (unsigned char *dst,const unsigned char *src,int attribute, +struct vc_data *vc) {int i, offset = (vc->vc_font.height <10 ) ?1 :2 ;int width =DIV_ROUND_UP (vc->vc_font.width,8 );unsigned int cellsize = vc->vc_font.height * width; -u8 c; +unsigned char c; offset = cellsize - (offset * width);for (i =0 ; i < cellsize; i++) {
@@ -76,12 +77,13 @@ static void bit_clear(struct vc_data *vc, struct fb_info *info, int sy,static inline void bit_putcs_aligned (struct vc_data *vc,struct fb_info *info,const u16 *s,u32 attr,u32 cnt,u32 d_pitch,u32 s_pitch,u32 cellsize, -struct fb_image *image,u8 *buf,u8 *dst) +struct fb_image *image, +unsigned char *buf,u8 *dst) {u16 charmask = vc->vc_hi_font_mask ?0x1ff :0xff ;unsigned int charcnt = vc->vc_font.charcount;u32 idx = vc->vc_font.width >>3 ; -const u8 *src; +const unsigned char *src;while (cnt--) {u16 ch =scr_readw (s++) & charmask;
@@ -112,15 +114,15 @@ static inline void bit_putcs_unaligned(struct vc_data *vc, struct fb_info *info, const u16 *s, u32 attr, u32 cnt, u32 d_pitch, u32 s_pitch, u32 cellsize, - struct fb_image *image, u8 *buf, - u8 *dst) + struct fb_image *image, + unsigned char *buf, u8 *dst) { u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;unsigned int charcnt = vc->vc_font.charcount;u32 shift_low =0 , mod = vc->vc_font.width %8 ;u32 shift_high =8 ;u32 idx = vc->vc_font.width >>3 ; -const u8 *src; +const unsigned char *src;while (cnt--) {u16 ch =scr_readw (s++) & charmask;
@@ -161,7 +163,8 @@ static void bit_putcs(struct vc_data *vc, struct fb_info *info,u32 buf_align = info->pixmap.buf_align -1 ;u32 mod = vc->vc_font.width %8 , cnt, pitch, size;u32 attribute =get_attribute (info,scr_readw (s)); -u8 *dst, *buf =NULL ; +unsigned char *buf =NULL ; +u8 *dst; image.fg_color = fg; image.bg_color = bg;
@@ -269,7 +272,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,int y =real_y (par->p, vc->state.y);int attribute, use_sw = vc->vc_cursor_type &CUR_SW ;int err =1 ; -const u8 *src; +const unsigned char *src; cursor.set =0 ;
@@ -287,12 +290,12 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) { - par->cursor_state.image.data = src; + par->cursor_state.image.data = (const char *)src; cursor.set |=FB_CUR_SETIMAGE ; }if (attribute) { -u8 *dst; +unsigned char *dst; dst =kmalloc_array (w, vc->vc_font.height,GFP_ATOMIC );if (!dst)
drivers/video/fbdev/core/fbcon.h +2 -2
@@ -75,7 +75,7 @@ struct fbcon_bitops { #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION struct fbcon_rotated { font_data_t *fontdata; /* source font */ - u8 *buf; /* rotated glyphs */ + unsigned char *buf; /* rotated glyphs */ size_t bufsize; int buf_rotate; /* rotation of buf */ unsigned int buf_width; /* geometry of source font */
@@ -98,7 +98,7 @@ struct fbcon_par {int graphics;bool initialized;int rotate; -char *cursor_data; +unsigned char *cursor_data;#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION struct fbcon_rotated rotated;#endif
drivers/video/fbdev/core/fbcon_ccw.c +12 -10
@@ -23,13 +23,13 @@* Rotation 270 degrees */ -static void ccw_update_attr (u8 *dst,u8 *src,int attribute, -struct vc_data *vc) +static void ccw_update_attr (unsigned char *dst,const unsigned char *src,int attribute, +struct vc_data *vc) {int i, j, offset = (vc->vc_font.height <10 ) ?1 :2 ;int width =font_glyph_pitch (vc->vc_font.height);int mod = vc->vc_font.height %8 ; -u8 c, msk = ~(0xff << offset), msk1 =0 ; +unsigned char c, msk = ~(0xff << offset), msk1 =0 ;if (mod) msk <<= (8 - mod);
@@ -98,12 +98,13 @@ static void ccw_clear(struct vc_data *vc, struct fb_info *info, int sy,static inline void ccw_putcs_aligned (struct vc_data *vc,struct fb_info *info,const u16 *s,u32 attr,u32 cnt,u32 d_pitch,u32 s_pitch,u32 cellsize, -struct fb_image *image,u8 *buf,u8 *dst) +struct fb_image *image, +unsigned char *buf,u8 *dst) {struct fbcon_par *par = info->fbcon_par;u16 charmask = vc->vc_hi_font_mask ?0x1ff :0xff ;u32 idx =font_glyph_pitch (vc->vc_font.height); -u8 *src; +const unsigned char *src;while (cnt--) { src = par->rotated.buf + (scr_readw (s--) & charmask) * cellsize;
@@ -139,8 +140,9 @@ static void ccw_putcs(struct vc_data *vc, struct fb_info *info,u32 buf_align = info->pixmap.buf_align -1 ;u32 cnt, pitch, size;u32 attribute =get_attribute (info,scr_readw (s)); -u8 *dst, *buf =NULL ; +unsigned char *buf =NULL ;u32 vyres =GETVYRES (par->p, info); +u8 *dst;if (!par->rotated.buf)return ;
@@ -229,7 +231,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,int y =real_y (par->p, vc->state.y);int attribute, use_sw = vc->vc_cursor_type &CUR_SW ;int err =1 , dx, dy; -char *src; +const unsigned char *src;u32 vyres =GETVYRES (par->p, info);if (!par->rotated.buf)
@@ -241,14 +243,14 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable, attribute =get_attribute (info, c); src = par->rotated.buf + ((c & charmask) * (w * vc->vc_font.width)); -if (par->cursor_state.image.data != src || +if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) { - par->cursor_state.image.data = src; + par->cursor_state.image.data = (const char *)src; cursor.set |=FB_CUR_SETIMAGE ; }if (attribute) { -u8 *dst; +unsigned char *dst; dst =kmalloc_array (w, vc->vc_font.width,GFP_ATOMIC );if (!dst)
drivers/video/fbdev/core/fbcon_cw.c +12 -10
@@ -23,12 +23,12 @@* Rotation 90 degrees */ -static void cw_update_attr (u8 *dst,u8 *src,int attribute, -struct vc_data *vc) +static void cw_update_attr (unsigned char *dst,const unsigned char *src,int attribute, +struct vc_data *vc) {int i, j, offset = (vc->vc_font.height <10 ) ?1 :2 ;int width =font_glyph_pitch (vc->vc_font.height); -u8 c, msk = ~(0xff >> offset); +unsigned char c, msk = ~(0xff >> offset);for (i =0 ; i < vc->vc_font.width; i++) {for (j =0 ; j < width; j++) {
@@ -83,12 +83,13 @@ static void cw_clear(struct vc_data *vc, struct fb_info *info, int sy,static inline void cw_putcs_aligned (struct vc_data *vc,struct fb_info *info,const u16 *s,u32 attr,u32 cnt,u32 d_pitch,u32 s_pitch,u32 cellsize, -struct fb_image *image,u8 *buf,u8 *dst) +struct fb_image *image, +unsigned char *buf,u8 *dst) {struct fbcon_par *par = info->fbcon_par;u16 charmask = vc->vc_hi_font_mask ?0x1ff :0xff ;u32 idx =font_glyph_pitch (vc->vc_font.height); -u8 *src; +const unsigned char *src;while (cnt--) { src = par->rotated.buf + (scr_readw (s++) & charmask) * cellsize;
@@ -124,8 +125,9 @@ static void cw_putcs(struct vc_data *vc, struct fb_info *info,u32 buf_align = info->pixmap.buf_align -1 ;u32 cnt, pitch, size;u32 attribute =get_attribute (info,scr_readw (s)); -u8 *dst, *buf =NULL ; +unsigned char *buf =NULL ;u32 vxres =GETVXRES (par->p, info); +u8 *dst;if (!par->rotated.buf)return ;
@@ -212,7 +214,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,int y =real_y (par->p, vc->state.y);int attribute, use_sw = vc->vc_cursor_type &CUR_SW ;int err =1 , dx, dy; -char *src; +const unsigned char *src;u32 vxres =GETVXRES (par->p, info);if (!par->rotated.buf)
@@ -224,14 +226,14 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable, attribute =get_attribute (info, c); src = par->rotated.buf + ((c & charmask) * (w * vc->vc_font.width)); -if (par->cursor_state.image.data != src || +if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) { - par->cursor_state.image.data = src; + par->cursor_state.image.data = (const char *)src; cursor.set |=FB_CUR_SETIMAGE ; }if (attribute) { -u8 *dst; +unsigned char *dst; dst =kmalloc_array (w, vc->vc_font.width,GFP_ATOMIC );if (!dst)
drivers/video/fbdev/core/fbcon_ud.c +15 -13
@@ -22,13 +22,13 @@* Rotation 180 degrees */ -static void ud_update_attr (u8 *dst,u8 *src,int attribute, -struct vc_data *vc) +static void ud_update_attr (unsigned char *dst,const unsigned char *src,int attribute, +struct vc_data *vc) {int i, offset = (vc->vc_font.height <10 ) ?1 :2 ;int width =font_glyph_pitch (vc->vc_font.width);unsigned int cellsize = vc->vc_font.height * width; -u8 c; +unsigned char c; offset = offset * width;
@@ -84,12 +84,13 @@ static void ud_clear(struct vc_data *vc, struct fb_info *info, int sy,static inline void ud_putcs_aligned (struct vc_data *vc,struct fb_info *info,const u16 *s,u32 attr,u32 cnt,u32 d_pitch,u32 s_pitch,u32 cellsize, -struct fb_image *image,u8 *buf,u8 *dst) +struct fb_image *image, +unsigned char *buf,u8 *dst) {struct fbcon_par *par = info->fbcon_par;u16 charmask = vc->vc_hi_font_mask ?0x1ff :0xff ;u32 idx = vc->vc_font.width >>3 ; -u8 *src; +const unsigned char *src;while (cnt--) { src = par->rotated.buf + (scr_readw (s--) & charmask) * cellsize;
@@ -116,15 +117,15 @@ static inline void ud_putcs_unaligned(struct vc_data *vc, struct fb_info *info, const u16 *s, u32 attr, u32 cnt, u32 d_pitch, u32 s_pitch, u32 cellsize, - struct fb_image *image, u8 *buf, - u8 *dst) + struct fb_image *image, + unsigned char *buf, u8 *dst) { struct fbcon_par *par = info->fbcon_par;u16 charmask = vc->vc_hi_font_mask ?0x1ff :0xff ;u32 shift_low =0 , mod = vc->vc_font.width %8 ;u32 shift_high =8 ;u32 idx = vc->vc_font.width >>3 ; -u8 *src; +const unsigned char *src;while (cnt--) { src = par->rotated.buf + (scr_readw (s--) & charmask) * cellsize;
@@ -160,9 +161,10 @@ static void ud_putcs(struct vc_data *vc, struct fb_info *info,u32 buf_align = info->pixmap.buf_align -1 ;u32 mod = vc->vc_font.width %8 , cnt, pitch, size;u32 attribute =get_attribute (info,scr_readw (s)); -u8 *dst, *buf =NULL ; +unsigned char *buf =NULL ;u32 vyres =GETVYRES (par->p, info);u32 vxres =GETVXRES (par->p, info); +u8 *dst;if (!par->rotated.buf)return ;
@@ -258,7 +260,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable,int y =real_y (par->p, vc->state.y);int attribute, use_sw = vc->vc_cursor_type &CUR_SW ;int err =1 , dx, dy; -char *src; +const unsigned char *src;u32 vyres =GETVYRES (par->p, info);u32 vxres =GETVXRES (par->p, info);
@@ -271,14 +273,14 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable, attribute =get_attribute (info, c); src = par->rotated.buf + ((c & charmask) * (w * vc->vc_font.height)); -if (par->cursor_state.image.data != src || +if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) { - par->cursor_state.image.data = src; + par->cursor_state.image.data = (const char *)src; cursor.set |=FB_CUR_SETIMAGE ; }if (attribute) { -u8 *dst; +unsigned char *dst; dst =kmalloc_array (w, vc->vc_font.height,GFP_ATOMIC );if (!dst)
Signature · 1 line
2.56.1
Helge Deller
maintainerRe: [PATCH v3 1/6] fbcon: Use unsigned char for glyph data
Quoted 11 lines · Thomas Zimmermann
Represent glyph data as unsigned char, as done by
font_data_t. Convert all related code. Also declare source buffers with glyph data as const because internal fonts reside in read-only memory. Avoid writing them.We still use char for glyph data in struct
fb_image. The type is part of the kernel uAPI and therefore cannot be changed. Fall back to type casting in this case.Destination buffers for font drawing are still u8. This is framebuffer memory provided by graphics hardware.
Quoted 8 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/video/fbdev/core/bitblit.c | 25 ++++++++++++++----------- drivers/video/fbdev/core/fbcon.h | 4 ++-- drivers/video/fbdev/core/fbcon_ccw.c | 22 ++++++++++++---------- drivers/video/fbdev/core/fbcon_cw.c | 22 ++++++++++++---------- drivers/video/fbdev/core/fbcon_ud.c | 28 +++++++++++++++------------- 5 files changed, 55 insertions(+), 46 deletions(-)
I've replaced the series in fbdev-for-next with this new series.
Thanks!
Helge
Thomas Zimmermann
maintainerPATCH v3 2/6 lib/fonts: Provide internal helpers for allocating font_data_t
In reply to Thomas ZimmermannFactor out the allocation code for font_data_t from font import in font_data_import(). Retrieve a writable glyph buffer from the new helper __font_data_wrbuf().
Having the allocation code in separate functions makes it available for font rotation and maybe other font utilities. The _wrbuf() helper returns a writable glyph buffer. Font data is only readable in general.
--- lib/fonts/font.h | 12 +++++++++ lib/fonts/fonts.c | 63 ++++++++++++++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 23 deletions(-)
lib/fonts/font.h +12 -0
@@ -4,6 +4,7 @@#define _LIB_FONTS_FONT_H#include <linux/font.h> +#include <linux/types.h> /* * Font data
@@ -16,6 +17,17 @@ struct font_data {unsigned char data[]; } __packed; +/* +* font_data_t and helpers +*/ + +static inline unsigned char *__font_data_wrbuf (font_data_t *fd) +{ +return (unsigned char *)fd; +} + +font_data_t *__font_data_alloc (unsigned int size,gfp_t flags); +/* * Built-in fonts */
lib/fonts/fonts.c +40 -23
82 lines not on this page · raw message
Signature · 1 line
2.56.1
Thomas Zimmermann
maintainerPATCH v3 3/6 lib/fonts, fbcon: Use font_data_t for rotated fonts
In reply to Thomas ZimmermannReturn rotated font data as font_data_t instead of unsigned char*. Release the data with font_data_put() in fbcon.
It is still possible to use preallocated font buffers for the rotated font data. The font data tracks the buffer size and reference count to do so; font_data_rotate() invokes __font_data_alloc() to allocate a new font-data buffer if necessary.
Returning rotated font data as font_data_t further allows for using regular font-data helpers on it. Fbcon now manages buffer life time with the font data's reference counting. Removes the plain kfree().
v3:
- replace remaining instances of kfree() with font_data_put()
- fix documentation of font_data_rotate
v2:
- fix typo in commit description
--- drivers/video/fbdev/core/fbcon.c | 12 +++++--- drivers/video/fbdev/core/fbcon.h | 3 +- drivers/video/fbdev/core/fbcon_rotate.c | 19 ++++++------ include/linux/font.h | 5 ++-- lib/fonts/font_rotate.c | 39 ++++++++++--------------- 5 files changed, 36 insertions(+), 42 deletions(-)
drivers/video/fbdev/core/fbcon.c +8 -4
@@ -770,7 +770,8 @@ static void fbcon_release(struct fb_info *info)kfree (par->cursor_data);kfree (par->cursor_src);#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION -kfree (par->rotated.buf); +if (par->rotated.buf) +font_data_put (par->rotated.buf);#endif kfree (info->fbcon_par); info->fbcon_par =NULL ;
@@ -2470,8 +2471,10 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount, }#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION -if (rotated_saved) -kfree (saved_rotated.buf); +if (rotated_saved) { +if (saved_rotated.buf) +font_data_put (saved_rotated.buf); + }#endif if (old_fontdata)font_data_put (old_fontdata);
@@ -2485,7 +2488,8 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,* state. */ if (rotated_saved) { -kfree (par->rotated.buf); +if (par->rotated.buf) +font_data_put (par->rotated.buf); par->rotated = saved_rotated; }#endif
drivers/video/fbdev/core/fbcon.h +1 -2
@@ -75,8 +75,7 @@ struct fbcon_bitops { #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION struct fbcon_rotated { font_data_t *fontdata; /* source font */ - unsigned char *buf; /* rotated glyphs */ - size_t bufsize; + font_data_t *buf; /* rotated font */ int buf_rotate; /* rotation of buf */ unsigned int buf_width; /* geometry of source font */ unsigned int buf_height;
drivers/video/fbdev/core/fbcon_rotate.c +10 -9
@@ -18,7 +18,7 @@int fbcon_rotate_font (struct fb_info *info,struct vc_data *vc) {struct fbcon_par *par = info->fbcon_par; -unsigned char *buf; +font_data_t *buf;int ret; if (par->p->fontdata == par->rotated.fontdata &&
@@ -40,21 +40,22 @@ int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc) buf =font_data_rotate (par->rotated.fontdata, vc->vc_font.width, vc->vc_font.height, vc->vc_font.charcount, - par->rotated.buf_rotate, par->rotated.buf, - &par->rotated.bufsize); + par->rotated.buf_rotate, par->rotated.buf);if (IS_ERR (buf)) { ret =PTR_ERR (buf); - goto err_kfree; + goto err_font_data_put; } +if (par->rotated.buf) +font_data_put (par->rotated.buf); par->rotated.buf = buf;return 0 ; -err_kfree: -kfree (par->rotated.buf); - par->rotated.buf =NULL ;/* clear here to avoid output */ - par->rotated.bufsize =0 ; - +err_font_data_put: +if (par->rotated.buf) { +font_data_put (par->rotated.buf); + par->rotated.buf =NULL ;/* clear here to avoid output */ + }return ret; }
include/linux/font.h +2 -3
@@ -120,9 +120,8 @@ void font_glyph_rotate_180(const unsigned char *glyph, unsigned int width, unsig unsigned char *out);void font_glyph_rotate_270 (const unsigned char *glyph,unsigned int width,unsigned int height,unsigned char *out); -unsigned char *font_data_rotate (font_data_t *fd,unsigned int width,unsigned int height, -unsigned int charcount,unsigned int steps, -unsigned char *buf,size_t *bufsize); +font_data_t *font_data_rotate (font_data_t *fd,unsigned int width,unsigned int height, +unsigned int charcount,unsigned int steps,font_data_t *buf);/* * Font description
lib/fonts/font_rotate.c +15 -24
@@ -181,29 +181,23 @@ EXPORT_SYMBOL_GPL(font_glyph_rotate_270);* @height: The number of scanlines in the glyph * @charcount: The number of glyphs in the font * @steps: Number of rotation steps of 90° -* @buf: Preallocated output buffer; can be NULL -* @bufsize: The size of @buf in bytes; can be NULL +* @buf: Preallocated font data; can be NULL * * The parameters @width and @height refer to the visible number of pixels * and scanlines in a single glyph. The number of glyphs is given in @charcount. * Rotation happens in steps of 90°. The @steps parameter can have any value, * but only 0 to 3 produce distinct results. With 4 or higher, a full rotation * has been performed. You can pass any value for @steps and the helper will -* perform the appropriate rotation. Note that the returned buffer is not -* compatible with font_data_t. It only contains glyph data in the same format -* as returned by font_data_buf(). Callers are responsible to free the returned -* buffer with kfree(). Font rotation typically happens when displays get -* re-oriented. To avoid unnecessary re-allocation of the memory buffer, the -* caller can pass in an earlier result buffer in @buf for reuse. The old and -* new buffer sizes are given and retrieved by the caller in @bufsize. The -* allocation semantics are compatible with krealloc(). +* perform the appropriate rotation. Font rotation typically happens when +* displays get re-oriented. To avoid unnecessary re-allocation of the memory +* buffer, the caller can pass in an earlier result in @buf for reuse. The +* returned font data should be released with font_data_put(). * * Returns: -* A buffer with rotated glyphs on success, or an error pointer otherwise +* Font data with rotated glyphs on success, or an error pointer otherwise */ -unsigned char *font_data_rotate (font_data_t *fd,unsigned int width,unsigned int height, -unsigned int charcount,unsigned int steps, -unsigned char *buf,size_t *bufsize) +font_data_t *font_data_rotate (font_data_t *fd,unsigned int width,unsigned int height, +unsigned int charcount,unsigned int steps,font_data_t *buf) {const unsigned char *src =font_data_buf (fd);unsigned int s_cellsize =font_glyph_size (width, height);
@@ -227,19 +221,16 @@ unsigned char *font_data_rotate(font_data_t *fd, unsigned int width, unsigned inif (check_mul_overflow (charcount, d_cellsize, &size))return ERR_PTR (-EINVAL ); -if (!buf || !bufsize || size > *bufsize) { - dst =kmalloc_array (charcount, d_cellsize,GFP_KERNEL ); -if (!dst) -return ERR_PTR (-ENOMEM ); - -kfree (buf); - buf = dst; -if (bufsize) - *bufsize = size; +if (!buf || size >font_data_size (buf)) { + buf =__font_data_alloc (size,GFP_KERNEL ); +if (IS_ERR (buf)) +return buf; }else { - dst = buf; +font_data_get (buf); } + dst =__font_data_wrbuf (buf); +switch (steps) {case 0 :memcpy (dst, src, size);
Signature · 1 line
2.56.1
Thomas Zimmermann
maintainerPATCH v3 4/6 fbcon: Refactor size calculation for cursor buffers
In reply to Thomas ZimmermannReplace open-coded size calculation for cursor glyph buffers with font helpers. Use it for glyph lookup and buffer allocation.
Treat glyph width as bits per scanline instead of bytes. This is consistent with font helpers.
Note that with screen rotation enabled, width and height swap places for CW and CCW implementations.
--- drivers/video/fbdev/core/bitblit.c | 9 ++++++--- drivers/video/fbdev/core/fbcon_ccw.c | 10 ++++++---- drivers/video/fbdev/core/fbcon_cw.c | 10 ++++++---- drivers/video/fbdev/core/fbcon_ud.c | 10 ++++++---- 4 files changed, 24 insertions(+), 15 deletions(-)
drivers/video/fbdev/core/bitblit.c +6 -3
@@ -268,7 +268,10 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,struct fb_cursor cursor;struct fbcon_par *par = info->fbcon_par;unsigned short charmask = vc->vc_hi_font_mask ?0x1ff :0xff ; -int w =DIV_ROUND_UP (vc->vc_font.width,8 ), c; +int width = vc->vc_font.width; +int vpitch = vc->vc_font.height; +int cellsize =font_glyph_size (width, vpitch); +int c;int y =real_y (par->p, vc->state.y);int attribute, use_sw = vc->vc_cursor_type &CUR_SW ;int err =1 ;
@@ -286,7 +289,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,/* Clamp to font size, same as bit_putcs_aligned() */ if (c >= vc->vc_font.charcount) c =0 ; - src = vc->vc_font.data + (c * (w * vc->vc_font.height)); + src = vc->vc_font.data + (c * cellsize);if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
@@ -297,7 +300,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,if (attribute) {unsigned char *dst; - dst =kmalloc_array (w, vc->vc_font.height,GFP_ATOMIC ); + dst =kmalloc (cellsize,GFP_ATOMIC );if (!dst)return ;kfree (par->cursor_data);
drivers/video/fbdev/core/fbcon_ccw.c +6 -4
@@ -226,7 +226,9 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,struct fb_cursor cursor;struct fbcon_par *par = info->fbcon_par;unsigned short charmask = vc->vc_hi_font_mask ?0x1ff :0xff ; -int w =font_glyph_pitch (vc->vc_font.height); +int width = vc->vc_font.height; +int vpitch = vc->vc_font.width; +int cellsize =font_glyph_size (width, vpitch);int c;int y =real_y (par->p, vc->state.y);int attribute, use_sw = vc->vc_cursor_type &CUR_SW ;
@@ -241,7 +243,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable, c =scr_readw ((u16 *) vc->vc_pos); attribute =get_attribute (info, c); - src = par->rotated.buf + ((c & charmask) * (w * vc->vc_font.width)); + src = par->rotated.buf + ((c & charmask) * cellsize);if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
@@ -252,7 +254,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,if (attribute) {unsigned char *dst; - dst =kmalloc_array (w, vc->vc_font.width,GFP_ATOMIC ); + dst =kmalloc (cellsize,GFP_ATOMIC );if (!dst)return ;kfree (par->cursor_data);
@@ -304,7 +306,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,if (!tmp)return ; - mask =kmalloc_array (vc->vc_font.width, w,GFP_ATOMIC ); + mask =kmalloc (cellsize,GFP_ATOMIC );if (!mask) {kfree (tmp);return ;
drivers/video/fbdev/core/fbcon_cw.c +6 -4
@@ -209,7 +209,9 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,struct fb_cursor cursor;struct fbcon_par *par = info->fbcon_par;unsigned short charmask = vc->vc_hi_font_mask ?0x1ff :0xff ; -int w =font_glyph_pitch (vc->vc_font.height); +int width = vc->vc_font.height; +int vpitch = vc->vc_font.width; +int cellsize =font_glyph_size (width, vpitch);int c;int y =real_y (par->p, vc->state.y);int attribute, use_sw = vc->vc_cursor_type &CUR_SW ;
@@ -224,7 +226,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable, c =scr_readw ((u16 *) vc->vc_pos); attribute =get_attribute (info, c); - src = par->rotated.buf + ((c & charmask) * (w * vc->vc_font.width)); + src = par->rotated.buf + ((c & charmask) * (cellsize));if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
@@ -235,7 +237,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,if (attribute) {unsigned char *dst; - dst =kmalloc_array (w, vc->vc_font.width,GFP_ATOMIC ); + dst =kmalloc (cellsize,GFP_ATOMIC );if (!dst)return ;kfree (par->cursor_data);
@@ -287,7 +289,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable,if (!tmp)return ; - mask =kmalloc_array (vc->vc_font.width, w,GFP_ATOMIC ); + mask =kmalloc (cellsize,GFP_ATOMIC );if (!mask) {kfree (tmp);return ;
drivers/video/fbdev/core/fbcon_ud.c +6 -4
@@ -255,7 +255,9 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable,struct fb_cursor cursor;struct fbcon_par *par = info->fbcon_par;unsigned short charmask = vc->vc_hi_font_mask ?0x1ff :0xff ; -int w =font_glyph_pitch (vc->vc_font.width); +int width = vc->vc_font.width; +int vpitch = vc->vc_font.height; +int cellsize =font_glyph_size (width, vpitch);int c;int y =real_y (par->p, vc->state.y);int attribute, use_sw = vc->vc_cursor_type &CUR_SW ;
@@ -271,7 +273,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable, c =scr_readw ((u16 *) vc->vc_pos); attribute =get_attribute (info, c); - src = par->rotated.buf + ((c & charmask) * (w * vc->vc_font.height)); + src = par->rotated.buf + ((c & charmask) * cellsize);if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
@@ -282,7 +284,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable,if (attribute) {unsigned char *dst; - dst =kmalloc_array (w, vc->vc_font.height,GFP_ATOMIC ); + dst =kmalloc (cellsize,GFP_ATOMIC );if (!dst)return ;kfree (par->cursor_data);
@@ -334,7 +336,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable,if (!tmp)return ; - mask =kmalloc_array (vc->vc_font.height, w,GFP_ATOMIC ); + mask =kmalloc (cellsize,GFP_ATOMIC );if (!mask) {kfree (tmp);return ;
Signature · 1 line
2.56.1
Thomas Zimmermann
maintainerPATCH v3 5/6 fbcon: Look up glyphs using the font interface
In reply to Thomas ZimmermannReplace the open-coded glyph lookup with font_data_glyph_buf() in implementations of putcs and cursor bitops. As rotated glyphs are now stored as font_data_t, the regular lookup function for glyphs works.
Also replace the open-coded size calculations with font-data helpers.
Note that with screen rotation enabled, width and height swap places for CW and CCW implementations.
v3:
- upcast vc_font.data to font_data_t for glyph lookup
--- drivers/video/fbdev/core/bitblit.c | 24 +++++++++++++++--------- drivers/video/fbdev/core/fbcon_ccw.c | 14 ++++++++------ drivers/video/fbdev/core/fbcon_cw.c | 14 ++++++++------ drivers/video/fbdev/core/fbcon_ud.c | 23 ++++++++++++++--------- 4 files changed, 45 insertions(+), 30 deletions(-)
drivers/video/fbdev/core/bitblit.c +15 -9
@@ -76,13 +76,15 @@ static void bit_clear(struct vc_data *vc, struct fb_info *info, int sy,static inline void bit_putcs_aligned (struct vc_data *vc,struct fb_info *info,const u16 *s,u32 attr,u32 cnt, -u32 d_pitch,u32 s_pitch,u32 cellsize, +u32 d_pitch,u32 s_width,u32 s_vpitch,struct fb_image *image,unsigned char *buf,u8 *dst) {u16 charmask = vc->vc_hi_font_mask ?0x1ff :0xff ;unsigned int charcnt = vc->vc_font.charcount;u32 idx = vc->vc_font.width >>3 ; +font_data_t *fd = (font_data_t *)vc->vc_font.data;/* upcast to font_data_t */ +u32 s_pitch =font_glyph_pitch (s_width);const unsigned char *src;while (cnt--) {
@@ -90,7 +92,7 @@ static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,if (ch >= charcnt) ch =0 ; - src = vc->vc_font.data + (unsigned int )ch * cellsize; + src =font_data_glyph_buf (fd, s_width, s_vpitch, ch);if (attr) {update_attr (buf, src, attr, vc);
@@ -113,7 +115,7 @@ static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,static inline void bit_putcs_unaligned (struct vc_data *vc,struct fb_info *info,const u16 *s,u32 attr,u32 cnt,u32 d_pitch, -u32 s_pitch,u32 cellsize, +u32 s_width,u32 s_vpitch,struct fb_image *image,unsigned char *buf,u8 *dst) {
@@ -122,6 +124,8 @@ static inline void bit_putcs_unaligned(struct vc_data *vc,u32 shift_low =0 , mod = vc->vc_font.width %8 ;u32 shift_high =8 ;u32 idx = vc->vc_font.width >>3 ; +font_data_t *fd = (font_data_t *)vc->vc_font.data;/* upcast to font_data_t */ +u32 s_pitch =font_glyph_pitch (s_width);const unsigned char *src;while (cnt--) {
@@ -129,7 +133,7 @@ static inline void bit_putcs_unaligned(struct vc_data *vc,if (ch >= charcnt) ch =0 ; - src = vc->vc_font.data + (unsigned int )ch * cellsize; + src =font_data_glyph_buf (fd, s_width, s_vpitch, ch);if (attr) {update_attr (buf, src, attr, vc);
@@ -156,8 +160,9 @@ static void bit_putcs(struct vc_data *vc, struct fb_info *info,struct fbcon_par *par = info->fbcon_par;struct fb_image image;u32 vyres =GETVYRES (par->p, info); -u32 width =DIV_ROUND_UP (vc->vc_font.width,8 ); -u32 cellsize = width * vc->vc_font.height; +u32 width = vc->vc_font.width; +u32 vpitch = vc->vc_font.height; +u32 cellsize =font_glyph_size (width, vpitch);u32 maxcnt = info->pixmap.size/cellsize;u32 scan_align = info->pixmap.scan_align -1 ;u32 buf_align = info->pixmap.buf_align -1 ;
@@ -212,10 +217,10 @@ static void bit_putcs(struct vc_data *vc, struct fb_info *info,if (!mod)bit_putcs_aligned (vc, info, s, attribute, cnt, pitch, - width, cellsize, &image, buf, dst); + width, vpitch, &image, buf, dst);else bit_putcs_unaligned (vc, info, s, attribute, cnt, - pitch, width, cellsize, &image, + pitch, width, vpitch, &image, buf, dst); image.dx += cnt * vc->vc_font.width;
@@ -271,6 +276,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,int width = vc->vc_font.width;int vpitch = vc->vc_font.height;int cellsize =font_glyph_size (width, vpitch); +font_data_t *fd = (font_data_t *)vc->vc_font.data;/* upcast to font_data_t */ int c;int y =real_y (par->p, vc->state.y);int attribute, use_sw = vc->vc_cursor_type &CUR_SW ;
@@ -289,7 +295,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable,/* Clamp to font size, same as bit_putcs_aligned() */ if (c >= vc->vc_font.charcount) c =0 ; - src = vc->vc_font.data + (c * cellsize); + src =font_data_glyph_buf (fd, width, vpitch, c);if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
drivers/video/fbdev/core/fbcon_ccw.c +8 -6
@@ -97,7 +97,7 @@ static void ccw_clear(struct vc_data *vc, struct fb_info *info, int sy,static inline void ccw_putcs_aligned (struct vc_data *vc,struct fb_info *info,const u16 *s,u32 attr,u32 cnt, -u32 d_pitch,u32 s_pitch,u32 cellsize, +u32 d_pitch,u32 s_width,u32 s_vpitch,struct fb_image *image,unsigned char *buf,u8 *dst) {
@@ -107,7 +107,8 @@ static inline void ccw_putcs_aligned(struct vc_data *vc, struct fb_info *info,const unsigned char *src;while (cnt--) { - src = par->rotated.buf + (scr_readw (s--) & charmask) * cellsize; + src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch, +scr_readw (s--) & charmask);if (attr) {ccw_update_attr (buf, src, attr, vc);
@@ -133,8 +134,9 @@ static void ccw_putcs(struct vc_data *vc, struct fb_info *info, {struct fb_image image;struct fbcon_par *par = info->fbcon_par; -u32 width =font_glyph_pitch (vc->vc_font.height); -u32 cellsize = width * vc->vc_font.width; +u32 width = vc->vc_font.height; +u32 vpitch = vc->vc_font.width; +u32 cellsize =font_glyph_size (width, vpitch);u32 maxcnt = info->pixmap.size/cellsize;u32 scan_align = info->pixmap.scan_align -1 ;u32 buf_align = info->pixmap.buf_align -1 ;
@@ -176,7 +178,7 @@ static void ccw_putcs(struct vc_data *vc, struct fb_info *info, dst =fb_get_buffer_offset (info, &info->pixmap, size); image.data = dst;ccw_putcs_aligned (vc, info, s, attribute, cnt, pitch, - width, cellsize, &image, buf, dst); + width, vpitch, &image, buf, dst); image.dy += image.height; count -= cnt; s -= cnt;
@@ -243,7 +245,7 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable, c =scr_readw ((u16 *) vc->vc_pos); attribute =get_attribute (info, c); - src = par->rotated.buf + ((c & charmask) * cellsize); + src =font_data_glyph_buf (par->rotated.buf, width, vpitch, c & charmask);if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
drivers/video/fbdev/core/fbcon_cw.c +8 -6
@@ -82,7 +82,7 @@ static void cw_clear(struct vc_data *vc, struct fb_info *info, int sy,static inline void cw_putcs_aligned (struct vc_data *vc,struct fb_info *info,const u16 *s,u32 attr,u32 cnt, -u32 d_pitch,u32 s_pitch,u32 cellsize, +u32 d_pitch,u32 s_width,u32 s_vpitch,struct fb_image *image,unsigned char *buf,u8 *dst) {
@@ -92,7 +92,8 @@ static inline void cw_putcs_aligned(struct vc_data *vc, struct fb_info *info,const unsigned char *src;while (cnt--) { - src = par->rotated.buf + (scr_readw (s++) & charmask) * cellsize; + src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch, +scr_readw (s++) & charmask);if (attr) {cw_update_attr (buf, src, attr, vc);
@@ -118,8 +119,9 @@ static void cw_putcs(struct vc_data *vc, struct fb_info *info, {struct fb_image image;struct fbcon_par *par = info->fbcon_par; -u32 width =font_glyph_pitch (vc->vc_font.height); -u32 cellsize = width * vc->vc_font.width; +u32 width = vc->vc_font.height; +u32 vpitch = vc->vc_font.width; +u32 cellsize =font_glyph_size (width, vpitch);u32 maxcnt = info->pixmap.size/cellsize;u32 scan_align = info->pixmap.scan_align -1 ;u32 buf_align = info->pixmap.buf_align -1 ;
@@ -159,7 +161,7 @@ static void cw_putcs(struct vc_data *vc, struct fb_info *info, dst =fb_get_buffer_offset (info, &info->pixmap, size); image.data = dst;cw_putcs_aligned (vc, info, s, attribute, cnt, pitch, - width, cellsize, &image, buf, dst); + width, vpitch, &image, buf, dst); image.dy += image.height; count -= cnt; s += cnt;
@@ -226,7 +228,7 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable, c =scr_readw ((u16 *) vc->vc_pos); attribute =get_attribute (info, c); - src = par->rotated.buf + ((c & charmask) * (cellsize)); + src =font_data_glyph_buf (par->rotated.buf, width, vpitch, c & charmask);if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
drivers/video/fbdev/core/fbcon_ud.c +14 -9
@@ -83,17 +83,19 @@ static void ud_clear(struct vc_data *vc, struct fb_info *info, int sy,static inline void ud_putcs_aligned (struct vc_data *vc,struct fb_info *info,const u16 *s,u32 attr,u32 cnt, -u32 d_pitch,u32 s_pitch,u32 cellsize, +u32 d_pitch,u32 s_width,u32 s_vpitch,struct fb_image *image,unsigned char *buf,u8 *dst) {struct fbcon_par *par = info->fbcon_par;u16 charmask = vc->vc_hi_font_mask ?0x1ff :0xff ;u32 idx = vc->vc_font.width >>3 ; +u32 s_pitch =font_glyph_pitch (s_width);const unsigned char *src;while (cnt--) { - src = par->rotated.buf + (scr_readw (s--) & charmask) * cellsize; + src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch, +scr_readw (s--) & charmask);if (attr) {ud_update_attr (buf, src, attr, vc);
@@ -116,7 +118,7 @@ static inline void ud_putcs_aligned(struct vc_data *vc, struct fb_info *info,static inline void ud_putcs_unaligned (struct vc_data *vc,struct fb_info *info,const u16 *s,u32 attr,u32 cnt,u32 d_pitch, -u32 s_pitch,u32 cellsize, +u32 s_width,u32 s_vpitch,struct fb_image *image,unsigned char *buf,u8 *dst) {
@@ -125,10 +127,12 @@ static inline void ud_putcs_unaligned(struct vc_data *vc,u32 shift_low =0 , mod = vc->vc_font.width %8 ;u32 shift_high =8 ;u32 idx = vc->vc_font.width >>3 ; +u32 s_pitch =font_glyph_pitch (s_width);const unsigned char *src;while (cnt--) { - src = par->rotated.buf + (scr_readw (s--) & charmask) * cellsize; + src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch, +scr_readw (s--) & charmask);if (attr) {ud_update_attr (buf, src, attr, vc);
@@ -154,8 +158,9 @@ static void ud_putcs(struct vc_data *vc, struct fb_info *info, {struct fb_image image;struct fbcon_par *par = info->fbcon_par; -u32 width =font_glyph_pitch (vc->vc_font.width); -u32 cellsize = width * vc->vc_font.height; +u32 width = vc->vc_font.width; +u32 vpitch = vc->vc_font.height; +u32 cellsize =font_glyph_size (width, vpitch);u32 maxcnt = info->pixmap.size/cellsize;u32 scan_align = info->pixmap.scan_align -1 ;u32 buf_align = info->pixmap.buf_align -1 ;
@@ -200,10 +205,10 @@ static void ud_putcs(struct vc_data *vc, struct fb_info *info,if (!mod)ud_putcs_aligned (vc, info, s, attribute, cnt, pitch, - width, cellsize, &image, buf, dst); + width, vpitch, &image, buf, dst);else ud_putcs_unaligned (vc, info, s, attribute, cnt, pitch, - width, cellsize, &image, + width, vpitch, &image, buf, dst); image.dx += image.width;
@@ -273,7 +278,7 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable, c =scr_readw ((u16 *) vc->vc_pos); attribute =get_attribute (info, c); - src = par->rotated.buf + ((c & charmask) * cellsize); + src =font_data_glyph_buf (par->rotated.buf, width, vpitch, c & charmask);if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
Signature · 1 line
2.56.1
Thomas Zimmermann
maintainerPATCH v3 6/6 fbcon: Handle characters with no glyph defined in a consistent way
In reply to Thomas ZimmermannCheck the result of font_data_glyph_buf() for NULL when drawing the screen. Fall back to a default value of '\0' for undefined glpyhs. Skip the character if no fallback exists.
Error checking for fonts has been inconsistent or absent from fbcon. Most of the drawing code relies on earlier validation in the font-import code. Some code implements the glyph test by itself. At least all of fbcon should be consistent in how it handles undefined glyphs.
Calls to font_data_glyph_buf() returning NULL for undefined glyphs make it easy to handle this special case consistently across fbcon.
v3:
- fix fallback in ccw_cursor()
--- drivers/video/fbdev/core/bitblit.c | 27 +++++++++++++++++---------- drivers/video/fbdev/core/fbcon_ccw.c | 12 +++++++++++- drivers/video/fbdev/core/fbcon_cw.c | 13 +++++++++++-- drivers/video/fbdev/core/fbcon_ud.c | 18 +++++++++++++++++- 4 files changed, 56 insertions(+), 14 deletions(-)
drivers/video/fbdev/core/bitblit.c +17 -10
@@ -81,7 +81,6 @@ static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info, unsigned char *buf, u8 *dst) { u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; -unsigned int charcnt = vc->vc_font.charcount;u32 idx = vc->vc_font.width >>3 ;font_data_t *fd = (font_data_t *)vc->vc_font.data;/* upcast to font_data_t */ u32 s_pitch =font_glyph_pitch (s_width);
@@ -90,9 +89,12 @@ static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,while (cnt--) {u16 ch =scr_readw (s++) & charmask; -if (ch >= charcnt) - ch =0 ; src =font_data_glyph_buf (fd, s_width, s_vpitch, ch); +if (!src) { + src =font_data_glyph_buf (fd, s_width, s_vpitch,'\0' ); +if (!src) + goto next_char; + }if (attr) {update_attr (buf, src, attr, vc);
@@ -105,7 +107,7 @@ static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,else fb_pad_aligned_buffer (dst, d_pitch, src, idx, image->height); - +next_char: dst += s_pitch; }
@@ -120,7 +122,6 @@ static inline void bit_putcs_unaligned(struct vc_data *vc, unsigned char *buf, u8 *dst) { u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; -unsigned int charcnt = vc->vc_font.charcount;u32 shift_low =0 , mod = vc->vc_font.width %8 ;u32 shift_high =8 ;u32 idx = vc->vc_font.width >>3 ;
@@ -131,9 +132,12 @@ static inline void bit_putcs_unaligned(struct vc_data *vc,while (cnt--) {u16 ch =scr_readw (s++) & charmask; -if (ch >= charcnt) - ch =0 ; src =font_data_glyph_buf (fd, s_width, s_vpitch, ch); +if (!src) { + src =font_data_glyph_buf (fd, s_width, s_vpitch,'\0' ); +if (!src) + goto next_char; + }if (attr) {update_attr (buf, src, attr, vc);
@@ -143,6 +147,7 @@ static inline void bit_putcs_unaligned(struct vc_data *vc,fb_pad_unaligned_buffer (dst, d_pitch, src, idx, image->height, shift_high, shift_low, mod); +next_char: shift_low += mod; dst += (shift_low >=8 ) ? s_pitch : s_pitch -1 ; shift_low &=7 ;
@@ -292,10 +297,12 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, bool enable, attribute =get_attribute (info, c); c &= charmask; -/* Clamp to font size, same as bit_putcs_aligned() */ -if (c >= vc->vc_font.charcount) - c =0 ; src =font_data_glyph_buf (fd, width, vpitch, c); +if (!src) { + src =font_data_glyph_buf (fd, width, vpitch,'\0' ); +if (!src) +return ; + }if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
drivers/video/fbdev/core/fbcon_ccw.c +11 -1
@@ -109,6 +109,11 @@ static inline void ccw_putcs_aligned(struct vc_data *vc, struct fb_info *info,while (cnt--) { src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch,scr_readw (s--) & charmask); +if (!src) { + src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch,'\0' ); +if (!src) + goto next_char; + }if (attr) {ccw_update_attr (buf, src, attr, vc);
@@ -121,7 +126,7 @@ static inline void ccw_putcs_aligned(struct vc_data *vc, struct fb_info *info,else fb_pad_aligned_buffer (dst, d_pitch, src, idx, vc->vc_font.width); - +next_char: dst += d_pitch * vc->vc_font.width; }
@@ -246,6 +251,11 @@ static void ccw_cursor(struct vc_data *vc, struct fb_info *info, bool enable, c =scr_readw ((u16 *) vc->vc_pos); attribute =get_attribute (info, c); src =font_data_glyph_buf (par->rotated.buf, width, vpitch, c & charmask); +if (!src) { + src =font_data_glyph_buf (par->rotated.buf, width, vpitch,'\0' ); +if (!src) +return ; + }if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
drivers/video/fbdev/core/fbcon_cw.c +11 -2
@@ -94,7 +94,11 @@ static inline void cw_putcs_aligned(struct vc_data *vc, struct fb_info *info,while (cnt--) { src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch,scr_readw (s++) & charmask); - +if (!src) { + src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch,'\0' ); +if (!src) + goto next_char; + }if (attr) {cw_update_attr (buf, src, attr, vc); src = buf;
@@ -106,7 +110,7 @@ static inline void cw_putcs_aligned(struct vc_data *vc, struct fb_info *info,else fb_pad_aligned_buffer (dst, d_pitch, src, idx, vc->vc_font.width); - +next_char: dst += d_pitch * vc->vc_font.width; }
@@ -229,6 +233,11 @@ static void cw_cursor(struct vc_data *vc, struct fb_info *info, bool enable, c =scr_readw ((u16 *) vc->vc_pos); attribute =get_attribute (info, c); src =font_data_glyph_buf (par->rotated.buf, width, vpitch, c & charmask); +if (!src) { + src =font_data_glyph_buf (par->rotated.buf, width, vpitch,'\0' ); +if (!src) +return ; + }if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
drivers/video/fbdev/core/fbcon_ud.c +17 -1
@@ -96,6 +96,11 @@ static inline void ud_putcs_aligned(struct vc_data *vc, struct fb_info *info,while (cnt--) { src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch,scr_readw (s--) & charmask); +if (!src) { + src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch,'\0' ); +if (!src) + goto next_char; + }if (attr) {ud_update_attr (buf, src, attr, vc);
@@ -108,7 +113,7 @@ static inline void ud_putcs_aligned(struct vc_data *vc, struct fb_info *info,else fb_pad_aligned_buffer (dst, d_pitch, src, idx, image->height); - +next_char: dst += s_pitch; }
@@ -133,6 +138,11 @@ static inline void ud_putcs_unaligned(struct vc_data *vc,while (cnt--) { src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch,scr_readw (s--) & charmask); +if (!src) { + src =font_data_glyph_buf (par->rotated.buf, s_width, s_vpitch,'\0' ); +if (!src) + goto next_char; + }if (attr) {ud_update_attr (buf, src, attr, vc);
@@ -142,6 +152,7 @@ static inline void ud_putcs_unaligned(struct vc_data *vc,fb_pad_unaligned_buffer (dst, d_pitch, src, idx, image->height, shift_high, shift_low, mod); +next_char: shift_low += mod; dst += (shift_low >=8 ) ? s_pitch : s_pitch -1 ; shift_low &=7 ;
@@ -279,6 +290,11 @@ static void ud_cursor(struct vc_data *vc, struct fb_info *info, bool enable, c =scr_readw ((u16 *) vc->vc_pos); attribute =get_attribute (info, c); src =font_data_glyph_buf (par->rotated.buf, width, vpitch, c & charmask); +if (!src) { + src =font_data_glyph_buf (par->rotated.buf, width, vpitch,'\0' ); +if (!src) +return ; + }if (par->cursor_state.image.data != (const char *)src || par->cursor_reset) {
Signature · 1 line
2.56.1