Skip to content

Commit

Permalink
vt: unicode fallback for scrollback
Browse files Browse the repository at this point in the history
There is currently no provision for scrollback content in the core code,
leaving that to backend video drivers where this can be highly optimized.
There is currently no common method for those drivers to tell the core
what part of the scrollback is actually displayed and what size the
scrollback buffer is either. Because of that, the unicode screen buffer
has no provision for any scrollback.

At least we can provide backtranslated glyph values when the scrollback
is active which should be plenty good enough for now.

Signed-off-by: Nicolas Pitre <nico@linaro.org>
Tested-by: Dave Mielke <Dave@mielke.cc>
Acked-by: Adam Borowski <kilobyte@angband.pl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Nicolas Pitre authored and Greg Kroah-Hartman committed Jun 28, 2018
1 parent d21b0be commit 708d0bf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion drivers/tty/vt/vc_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
do {
if (nr > this_round/4)
nr = this_round/4;
vc_uniscr_copy_line(vc, con_buf0, row, col, nr);
vc_uniscr_copy_line(vc, con_buf0, viewed,
row, col, nr);
con_buf0 += nr * 4;
this_round -= nr * 4;
row++;
Expand Down
31 changes: 29 additions & 2 deletions drivers/tty/vt/vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,40 @@ int vc_uniscr_check(struct vc_data *vc)
* This must be preceded by a successful call to vc_uniscr_check() once
* the console lock has been taken.
*/
void vc_uniscr_copy_line(struct vc_data *vc, void *dest,
void vc_uniscr_copy_line(struct vc_data *vc, void *dest, int viewed,
unsigned int row, unsigned int col, unsigned int nr)
{
struct uni_screen *uniscr = get_vc_uniscr(vc);
int offset = row * vc->vc_size_row + col * 2;
unsigned long pos;

BUG_ON(!uniscr);
memcpy(dest, &uniscr->lines[row][col], nr * sizeof(char32_t));

pos = (unsigned long)screenpos(vc, offset, viewed);
if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
/*
* Desired position falls in the main screen buffer.
* However the actual row/col might be different if
* scrollback is active.
*/
row = (pos - vc->vc_origin) / vc->vc_size_row;
col = ((pos - vc->vc_origin) % vc->vc_size_row) / 2;
memcpy(dest, &uniscr->lines[row][col], nr * sizeof(char32_t));
} else {
/*
* Scrollback is active. For now let's simply backtranslate
* the screen glyphs until the unicode screen buffer does
* synchronize with console display drivers for a scrollback
* buffer of its own.
*/
u16 *p = (u16 *)pos;
int mask = vc->vc_hi_font_mask | 0xff;
char32_t *uni_buf = dest;
while (nr--) {
u16 glyph = scr_readw(p++) & mask;
*uni_buf++ = inverse_translate(vc, glyph, true);
}
}
}


Expand Down
2 changes: 1 addition & 1 deletion include/linux/selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org);
extern void vcs_scr_updated(struct vc_data *vc);

extern int vc_uniscr_check(struct vc_data *vc);
extern void vc_uniscr_copy_line(struct vc_data *vc, void *dest,
extern void vc_uniscr_copy_line(struct vc_data *vc, void *dest, int viewed,
unsigned int row, unsigned int col,
unsigned int nr);

Expand Down

0 comments on commit 708d0bf

Please sign in to comment.