vt.h revision 259615
147133Sobrien/*-
247133Sobrien * Copyright (c) 2009, 2013 The FreeBSD Foundation
347133Sobrien * All rights reserved.
447133Sobrien *
547133Sobrien * This software was developed by Ed Schouten under sponsorship from the
647133Sobrien * FreeBSD Foundation.
747133Sobrien *
847133Sobrien * Portions of this software were developed by Oleksandr Rybalko
947133Sobrien * under sponsorship from the FreeBSD Foundation.
1047133Sobrien *
1147133Sobrien * Redistribution and use in source and binary forms, with or without
1247133Sobrien * modification, are permitted provided that the following conditions
1347133Sobrien * are met:
1447133Sobrien * 1. Redistributions of source code must retain the above copyright
1547133Sobrien *    notice, this list of conditions and the following disclaimer.
1647133Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1747133Sobrien *    notice, this list of conditions and the following disclaimer in the
1847133Sobrien *    documentation and/or other materials provided with the distribution.
1947133Sobrien *
2047133Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2147133Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2247133Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2347133Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2447133Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2547133Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2651594Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2750477Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2847133Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2955723Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3055723Simp * SUCH DAMAGE.
3147133Sobrien *
3247133Sobrien * $FreeBSD: head/sys/dev/vt/vt.h 259615 2013-12-19 15:31:20Z ray $
3348114Sobrien */
3448114Sobrien
3548114Sobrien#ifndef _DEV_VT_VT_H_
3648114Sobrien#define	_DEV_VT_VT_H_
3748114Sobrien
3848114Sobrien#include <sys/param.h>
3948114Sobrien#include <sys/_lock.h>
4048114Sobrien#include <sys/_mutex.h>
4148114Sobrien#include <sys/callout.h>
4248114Sobrien#include <sys/condvar.h>
4348114Sobrien#include <sys/consio.h>
4448114Sobrien#include <sys/kbio.h>
4548114Sobrien#include <sys/mouse.h>
4648114Sobrien#include <sys/terminal.h>
4748114Sobrien#include <sys/sysctl.h>
4848114Sobrien
4948114Sobrien#include "opt_syscons.h"
5048114Sobrien#include "opt_splash.h"
5148114Sobrien
5248114Sobrien#ifdef DEV_SC
5348114Sobrien#error "Build with both syscons and vt is not supported. Please enable only \
5448114Sobrienone 'device sc' or 'device vt'"
5548114Sobrien#endif
5648114Sobrien
5748114Sobrien#ifndef	VT_MAXWINDOWS
5848114Sobrien#ifdef	MAXCONS
5948114Sobrien#define	VT_MAXWINDOWS	MAXCONS
6048114Sobrien#else
6148114Sobrien#define	VT_MAXWINDOWS	12
6248114Sobrien#endif
6348114Sobrien#endif
6448114Sobrien
6548114Sobrien#ifndef VT_ALT_TO_ESC_HACK
6648114Sobrien#define	VT_ALT_TO_ESC_HACK	1
6748114Sobrien#endif
6848114Sobrien
6947133Sobrien#define	VT_CONSWINDOW	0
7047133Sobrien
7148114Sobrien#if defined(SC_TWOBUTTON_MOUSE) || defined(VT_TWOBUTTON_MOUSE)
7248114Sobrien#define VT_MOUSE_PASTEBUTTON	MOUSE_BUTTON3DOWN	/* right button */
7348114Sobrien#define VT_MOUSE_EXTENDBUTTON	MOUSE_BUTTON2DOWN	/* not really used */
7448114Sobrien#else
7547133Sobrien#define VT_MOUSE_PASTEBUTTON	MOUSE_BUTTON2DOWN	/* middle button */
7648114Sobrien#define VT_MOUSE_EXTENDBUTTON	MOUSE_BUTTON3DOWN	/* right button */
7748114Sobrien#endif /* defined(SC_TWOBUTTON_MOUSE) || defined(VT_TWOBUTTON_MOUSE) */
7848114Sobrien
7947133Sobrien#define	SC_DRIVER_NAME	"vt"
8048114Sobrien#define	DPRINTF(_l, ...)	if (vt_debug > (_l)) printf( __VA_ARGS__ )
8148114Sobrien#define	ISSIGVALID(sig)	((sig) > 0 && (sig) < NSIG)
8248114Sobrien
8348114Sobrien#define	VT_SYSCTL_INT(_name, _default, _descr)				\
8447133Sobrienstatic int vt_##_name = _default;					\
8548114SobrienSYSCTL_INT(_kern_vt, OID_AUTO, _name, CTLFLAG_RW, &vt_##_name, _default,\
8647133Sobrien		_descr);						\
8748114SobrienTUNABLE_INT("kern.vt." #_name, &vt_##_name);
8847133Sobrien
8948114Sobrienstruct vt_driver;
9048114Sobrien
9148114Sobrienvoid vt_allocate(struct vt_driver *, void *);
9248114Sobrienvoid vt_resume(void);
9347133Sobrienvoid vt_suspend(void);
9448114Sobrien
9548114Sobrientypedef unsigned int 	vt_axis_t;
9648114Sobrien
9748114Sobrien/*
9848114Sobrien * List of locks
9948114Sobrien * (d)	locked by vd_lock
10048114Sobrien * (b)	locked by vb_lock
10148114Sobrien * (G)	locked by Giant
10248114Sobrien * (u)	unlocked, locked by higher levels
10348114Sobrien * (c)	const until freeing
10448114Sobrien * (?)	yet to be determined
10548114Sobrien */
10648114Sobrien
10748114Sobrien/*
10848114Sobrien * Per-device datastructure.
10947133Sobrien */
11048114Sobrien
11148114Sobrienstruct vt_device {
11247133Sobrien	struct vt_window	*vd_windows[VT_MAXWINDOWS]; /* (c) Windows. */
11347133Sobrien	struct vt_window	*vd_curwindow;	/* (d) Current window. */
11448114Sobrien	struct vt_window	*vd_savedwindow;/* (?) Saved for suspend. */
11547133Sobrien	struct vt_window	*vd_markedwin;	/* (?) Copy/paste buf owner. */
11648114Sobrien	const struct vt_driver	*vd_driver;	/* (c) Graphics driver. */
11747133Sobrien	void			*vd_softc;	/* (u) Driver data. */
11848114Sobrien	uint16_t		 vd_mx;		/* (?) Mouse X. */
11948114Sobrien	uint16_t		 vd_my;		/* (?) Mouse Y. */
12048114Sobrien	vt_axis_t		 vd_mdirtyx;	/* (?) Screen width. */
12148114Sobrien	vt_axis_t		 vd_mdirtyy;	/* (?) Screen height. */
12248114Sobrien	uint32_t		 vd_mstate;	/* (?) Mouse state. */
12347133Sobrien	term_pos_t		 vd_offset;	/* (?) Pixel offset. */
12448114Sobrien	vt_axis_t		 vd_width;	/* (?) Screen width. */
12548114Sobrien	vt_axis_t		 vd_height;	/* (?) Screen height. */
12648114Sobrien	struct mtx		 vd_lock;	/* Per-device lock. */
12748114Sobrien	struct cv		 vd_winswitch;	/* (d) Window switch notify. */
12848114Sobrien	struct callout		 vd_timer;	/* (d) Display timer. */
12948114Sobrien	int			 vd_flags;	/* (d) Device flags. */
13048114Sobrien#define	VDF_TEXTMODE	0x01	/* Do text mode rendering. */
13148114Sobrien#define	VDF_SPLASH	0x02	/* Splash screen active. */
13247133Sobrien#define	VDF_ASYNC	0x04	/* vt_timer() running. */
13348114Sobrien#define	VDF_INVALID	0x08	/* Entire screen should be re-rendered. */
13448114Sobrien#define	VDF_DEAD	0x10	/* Early probing found nothing. */
13548114Sobrien#define	VDF_INITIALIZED	0x20	/* vtterm_cnprobe already done. */
13648114Sobrien#define	VDF_MOUSECURSOR	0x40	/* Mouse cursor visible. */
13748114Sobrien	int			 vd_keyboard;	/* (G) Keyboard index. */
13848114Sobrien	unsigned int		 vd_kbstate;	/* (?) Device unit. */
13948114Sobrien	unsigned int		 vd_unit;	/* (c) Device unit. */
14048114Sobrien};
14148114Sobrien
14248114Sobrien/*
14348114Sobrien * Per-window terminal screen buffer.
14448114Sobrien *
14548114Sobrien * Because redrawing is performed asynchronously, the buffer keeps track
14648114Sobrien * of a rectangle that needs to be redrawn (vb_dirtyrect).  Because this
14748114Sobrien * approach seemed to cause suboptimal performance (when the top left
14847133Sobrien * and the bottom right of the screen are modified), it also uses a set
14948114Sobrien * of bitmasks to keep track of the rows and columns (mod 64) that have
15048114Sobrien * been modified.
15148114Sobrien */
15247133Sobrien
15347133Sobrienstruct vt_bufmask {
15448114Sobrien	uint64_t		 vbm_row, vbm_col;
15547133Sobrien#define	VBM_DIRTY		UINT64_MAX
15648114Sobrien};
15747133Sobrien
15848114Sobrienstruct vt_buf {
15948114Sobrien	struct mtx		 vb_lock;	/* Buffer lock. */
16048114Sobrien	term_pos_t		 vb_scr_size;	/* (b) Screen dimensions. */
16148114Sobrien	int			 vb_flags;	/* (b) Flags. */
16248114Sobrien#define	VBF_CURSOR	0x1	/* Cursor visible. */
16347133Sobrien#define	VBF_STATIC	0x2	/* Buffer is statically allocated. */
16448114Sobrien#define	VBF_MTX_INIT	0x4	/* Mutex initialized. */
16548114Sobrien#define	VBF_SCROLL	0x8	/* scroll locked mode. */
16648114Sobrien#define	VBF_HISTORY_FULL 0x10	/* All rows filled. */
16748114Sobrien	int			 vb_history_size;
16848114Sobrien#define	VBF_DEFAULT_HISTORY_SIZE	500
16948114Sobrien	int			 vb_roffset;	/* (b) History rows offset. */
17048114Sobrien	int			 vb_curroffset;	/* (b) Saved rows offset. */
17148114Sobrien	term_pos_t		 vb_cursor;	/* (u) Cursor position. */
17248114Sobrien	term_pos_t		 vb_mark_start;	/* (b) Copy region start. */
17347133Sobrien	term_pos_t		 vb_mark_end;	/* (b) Copy region end. */
17448114Sobrien	int			 vb_mark_last;	/* Last mouse event. */
17548114Sobrien	term_rect_t		 vb_dirtyrect;	/* (b) Dirty rectangle. */
17648114Sobrien	struct vt_bufmask	 vb_dirtymask;	/* (b) Dirty bitmasks. */
17748114Sobrien	term_char_t		*vb_buffer;	/* (u) Data buffer. */
17848114Sobrien	term_char_t		**vb_rows;	/* (u) Array of rows */
17947133Sobrien};
18048114Sobrien
18148114Sobrienvoid vtbuf_copy(struct vt_buf *, const term_rect_t *, const term_pos_t *);
18247133Sobrienvoid vtbuf_fill_locked(struct vt_buf *, const term_rect_t *, term_char_t);
18347133Sobrienvoid vtbuf_init_early(struct vt_buf *);
18447133Sobrienvoid vtbuf_init(struct vt_buf *, const term_pos_t *);
18548114Sobrienvoid vtbuf_grow(struct vt_buf *, const term_pos_t *, int);
18648114Sobrienvoid vtbuf_putchar(struct vt_buf *, const term_pos_t *, term_char_t);
18747133Sobrienvoid vtbuf_cursor_position(struct vt_buf *, const term_pos_t *);
18847133Sobrienvoid vtbuf_scroll_mode(struct vt_buf *vb, int yes);
18947133Sobrienvoid vtbuf_undirty(struct vt_buf *, term_rect_t *, struct vt_bufmask *);
19048114Sobrienvoid vtbuf_sethistory_size(struct vt_buf *, int);
19148114Sobrienint vtbuf_iscursor(struct vt_buf *vb, int row, int col);
19248114Sobrienvoid vtbuf_cursor_visibility(struct vt_buf *, int);
19348114Sobrien#ifndef SC_NO_CUTPASTE
19448114Sobrienvoid vtbuf_mouse_cursor_position(struct vt_buf *vb, int col, int row);
19547133Sobrienint vtbuf_set_mark(struct vt_buf *vb, int type, int col, int row);
19648114Sobrienint vtbuf_get_marked_len(struct vt_buf *vb);
19748114Sobrienvoid vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz);
19848114Sobrien#endif
19948114Sobrien
20048114Sobrien#define	VTB_MARK_NONE		0
20148114Sobrien#define	VTB_MARK_END		1
20248114Sobrien#define	VTB_MARK_START		2
20348114Sobrien#define	VTB_MARK_WORD		3
20448114Sobrien#define	VTB_MARK_ROW		4
20548114Sobrien#define	VTB_MARK_EXTEND		5
20648114Sobrien#define	VTB_MARK_MOVE		6
20748114Sobrien
20848114Sobrien#define	VTBUF_SLCK_ENABLE(vb)	vtbuf_scroll_mode((vb), 1)
20948114Sobrien#define	VTBUF_SLCK_DISABLE(vb)	vtbuf_scroll_mode((vb), 0)
21048114Sobrien
21148114Sobrien#define	VTBUF_MAX_HEIGHT(vb) \
21248114Sobrien	((vb)->vb_history_size)
21348114Sobrien#define	VTBUF_GET_ROW(vb, r) \
21448114Sobrien	((vb)->vb_rows[((vb)->vb_roffset + (r)) % VTBUF_MAX_HEIGHT(vb)])
21548114Sobrien#define	VTBUF_GET_FIELD(vb, r, c) \
21648114Sobrien	((vb)->vb_rows[((vb)->vb_roffset + (r)) % VTBUF_MAX_HEIGHT(vb)][(c)])
21748114Sobrien#define	VTBUF_FIELD(vb, r, c) \
21848114Sobrien	((vb)->vb_rows[((vb)->vb_curroffset + (r)) % VTBUF_MAX_HEIGHT(vb)][(c)])
21948114Sobrien#define	VTBUF_ISCURSOR(vb, r, c) \
22048114Sobrien	vtbuf_iscursor((vb), (r), (c))
22148114Sobrien#define	VTBUF_DIRTYROW(mask, row) \
22248114Sobrien	((mask)->vbm_row & ((uint64_t)1 << ((row) % 64)))
22348114Sobrien#define	VTBUF_DIRTYCOL(mask, col) \
22448114Sobrien	((mask)->vbm_col & ((uint64_t)1 << ((col) % 64)))
22548114Sobrien#define	VTBUF_SPACE_CHAR	(' ' | TC_WHITE << 26 | TC_BLACK << 29)
22648114Sobrien
22748114Sobrien#define	VHS_SET	0
22848114Sobrien#define	VHS_CUR	1
22948114Sobrien#define	VHS_END	2
23048114Sobrienint vthistory_seek(struct vt_buf *, int offset, int whence);
23148114Sobrienvoid vthistory_addlines(struct vt_buf *vb, int offset);
23248114Sobrienvoid vthistory_getpos(const struct vt_buf *, unsigned int *offset);
23348114Sobrien
23448114Sobrien/*
23548114Sobrien * Per-window datastructure.
23648114Sobrien */
23748114Sobrien
23848114Sobrienstruct vt_window {
23948114Sobrien	struct vt_device	*vw_device;	/* (c) Device. */
24048114Sobrien	struct terminal		*vw_terminal;	/* (c) Terminal. */
24148114Sobrien	struct vt_buf		 vw_buf;	/* (u) Screen buffer. */
24248114Sobrien	struct vt_font		*vw_font;	/* (d) Graphical font. */
24348114Sobrien	unsigned int		 vw_number;	/* (c) Window number. */
24448114Sobrien	int			 vw_kbdmode;	/* (?) Keyboard mode. */
24548114Sobrien	char			*vw_kbdsq;	/* Escape sequence queue*/
24648114Sobrien	unsigned int		 vw_flags;	/* (d) Per-window flags. */
24748114Sobrien#define	VWF_BUSY	0x1	/* Busy reconfiguring device. */
24848114Sobrien#define	VWF_OPENED	0x2	/* TTY in use. */
24948114Sobrien#define	VWF_SCROLL	0x4	/* Keys influence scrollback. */
25048114Sobrien#define	VWF_CONSOLE	0x8	/* Kernel message console window. */
25148114Sobrien#define	VWF_VTYLOCK	0x10	/* Prevent window switch. */
25248114Sobrien#define	VWF_MOUSE_HIDE	0x20	/* Disable mouse events processing. */
25348114Sobrien#define	VWF_SWWAIT_REL	0x10000	/* Program wait for VT acquire is done. */
25448114Sobrien#define	VWF_SWWAIT_ACQ	0x20000	/* Program wait for VT release is done. */
25548114Sobrien	pid_t			 vw_pid;	/* Terminal holding process */
25648114Sobrien	struct proc		*vw_proc;
25748114Sobrien	struct vt_mode		 vw_smode;	/* switch mode */
25848114Sobrien	struct callout		 vw_proc_dead_timer;
25948114Sobrien	struct vt_window	*vw_switch_to;
26048114Sobrien};
26148114Sobrien
26248114Sobrien#define	VT_AUTO		0		/* switching is automatic */
26348114Sobrien#define	VT_PROCESS	1		/* switching controlled by prog */
26448114Sobrien#define	VT_KERNEL	255		/* switching controlled in kernel */
26548114Sobrien
26648114Sobrien#define	IS_VT_PROC_MODE(vw)	((vw)->vw_smode.mode == VT_PROCESS)
26748114Sobrien
26848114Sobrien/*
26948114Sobrien * Per-device driver routines.
27048114Sobrien *
27148114Sobrien * vd_bitbltchr is used when the driver operates in graphics mode, while
27248114Sobrien * vd_putchar is used when the driver operates in text mode
27348114Sobrien * (VDF_TEXTMODE).
27448114Sobrien */
27548114Sobrien
27648114Sobrientypedef int vd_init_t(struct vt_device *vd);
27748114Sobrientypedef void vd_postswitch_t(struct vt_device *vd);
27848114Sobrientypedef void vd_blank_t(struct vt_device *vd, term_color_t color);
27948114Sobrientypedef void vd_bitbltchr_t(struct vt_device *vd, const uint8_t *src,
28048114Sobrien    const uint8_t *mask, int bpl, vt_axis_t top, vt_axis_t left,
28148114Sobrien    unsigned int width, unsigned int height, term_color_t fg, term_color_t bg);
28248114Sobrientypedef void vd_putchar_t(struct vt_device *vd, term_char_t,
28348114Sobrien    vt_axis_t top, vt_axis_t left, term_color_t fg, term_color_t bg);
28448114Sobrien
28548114Sobrienstruct vt_driver {
286121099Srsm	/* Console attachment. */
28748114Sobrien	vd_init_t	*vd_init;
28848114Sobrien
28948114Sobrien	/* Drawing. */
29048114Sobrien	vd_blank_t	*vd_blank;
29148114Sobrien	vd_bitbltchr_t	*vd_bitbltchr;
292121099Srsm
293121099Srsm	/* Text mode operation. */
294121099Srsm	vd_putchar_t	*vd_putchar;
29548114Sobrien
29648114Sobrien	/* Update display setting on vt switch. */
29748114Sobrien	vd_postswitch_t	*vd_postswitch;
29848114Sobrien
29948114Sobrien	/* Priority to know which one can override */
30048114Sobrien	int		vd_priority;
30148114Sobrien#define	VD_PRIORITY_DUMB	10
30248114Sobrien#define	VD_PRIORITY_GENERIC	100
30348114Sobrien#define	VD_PRIORITY_SPECIFIC	1000
30448114Sobrien};
30548114Sobrien
30648114Sobrien/*
30747133Sobrien * Console device madness.
30847133Sobrien *
30948114Sobrien * Utility macro to make early vt(4) instances work.
31048114Sobrien */
31148114Sobrien
31248114Sobrienextern const struct terminal_class vt_termclass;
31348114Sobrienvoid vt_upgrade(struct vt_device *vd);
31447133Sobrien
31548114Sobrien#define	PIXEL_WIDTH(w)	((w) / 8)
31648114Sobrien#define	PIXEL_HEIGHT(h)	((h) / 16)
31748114Sobrien
31848114Sobrien#ifndef VT_FB_DEFAULT_WIDTH
31948114Sobrien#define	VT_FB_DEFAULT_WIDTH	640
32048114Sobrien#endif
32148114Sobrien#ifndef VT_FB_DEFAULT_HEIGHT
32248114Sobrien#define	VT_FB_DEFAULT_HEIGHT	480
32348114Sobrien#endif
32448114Sobrien
32548114Sobrien#define	VT_CONSDEV_DECLARE(driver, width, height, softc)		\
32647133Sobrienstatic struct terminal	driver ## _consterm;				\
32748114Sobrienstatic struct vt_window	driver ## _conswindow;				\
32848114Sobrienstatic struct vt_device	driver ## _consdev = {				\
32948114Sobrien	.vd_driver = &driver,						\
33048114Sobrien	.vd_softc = (softc),						\
33148114Sobrien	.vd_flags = VDF_INVALID,					\
33248114Sobrien	.vd_windows = { [VT_CONSWINDOW] =  &driver ## _conswindow, },	\
33348114Sobrien	.vd_curwindow = &driver ## _conswindow,				\
33448114Sobrien	.vd_markedwin = NULL,						\
33548114Sobrien	.vd_kbstate = 0,						\
33648114Sobrien};									\
33748114Sobrienstatic term_char_t	driver ## _constextbuf[(width) * 		\
33848114Sobrien	    (VBF_DEFAULT_HISTORY_SIZE)];				\
33948114Sobrienstatic term_char_t	*driver ## _constextbufrows[			\
34048114Sobrien	    VBF_DEFAULT_HISTORY_SIZE];					\
34148114Sobrienstatic struct vt_window	driver ## _conswindow = {			\
34248114Sobrien	.vw_number = VT_CONSWINDOW,					\
34348114Sobrien	.vw_flags = VWF_CONSOLE,					\
34448114Sobrien	.vw_buf = {							\
34548114Sobrien		.vb_buffer = driver ## _constextbuf,			\
34648114Sobrien		.vb_rows = driver ## _constextbufrows,			\
34748114Sobrien		.vb_history_size = VBF_DEFAULT_HISTORY_SIZE,		\
34848114Sobrien		.vb_curroffset = 0,					\
34948114Sobrien		.vb_roffset = 0,					\
35048114Sobrien		.vb_flags = VBF_STATIC,					\
35148114Sobrien		.vb_mark_start = {					\
35248114Sobrien			.tp_row = 0,					\
35348114Sobrien			.tp_col = 0,					\
35448114Sobrien		},							\
35547133Sobrien		.vb_mark_end = {					\
35648114Sobrien			.tp_row = 0,					\
35748114Sobrien			.tp_col = 0,					\
35848114Sobrien		},							\
35948114Sobrien		.vb_scr_size = {					\
36048114Sobrien			.tp_row = height,				\
36148114Sobrien			.tp_col = width,				\
36247133Sobrien		},							\
36347133Sobrien	},								\
36448114Sobrien	.vw_device = &driver ## _consdev,				\
36548114Sobrien	.vw_terminal = &driver ## _consterm,				\
36648114Sobrien	.vw_kbdmode = K_XLATE,						\
36748114Sobrien};									\
36848114SobrienTERMINAL_DECLARE_EARLY(driver ## _consterm, vt_termclass,		\
36948114Sobrien    &driver ## _conswindow);						\
37047133SobrienSYSINIT(vt_early_cons, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_ANY,		\
37148114Sobrien    vt_upgrade, &driver ## _consdev)
37248114Sobrien
373121099Srsm/*
37448114Sobrien * Fonts.
37548114Sobrien *
37648114Sobrien * Remapping tables are used to map Unicode points to glyphs.  They need
37748114Sobrien * to be sorted, because vtfont_lookup() performs a binary search.  Each
37847133Sobrien * font has two remapping tables, for normal and bold.  When a character
37948114Sobrien * is not present in bold, it uses a normal glyph.  When no glyph is
380121099Srsm * available, it uses glyph 0, which is normally equal to U+FFFD.
381121099Srsm */
38248114Sobrien
38348114Sobrienstruct vt_font_map {
38448114Sobrien	uint32_t		 vfm_src;
38548114Sobrien	uint16_t		 vfm_dst;
38648114Sobrien	uint16_t		 vfm_len;
38748114Sobrien};
38848114Sobrien
38948114Sobrienstruct vt_font {
39048114Sobrien	struct vt_font_map	*vf_bold;
39148114Sobrien	struct vt_font_map	*vf_normal;
39248114Sobrien	uint8_t			*vf_bytes;
39348114Sobrien	unsigned int		 vf_height, vf_width,
39448114Sobrien				 vf_normal_length, vf_bold_length;
39548114Sobrien	unsigned int		 vf_refcount;
39648114Sobrien};
39747133Sobrien
39848114Sobrien#ifndef SC_NO_CUTPASTE
39947133Sobrienstruct mouse_cursor {
40048114Sobrien	uint8_t map[64 * 64 / 8];
40148114Sobrien	uint8_t mask[64 * 64 / 8];
40248114Sobrien	uint8_t w;
40348114Sobrien	uint8_t h;
40447133Sobrien};
40547133Sobrien#endif
40647133Sobrien
40748114Sobrienconst uint8_t	*vtfont_lookup(const struct vt_font *vf, term_char_t c);
40847133Sobrienstruct vt_font	*vtfont_ref(struct vt_font *vf);
40948114Sobrienvoid		 vtfont_unref(struct vt_font *vf);
41048114Sobrienint		 vtfont_load(vfnt_t *f, struct vt_font **ret);
41148114Sobrien
41248114Sobrien/* Sysmouse. */
41347133Sobrienvoid sysmouse_process_event(mouse_info_t *mi);
41448114Sobrien#ifndef SC_NO_CUTPASTE
41547133Sobrienvoid vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel);
41648114Sobrienvoid vt_mouse_state(int show);
41747133Sobrien#endif
41848114Sobrien#define	VT_MOUSE_SHOW 1
41948114Sobrien#define	VT_MOUSE_HIDE 0
42048114Sobrien
42148114Sobrien#endif /* !_DEV_VT_VT_H_ */
42247133Sobrien
42347133Sobrien