/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2015 Tycho Nightingale <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/types.h>2930#include "bhyvegc.h"31#include "console.h"3233static struct {34struct bhyvegc *gc;3536fb_render_func_t fb_render_cb;37void *fb_arg;3839kbd_event_func_t kbd_event_cb;40void *kbd_arg;41int kbd_priority;4243ptr_event_func_t ptr_event_cb;44void *ptr_arg;45int ptr_priority;46} console;4748void49console_init(int w, int h, void *fbaddr)50{51console.gc = bhyvegc_init(w, h, fbaddr);52}5354void55console_set_fbaddr(void *fbaddr)56{57bhyvegc_set_fbaddr(console.gc, fbaddr);58}5960struct bhyvegc_image *61console_get_image(void)62{63struct bhyvegc_image *bhyvegc_image;6465bhyvegc_image = bhyvegc_get_image(console.gc);6667return (bhyvegc_image);68}6970void71console_fb_register(fb_render_func_t render_cb, void *arg)72{73console.fb_render_cb = render_cb;74console.fb_arg = arg;75}7677void78console_refresh(void)79{80if (console.fb_render_cb)81(*console.fb_render_cb)(console.gc, console.fb_arg);82}8384void85console_kbd_register(kbd_event_func_t event_cb, void *arg, int pri)86{87if (pri > console.kbd_priority) {88console.kbd_event_cb = event_cb;89console.kbd_arg = arg;90console.kbd_priority = pri;91}92}9394void95console_ptr_register(ptr_event_func_t event_cb, void *arg, int pri)96{97if (pri > console.ptr_priority) {98console.ptr_event_cb = event_cb;99console.ptr_arg = arg;100console.ptr_priority = pri;101}102}103104void105console_key_event(int down, uint32_t keysym, uint32_t keycode)106{107if (console.kbd_event_cb)108(*console.kbd_event_cb)(down, keysym, keycode, console.kbd_arg);109}110111void112console_ptr_event(uint8_t button, int x, int y)113{114if (console.ptr_event_cb)115(*console.ptr_event_cb)(button, x, y, console.ptr_arg);116}117118119