1219888Sed/*-
2257547Sray * Copyright (c) 2009, 2013 The FreeBSD Foundation
3219888Sed * All rights reserved.
4219888Sed *
5219888Sed * This software was developed by Ed Schouten under sponsorship from the
6219888Sed * FreeBSD Foundation.
7219888Sed *
8257547Sray * Portions of this software were developed by Oleksandr Rybalko
9257547Sray * under sponsorship from the FreeBSD Foundation.
10257547Sray *
11219888Sed * Redistribution and use in source and binary forms, with or without
12219888Sed * modification, are permitted provided that the following conditions
13219888Sed * are met:
14219888Sed * 1. Redistributions of source code must retain the above copyright
15219888Sed *    notice, this list of conditions and the following disclaimer.
16219888Sed * 2. Redistributions in binary form must reproduce the above copyright
17219888Sed *    notice, this list of conditions and the following disclaimer in the
18219888Sed *    documentation and/or other materials provided with the distribution.
19219888Sed *
20219888Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21219888Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22219888Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23219888Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24219888Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25219888Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26219888Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27219888Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28219888Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29219888Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30219888Sed * SUCH DAMAGE.
31219888Sed *
32219888Sed * $FreeBSD$
33219888Sed */
34219888Sed
35219888Sed#ifndef _DEV_VT_VT_H_
36219888Sed#define	_DEV_VT_VT_H_
37219888Sed
38219888Sed#include <sys/param.h>
39219888Sed#include <sys/_lock.h>
40219888Sed#include <sys/_mutex.h>
41219888Sed#include <sys/callout.h>
42219888Sed#include <sys/condvar.h>
43263817Sray#include <sys/conf.h>
44219888Sed#include <sys/consio.h>
45219888Sed#include <sys/kbio.h>
46257974Sray#include <sys/mouse.h>
47219888Sed#include <sys/terminal.h>
48256145Sray#include <sys/sysctl.h>
49219888Sed
50257966Sray#include "opt_syscons.h"
51263817Sray#include "opt_splash.h"
52257966Sray
53263817Sray#ifdef DEV_SC
54263817Sray#error "Build with both syscons and vt is not supported. Please enable only \
55263817Srayone 'device sc' or 'device vt'"
56263817Sray#endif
57263817Sray
58257966Sray#ifndef	VT_MAXWINDOWS
59257966Sray#ifdef	MAXCONS
60257966Sray#define	VT_MAXWINDOWS	MAXCONS
61257966Sray#else
62219888Sed#define	VT_MAXWINDOWS	12
63257966Sray#endif
64257966Sray#endif
65257966Sray
66258165Sray#ifndef VT_ALT_TO_ESC_HACK
67258165Sray#define	VT_ALT_TO_ESC_HACK	1
68258165Sray#endif
69258165Sray
70219888Sed#define	VT_CONSWINDOW	0
71219888Sed
72257966Sray#if defined(SC_TWOBUTTON_MOUSE) || defined(VT_TWOBUTTON_MOUSE)
73257966Sray#define VT_MOUSE_PASTEBUTTON	MOUSE_BUTTON3DOWN	/* right button */
74257966Sray#define VT_MOUSE_EXTENDBUTTON	MOUSE_BUTTON2DOWN	/* not really used */
75257966Sray#else
76257966Sray#define VT_MOUSE_PASTEBUTTON	MOUSE_BUTTON2DOWN	/* middle button */
77257966Sray#define VT_MOUSE_EXTENDBUTTON	MOUSE_BUTTON3DOWN	/* right button */
78257966Sray#endif /* defined(SC_TWOBUTTON_MOUSE) || defined(VT_TWOBUTTON_MOUSE) */
79257966Sray
80256145Sray#define	SC_DRIVER_NAME	"vt"
81256145Sray#define	DPRINTF(_l, ...)	if (vt_debug > (_l)) printf( __VA_ARGS__ )
82256145Sray#define	ISSIGVALID(sig)	((sig) > 0 && (sig) < NSIG)
83256145Sray
84256145Sray#define	VT_SYSCTL_INT(_name, _default, _descr)				\
85256145Sraystatic int vt_##_name = _default;					\
86256145SraySYSCTL_INT(_kern_vt, OID_AUTO, _name, CTLFLAG_RW, &vt_##_name, _default,\
87256145Sray		_descr);						\
88256145SrayTUNABLE_INT("kern.vt." #_name, &vt_##_name);
89256145Sray
90219888Sedstruct vt_driver;
91219888Sed
92219888Sedvoid vt_allocate(struct vt_driver *, void *);
93257815Srayvoid vt_resume(void);
94257815Srayvoid vt_suspend(void);
95219888Sed
96219888Sedtypedef unsigned int 	vt_axis_t;
97219888Sed
98219888Sed/*
99219888Sed * List of locks
100219888Sed * (d)	locked by vd_lock
101219888Sed * (b)	locked by vb_lock
102219888Sed * (G)	locked by Giant
103219888Sed * (u)	unlocked, locked by higher levels
104219888Sed * (c)	const until freeing
105219888Sed * (?)	yet to be determined
106219888Sed */
107219888Sed
108219888Sed/*
109219888Sed * Per-device datastructure.
110219888Sed */
111219888Sed
112219888Sedstruct vt_device {
113219888Sed	struct vt_window	*vd_windows[VT_MAXWINDOWS]; /* (c) Windows. */
114219888Sed	struct vt_window	*vd_curwindow;	/* (d) Current window. */
115257815Sray	struct vt_window	*vd_savedwindow;/* (?) Saved for suspend. */
116258090Sray	struct vt_window	*vd_markedwin;	/* (?) Copy/paste buf owner. */
117219888Sed	const struct vt_driver	*vd_driver;	/* (c) Graphics driver. */
118219888Sed	void			*vd_softc;	/* (u) Driver data. */
119257974Sray	uint16_t		 vd_mx;		/* (?) Mouse X. */
120257974Sray	uint16_t		 vd_my;		/* (?) Mouse Y. */
121257974Sray	vt_axis_t		 vd_mdirtyx;	/* (?) Screen width. */
122257974Sray	vt_axis_t		 vd_mdirtyy;	/* (?) Screen height. */
123257974Sray	uint32_t		 vd_mstate;	/* (?) Mouse state. */
124257974Sray	term_pos_t		 vd_offset;	/* (?) Pixel offset. */
125219888Sed	vt_axis_t		 vd_width;	/* (?) Screen width. */
126219888Sed	vt_axis_t		 vd_height;	/* (?) Screen height. */
127219888Sed	struct mtx		 vd_lock;	/* Per-device lock. */
128219888Sed	struct cv		 vd_winswitch;	/* (d) Window switch notify. */
129219888Sed	struct callout		 vd_timer;	/* (d) Display timer. */
130219888Sed	int			 vd_flags;	/* (d) Device flags. */
131219888Sed#define	VDF_TEXTMODE	0x01	/* Do text mode rendering. */
132219888Sed#define	VDF_SPLASH	0x02	/* Splash screen active. */
133219888Sed#define	VDF_ASYNC	0x04	/* vt_timer() running. */
134219888Sed#define	VDF_INVALID	0x08	/* Entire screen should be re-rendered. */
135219888Sed#define	VDF_DEAD	0x10	/* Early probing found nothing. */
136256145Sray#define	VDF_INITIALIZED	0x20	/* vtterm_cnprobe already done. */
137257974Sray#define	VDF_MOUSECURSOR	0x40	/* Mouse cursor visible. */
138263817Sray#define	VDF_QUIET_BELL	0x80	/* Disable bell. */
139219888Sed	int			 vd_keyboard;	/* (G) Keyboard index. */
140258165Sray	unsigned int		 vd_kbstate;	/* (?) Device unit. */
141219888Sed	unsigned int		 vd_unit;	/* (c) Device unit. */
142219888Sed};
143219888Sed
144219888Sed/*
145219888Sed * Per-window terminal screen buffer.
146219888Sed *
147219888Sed * Because redrawing is performed asynchronously, the buffer keeps track
148219888Sed * of a rectangle that needs to be redrawn (vb_dirtyrect).  Because this
149219888Sed * approach seemed to cause suboptimal performance (when the top left
150219888Sed * and the bottom right of the screen are modified), it also uses a set
151219888Sed * of bitmasks to keep track of the rows and columns (mod 64) that have
152219888Sed * been modified.
153219888Sed */
154219888Sed
155219888Sedstruct vt_bufmask {
156219888Sed	uint64_t		 vbm_row, vbm_col;
157219888Sed#define	VBM_DIRTY		UINT64_MAX
158219888Sed};
159219888Sed
160219888Sedstruct vt_buf {
161219888Sed	struct mtx		 vb_lock;	/* Buffer lock. */
162256145Sray	term_pos_t		 vb_scr_size;	/* (b) Screen dimensions. */
163219888Sed	int			 vb_flags;	/* (b) Flags. */
164219888Sed#define	VBF_CURSOR	0x1	/* Cursor visible. */
165219888Sed#define	VBF_STATIC	0x2	/* Buffer is statically allocated. */
166256145Sray#define	VBF_MTX_INIT	0x4	/* Mutex initialized. */
167256145Sray#define	VBF_SCROLL	0x8	/* scroll locked mode. */
168256964Sray#define	VBF_HISTORY_FULL 0x10	/* All rows filled. */
169256145Sray	int			 vb_history_size;
170257723Sray#define	VBF_DEFAULT_HISTORY_SIZE	500
171256145Sray	int			 vb_roffset;	/* (b) History rows offset. */
172256145Sray	int			 vb_curroffset;	/* (b) Saved rows offset. */
173219888Sed	term_pos_t		 vb_cursor;	/* (u) Cursor position. */
174257972Sray	term_pos_t		 vb_mark_start;	/* (b) Copy region start. */
175257972Sray	term_pos_t		 vb_mark_end;	/* (b) Copy region end. */
176258130Sray	int			 vb_mark_last;	/* Last mouse event. */
177219888Sed	term_rect_t		 vb_dirtyrect;	/* (b) Dirty rectangle. */
178219888Sed	struct vt_bufmask	 vb_dirtymask;	/* (b) Dirty bitmasks. */
179219888Sed	term_char_t		*vb_buffer;	/* (u) Data buffer. */
180256145Sray	term_char_t		**vb_rows;	/* (u) Array of rows */
181219888Sed};
182219888Sed
183219888Sedvoid vtbuf_copy(struct vt_buf *, const term_rect_t *, const term_pos_t *);
184256145Srayvoid vtbuf_fill_locked(struct vt_buf *, const term_rect_t *, term_char_t);
185219888Sedvoid vtbuf_init_early(struct vt_buf *);
186219888Sedvoid vtbuf_init(struct vt_buf *, const term_pos_t *);
187256145Srayvoid vtbuf_grow(struct vt_buf *, const term_pos_t *, int);
188219888Sedvoid vtbuf_putchar(struct vt_buf *, const term_pos_t *, term_char_t);
189219888Sedvoid vtbuf_cursor_position(struct vt_buf *, const term_pos_t *);
190258090Srayvoid vtbuf_scroll_mode(struct vt_buf *vb, int yes);
191219888Sedvoid vtbuf_undirty(struct vt_buf *, term_rect_t *, struct vt_bufmask *);
192256145Srayvoid vtbuf_sethistory_size(struct vt_buf *, int);
193263817Srayint vtbuf_iscursor(struct vt_buf *vb, int row, int col);
194263817Srayvoid vtbuf_cursor_visibility(struct vt_buf *, int);
195263817Sray#ifndef SC_NO_CUTPASTE
196263817Srayvoid vtbuf_mouse_cursor_position(struct vt_buf *vb, int col, int row);
197258090Srayint vtbuf_set_mark(struct vt_buf *vb, int type, int col, int row);
198258090Srayint vtbuf_get_marked_len(struct vt_buf *vb);
199258090Srayvoid vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz);
200263817Sray#endif
201256145Sray
202258090Sray#define	VTB_MARK_NONE		0
203257973Sray#define	VTB_MARK_END		1
204257973Sray#define	VTB_MARK_START		2
205257973Sray#define	VTB_MARK_WORD		3
206257973Sray#define	VTB_MARK_ROW		4
207257973Sray#define	VTB_MARK_EXTEND		5
208258130Sray#define	VTB_MARK_MOVE		6
209257973Sray
210258090Sray#define	VTBUF_SLCK_ENABLE(vb)	vtbuf_scroll_mode((vb), 1)
211258090Sray#define	VTBUF_SLCK_DISABLE(vb)	vtbuf_scroll_mode((vb), 0)
212256145Sray
213256145Sray#define	VTBUF_MAX_HEIGHT(vb) \
214256145Sray	((vb)->vb_history_size)
215256145Sray#define	VTBUF_GET_ROW(vb, r) \
216256145Sray	((vb)->vb_rows[((vb)->vb_roffset + (r)) % VTBUF_MAX_HEIGHT(vb)])
217256145Sray#define	VTBUF_GET_FIELD(vb, r, c) \
218256145Sray	((vb)->vb_rows[((vb)->vb_roffset + (r)) % VTBUF_MAX_HEIGHT(vb)][(c)])
219219888Sed#define	VTBUF_FIELD(vb, r, c) \
220256145Sray	((vb)->vb_rows[((vb)->vb_curroffset + (r)) % VTBUF_MAX_HEIGHT(vb)][(c)])
221219888Sed#define	VTBUF_ISCURSOR(vb, r, c) \
222257975Sray	vtbuf_iscursor((vb), (r), (c))
223219888Sed#define	VTBUF_DIRTYROW(mask, row) \
224219888Sed	((mask)->vbm_row & ((uint64_t)1 << ((row) % 64)))
225219888Sed#define	VTBUF_DIRTYCOL(mask, col) \
226219888Sed	((mask)->vbm_col & ((uint64_t)1 << ((col) % 64)))
227256145Sray#define	VTBUF_SPACE_CHAR	(' ' | TC_WHITE << 26 | TC_BLACK << 29)
228219888Sed
229219888Sed#define	VHS_SET	0
230219888Sed#define	VHS_CUR	1
231219888Sed#define	VHS_END	2
232256145Srayint vthistory_seek(struct vt_buf *, int offset, int whence);
233256145Srayvoid vthistory_addlines(struct vt_buf *vb, int offset);
234256145Srayvoid vthistory_getpos(const struct vt_buf *, unsigned int *offset);
235219888Sed
236219888Sed/*
237219888Sed * Per-window datastructure.
238219888Sed */
239219888Sed
240219888Sedstruct vt_window {
241219888Sed	struct vt_device	*vw_device;	/* (c) Device. */
242219888Sed	struct terminal		*vw_terminal;	/* (c) Terminal. */
243219888Sed	struct vt_buf		 vw_buf;	/* (u) Screen buffer. */
244219888Sed	struct vt_font		*vw_font;	/* (d) Graphical font. */
245219888Sed	unsigned int		 vw_number;	/* (c) Window number. */
246219888Sed	int			 vw_kbdmode;	/* (?) Keyboard mode. */
247257076Sray	char			*vw_kbdsq;	/* Escape sequence queue*/
248219888Sed	unsigned int		 vw_flags;	/* (d) Per-window flags. */
249263817Sray	int			 vw_mouse_level;/* Mouse op mode. */
250219888Sed#define	VWF_BUSY	0x1	/* Busy reconfiguring device. */
251219888Sed#define	VWF_OPENED	0x2	/* TTY in use. */
252219888Sed#define	VWF_SCROLL	0x4	/* Keys influence scrollback. */
253219888Sed#define	VWF_CONSOLE	0x8	/* Kernel message console window. */
254256145Sray#define	VWF_VTYLOCK	0x10	/* Prevent window switch. */
255258327Sray#define	VWF_MOUSE_HIDE	0x20	/* Disable mouse events processing. */
256256145Sray#define	VWF_SWWAIT_REL	0x10000	/* Program wait for VT acquire is done. */
257256145Sray#define	VWF_SWWAIT_ACQ	0x20000	/* Program wait for VT release is done. */
258256145Sray	pid_t			 vw_pid;	/* Terminal holding process */
259256145Sray	struct proc		*vw_proc;
260256145Sray	struct vt_mode		 vw_smode;	/* switch mode */
261256145Sray	struct callout		 vw_proc_dead_timer;
262256145Sray	struct vt_window	*vw_switch_to;
263219888Sed};
264219888Sed
265256145Sray#define	VT_AUTO		0		/* switching is automatic */
266256145Sray#define	VT_PROCESS	1		/* switching controlled by prog */
267256145Sray#define	VT_KERNEL	255		/* switching controlled in kernel */
268256145Sray
269256145Sray#define	IS_VT_PROC_MODE(vw)	((vw)->vw_smode.mode == VT_PROCESS)
270256145Sray
271219888Sed/*
272219888Sed * Per-device driver routines.
273219888Sed *
274256527Sray * vd_bitbltchr is used when the driver operates in graphics mode, while
275219888Sed * vd_putchar is used when the driver operates in text mode
276219888Sed * (VDF_TEXTMODE).
277219888Sed */
278219888Sed
279219888Sedtypedef int vd_init_t(struct vt_device *vd);
280256145Sraytypedef void vd_postswitch_t(struct vt_device *vd);
281219888Sedtypedef void vd_blank_t(struct vt_device *vd, term_color_t color);
282256527Sraytypedef void vd_bitbltchr_t(struct vt_device *vd, const uint8_t *src,
283257988Sray    const uint8_t *mask, int bpl, vt_axis_t top, vt_axis_t left,
284257988Sray    unsigned int width, unsigned int height, term_color_t fg, term_color_t bg);
285264113Sraytypedef void vd_maskbitbltchr_t(struct vt_device *vd, const uint8_t *src,
286264113Sray    const uint8_t *mask, int bpl, vt_axis_t top, vt_axis_t left,
287264113Sray    unsigned int width, unsigned int height, term_color_t fg, term_color_t bg);
288219888Sedtypedef void vd_putchar_t(struct vt_device *vd, term_char_t,
289219888Sed    vt_axis_t top, vt_axis_t left, term_color_t fg, term_color_t bg);
290263817Sraytypedef int vd_fb_ioctl_t(struct vt_device *, u_long, caddr_t, struct thread *);
291263817Sraytypedef int vd_fb_mmap_t(struct vt_device *, vm_ooffset_t, vm_paddr_t *, int,
292263817Sray    vm_memattr_t *);
293263817Sraytypedef void vd_drawrect_t(struct vt_device *, int, int, int, int, int,
294263817Sray    term_color_t);
295263817Sraytypedef void vd_setpixel_t(struct vt_device *, int, int, term_color_t);
296219888Sed
297219888Sedstruct vt_driver {
298219888Sed	/* Console attachment. */
299256145Sray	vd_init_t	*vd_init;
300219888Sed
301219888Sed	/* Drawing. */
302256145Sray	vd_blank_t	*vd_blank;
303256527Sray	vd_bitbltchr_t	*vd_bitbltchr;
304264113Sray	vd_maskbitbltchr_t *vd_maskbitbltchr;
305263817Sray	vd_drawrect_t	*vd_drawrect;
306263817Sray	vd_setpixel_t	*vd_setpixel;
307219888Sed
308263817Sray	/* Framebuffer ioctls, if present. */
309263817Sray	vd_fb_ioctl_t	*vd_fb_ioctl;
310263817Sray
311263817Sray	/* Framebuffer mmap, if present. */
312263817Sray	vd_fb_mmap_t	*vd_fb_mmap;
313263817Sray
314219888Sed	/* Text mode operation. */
315256145Sray	vd_putchar_t	*vd_putchar;
316256145Sray
317256145Sray	/* Update display setting on vt switch. */
318256145Sray	vd_postswitch_t	*vd_postswitch;
319256145Sray
320256145Sray	/* Priority to know which one can override */
321256145Sray	int		vd_priority;
322256902Sray#define	VD_PRIORITY_DUMB	10
323256902Sray#define	VD_PRIORITY_GENERIC	100
324256902Sray#define	VD_PRIORITY_SPECIFIC	1000
325219888Sed};
326219888Sed
327219888Sed/*
328219888Sed * Console device madness.
329219888Sed *
330219888Sed * Utility macro to make early vt(4) instances work.
331219888Sed */
332219888Sed
333219888Sedextern const struct terminal_class vt_termclass;
334219888Sedvoid vt_upgrade(struct vt_device *vd);
335219888Sed
336219888Sed#define	PIXEL_WIDTH(w)	((w) / 8)
337219888Sed#define	PIXEL_HEIGHT(h)	((h) / 16)
338219888Sed
339257724Sray#ifndef VT_FB_DEFAULT_WIDTH
340257724Sray#define	VT_FB_DEFAULT_WIDTH	640
341257724Sray#endif
342257724Sray#ifndef VT_FB_DEFAULT_HEIGHT
343257724Sray#define	VT_FB_DEFAULT_HEIGHT	480
344257724Sray#endif
345257724Sray
346219888Sed#define	VT_CONSDEV_DECLARE(driver, width, height, softc)		\
347219888Sedstatic struct terminal	driver ## _consterm;				\
348219888Sedstatic struct vt_window	driver ## _conswindow;				\
349219888Sedstatic struct vt_device	driver ## _consdev = {				\
350219888Sed	.vd_driver = &driver,						\
351219888Sed	.vd_softc = (softc),						\
352219888Sed	.vd_flags = VDF_INVALID,					\
353219888Sed	.vd_windows = { [VT_CONSWINDOW] =  &driver ## _conswindow, },	\
354219888Sed	.vd_curwindow = &driver ## _conswindow,				\
355258090Sray	.vd_markedwin = NULL,						\
356258165Sray	.vd_kbstate = 0,						\
357219888Sed};									\
358256145Sraystatic term_char_t	driver ## _constextbuf[(width) * 		\
359256145Sray	    (VBF_DEFAULT_HISTORY_SIZE)];				\
360256145Sraystatic term_char_t	*driver ## _constextbufrows[			\
361256145Sray	    VBF_DEFAULT_HISTORY_SIZE];					\
362219888Sedstatic struct vt_window	driver ## _conswindow = {			\
363219888Sed	.vw_number = VT_CONSWINDOW,					\
364219888Sed	.vw_flags = VWF_CONSOLE,					\
365219888Sed	.vw_buf = {							\
366219888Sed		.vb_buffer = driver ## _constextbuf,			\
367256145Sray		.vb_rows = driver ## _constextbufrows,			\
368256145Sray		.vb_history_size = VBF_DEFAULT_HISTORY_SIZE,		\
369256145Sray		.vb_curroffset = 0,					\
370256145Sray		.vb_roffset = 0,					\
371219888Sed		.vb_flags = VBF_STATIC,					\
372257972Sray		.vb_mark_start = {					\
373257972Sray			.tp_row = 0,					\
374257972Sray			.tp_col = 0,					\
375257972Sray		},							\
376257972Sray		.vb_mark_end = {					\
377257972Sray			.tp_row = 0,					\
378257972Sray			.tp_col = 0,					\
379257972Sray		},							\
380256145Sray		.vb_scr_size = {					\
381219888Sed			.tp_row = height,				\
382219888Sed			.tp_col = width,				\
383219888Sed		},							\
384219888Sed	},								\
385219888Sed	.vw_device = &driver ## _consdev,				\
386219888Sed	.vw_terminal = &driver ## _consterm,				\
387219888Sed	.vw_kbdmode = K_XLATE,						\
388219888Sed};									\
389219888SedTERMINAL_DECLARE_EARLY(driver ## _consterm, vt_termclass,		\
390219888Sed    &driver ## _conswindow);						\
391219888SedSYSINIT(vt_early_cons, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_ANY,		\
392219888Sed    vt_upgrade, &driver ## _consdev)
393219888Sed
394219888Sed/*
395219888Sed * Fonts.
396219888Sed *
397219888Sed * Remapping tables are used to map Unicode points to glyphs.  They need
398219888Sed * to be sorted, because vtfont_lookup() performs a binary search.  Each
399219888Sed * font has two remapping tables, for normal and bold.  When a character
400219888Sed * is not present in bold, it uses a normal glyph.  When no glyph is
401219888Sed * available, it uses glyph 0, which is normally equal to U+FFFD.
402219888Sed */
403219888Sed
404219888Sedstruct vt_font_map {
405219888Sed	uint32_t		 vfm_src;
406219888Sed	uint16_t		 vfm_dst;
407219888Sed	uint16_t		 vfm_len;
408219888Sed};
409219888Sed
410219888Sedstruct vt_font {
411263817Sray	struct vt_font_map	*vf_map[VFNT_MAPS];
412219888Sed	uint8_t			*vf_bytes;
413263817Sray	unsigned int		 vf_height, vf_width;
414263817Sray	unsigned int		 vf_map_count[VFNT_MAPS];
415219888Sed	unsigned int		 vf_refcount;
416219888Sed};
417219888Sed
418263817Sray#ifndef SC_NO_CUTPASTE
419257967Sraystruct mouse_cursor {
420257967Sray	uint8_t map[64 * 64 / 8];
421257967Sray	uint8_t mask[64 * 64 / 8];
422257967Sray	uint8_t w;
423257967Sray	uint8_t h;
424257967Sray};
425263817Sray#endif
426257967Sray
427219888Sedconst uint8_t	*vtfont_lookup(const struct vt_font *vf, term_char_t c);
428219888Sedstruct vt_font	*vtfont_ref(struct vt_font *vf);
429219888Sedvoid		 vtfont_unref(struct vt_font *vf);
430219888Sedint		 vtfont_load(vfnt_t *f, struct vt_font **ret);
431219888Sed
432219888Sed/* Sysmouse. */
433219888Sedvoid sysmouse_process_event(mouse_info_t *mi);
434263817Sray#ifndef SC_NO_CUTPASTE
435263817Srayvoid vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel);
436258327Srayvoid vt_mouse_state(int show);
437263817Sray#endif
438258327Sray#define	VT_MOUSE_SHOW 1
439258327Sray#define	VT_MOUSE_HIDE 0
440219888Sed
441219888Sed#endif /* !_DEV_VT_VT_H_ */
442258327Sray
443