qemu gtk显示系统分析
一:概念介绍
GTK(以前称为GIMP ToolKit和GTK+)是一个免费的开源 跨平台 小部件工具包,用于创建图形用户界面(GUI)。它根据GNU Lesser General Public License的条款获得许可,允许免费和专有软件使用它。它是Wayland和X11 窗口系统最流行的工具包之一。
二: 代码分析
2.1 QOM设备初始化
文件:gtk.c
type_init(register_gtk);
qemu_display_register(&qemu_display_gtk);
QemuDisplay *dpys[DISPLAY_TYPE_GTK] = qemu_display_gtk
2.2 dpy初始化
文件:vl.c
static DisplayOptions dpy;
qemu_create_default_devices
qemu_display_find_default
dpy->type = DISPLAY_TYPE_GTK
qemu_create_early_backends
qemu_display_early_init(&dpy);
dpys[dpy->type]->early_init
early_gtk_display_init
qemu_console_early_init();
audio_init_audiodevs
qemu_init_displays
init_displaystate
qemu_display_init(ds, &dpy);
dpys[opts->type]->init(ds, opts);
接上文: console.c
qemu_display_init
dpys[opts->type]->init(ds, opts);
接上文: gtk.c
gtk_display_init //GtkDisplayState
GtkDisplayState *s = g_malloc0(sizeof(*s));
s->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
s->notebook = gtk_notebook_new();
s->menu_bar = gtk_menu_bar_new();
s->null_cursor = gdk_cursor_new_for_display(window_display,
GDK_BLANK_CURSOR); //创建不可见的鼠标
s->mouse_mode_notifier.notify = gd_mouse_mode_change; //鼠标修改事件监听
gd_create_menus(s); //创建各个menu
s->machine_menu = gd_create_menu_machine(s);
s->view_menu = gd_create_menu_view(s);
gd_vc_gfx_init //创建各个vc并对应label
vc->gfx.drawing_area = gtk_drawing_area_new(); //创建画布区域
gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook),
vc->tab_item, gtk_label_new(vc->label)); //关联到label上
gd_connect_signals //为各个menu挂载操作响应回调