xref: /illumos-gate/usr/src/cmd/bhyve/console.c (revision bf21cd9318e0a3a51b7f02c14a7c1b1aef2dc861)
1 /*-
2  * Copyright (c) 2015 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include <sys/types.h>
31 
32 #include "bhyvegc.h"
33 #include "console.h"
34 
35 static struct {
36 	struct bhyvegc		*gc;
37 
38 	fb_render_func_t	fb_render_cb;
39 	void			*fb_arg;
40 
41 	kbd_event_func_t	kbd_event_cb;
42 	void			*kbd_arg;
43 
44 	ptr_event_func_t	ptr_event_cb;
45 	void			*ptr_arg;
46 } console;
47 
48 void
49 console_init(void)
50 {
51 	console.gc = bhyvegc_init(640, 400);
52 }
53 
54 struct bhyvegc_image *
55 console_get_image(void)
56 {
57 	struct bhyvegc_image *bhyvegc_image;
58 
59 	bhyvegc_image = bhyvegc_get_image(console.gc);
60 
61 	return (bhyvegc_image);
62 }
63 
64 void
65 console_fb_register(fb_render_func_t render_cb, void *arg)
66 {
67 	console.fb_render_cb = render_cb;
68 	console.fb_arg = arg;
69 }
70 
71 void
72 console_refresh(void)
73 {
74 	(*console.fb_render_cb)(console.gc, console.fb_arg);
75 }
76 
77 void
78 console_kbd_register(kbd_event_func_t event_cb, void *arg)
79 {
80 	console.kbd_event_cb = event_cb;
81 	console.kbd_arg = arg;
82 }
83 
84 void
85 console_ptr_register(ptr_event_func_t event_cb, void *arg)
86 {
87 	console.ptr_event_cb = event_cb;
88 	console.ptr_arg = arg;
89 }
90 
91 void
92 console_key_event(int down, uint32_t keysym)
93 {
94 	(*console.kbd_event_cb)(down, keysym, console.kbd_arg);
95 }
96 
97 void
98 console_ptr_event(uint8_t button, int x, int y)
99 {
100 	(*console.ptr_event_cb)(button, x, y, console.ptr_arg);
101 }
102