mirror of https://github.com/xqemu/xqemu.git
sdl2: add support for display rendering using opengl.
Add new sdl2-gl.c file, with display rendering functions using opengl. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
19dadfccd0
commit
0b71a5d5ca
|
@ -354,6 +354,7 @@ void surface_gl_setup_viewport(ConsoleGLState *gls,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* sdl.c */
|
/* sdl.c */
|
||||||
|
void sdl_display_early_init(int opengl);
|
||||||
void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
|
void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
|
||||||
|
|
||||||
/* cocoa.m */
|
/* cocoa.m */
|
||||||
|
|
|
@ -17,6 +17,10 @@ struct sdl2_console {
|
||||||
int last_vm_running; /* per console for caption reasons */
|
int last_vm_running; /* per console for caption reasons */
|
||||||
int x, y;
|
int x, y;
|
||||||
int hidden;
|
int hidden;
|
||||||
|
int opengl;
|
||||||
|
int updates;
|
||||||
|
SDL_GLContext winctx;
|
||||||
|
ConsoleGLState *gls;
|
||||||
};
|
};
|
||||||
|
|
||||||
void sdl2_window_create(struct sdl2_console *scon);
|
void sdl2_window_create(struct sdl2_console *scon);
|
||||||
|
@ -37,4 +41,11 @@ void sdl2_2d_redraw(struct sdl2_console *scon);
|
||||||
bool sdl2_2d_check_format(DisplayChangeListener *dcl,
|
bool sdl2_2d_check_format(DisplayChangeListener *dcl,
|
||||||
pixman_format_code_t format);
|
pixman_format_code_t format);
|
||||||
|
|
||||||
|
void sdl2_gl_update(DisplayChangeListener *dcl,
|
||||||
|
int x, int y, int w, int h);
|
||||||
|
void sdl2_gl_switch(DisplayChangeListener *dcl,
|
||||||
|
DisplaySurface *new_surface);
|
||||||
|
void sdl2_gl_refresh(DisplayChangeListener *dcl);
|
||||||
|
void sdl2_gl_redraw(struct sdl2_console *scon);
|
||||||
|
|
||||||
#endif /* SDL2_H */
|
#endif /* SDL2_H */
|
||||||
|
|
|
@ -21,6 +21,9 @@ sdl.mo-objs := sdl.o sdl_zoom.o
|
||||||
endif
|
endif
|
||||||
ifeq ($(CONFIG_SDLABI),2.0)
|
ifeq ($(CONFIG_SDLABI),2.0)
|
||||||
sdl.mo-objs := sdl2.o sdl2-input.o sdl2-2d.o
|
sdl.mo-objs := sdl2.o sdl2-input.o sdl2-2d.o
|
||||||
|
ifeq ($(CONFIG_OPENGL),y)
|
||||||
|
sdl.mo-objs += sdl2-gl.o
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
sdl.mo-cflags := $(SDL_CFLAGS)
|
sdl.mo-cflags := $(SDL_CFLAGS)
|
||||||
|
|
||||||
|
|
10
ui/sdl.c
10
ui/sdl.c
|
@ -908,6 +908,16 @@ static const DisplayChangeListenerOps dcl_ops = {
|
||||||
.dpy_cursor_define = sdl_mouse_define,
|
.dpy_cursor_define = sdl_mouse_define,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void sdl_display_early_init(int opengl)
|
||||||
|
{
|
||||||
|
if (opengl == 1 /* on */) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"SDL1 display code has no opengl support.\n"
|
||||||
|
"Please recompile qemu with SDL2, using\n"
|
||||||
|
"./configure --enable-sdl --with-sdlabi=2.0\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
|
void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
|
|
|
@ -36,6 +36,8 @@ void sdl2_2d_update(DisplayChangeListener *dcl,
|
||||||
DisplaySurface *surf = qemu_console_surface(dcl->con);
|
DisplaySurface *surf = qemu_console_surface(dcl->con);
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
|
|
||||||
|
assert(!scon->opengl);
|
||||||
|
|
||||||
if (!surf) {
|
if (!surf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +63,8 @@ void sdl2_2d_switch(DisplayChangeListener *dcl,
|
||||||
DisplaySurface *old_surface = scon->surface;
|
DisplaySurface *old_surface = scon->surface;
|
||||||
int format = 0;
|
int format = 0;
|
||||||
|
|
||||||
|
assert(!scon->opengl);
|
||||||
|
|
||||||
scon->surface = new_surface;
|
scon->surface = new_surface;
|
||||||
|
|
||||||
if (scon->texture) {
|
if (scon->texture) {
|
||||||
|
@ -101,12 +105,15 @@ void sdl2_2d_refresh(DisplayChangeListener *dcl)
|
||||||
{
|
{
|
||||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||||
|
|
||||||
|
assert(!scon->opengl);
|
||||||
graphic_hw_update(dcl->con);
|
graphic_hw_update(dcl->con);
|
||||||
sdl2_poll_events(scon);
|
sdl2_poll_events(scon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdl2_2d_redraw(struct sdl2_console *scon)
|
void sdl2_2d_redraw(struct sdl2_console *scon)
|
||||||
{
|
{
|
||||||
|
assert(!scon->opengl);
|
||||||
|
|
||||||
if (!scon->surface) {
|
if (!scon->surface) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,112 @@
|
||||||
|
/*
|
||||||
|
* QEMU SDL display driver -- opengl support
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Red Hat
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Gerd Hoffmann <kraxel@redhat.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qemu-common.h"
|
||||||
|
#include "ui/console.h"
|
||||||
|
#include "ui/input.h"
|
||||||
|
#include "ui/sdl2.h"
|
||||||
|
#include "sysemu/sysemu.h"
|
||||||
|
|
||||||
|
static void sdl2_gl_render_surface(struct sdl2_console *scon)
|
||||||
|
{
|
||||||
|
int ww, wh;
|
||||||
|
|
||||||
|
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
|
||||||
|
|
||||||
|
SDL_GetWindowSize(scon->real_window, &ww, &wh);
|
||||||
|
surface_gl_setup_viewport(scon->gls, scon->surface, ww, wh);
|
||||||
|
|
||||||
|
surface_gl_render_texture(scon->gls, scon->surface);
|
||||||
|
SDL_GL_SwapWindow(scon->real_window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sdl2_gl_update(DisplayChangeListener *dcl,
|
||||||
|
int x, int y, int w, int h)
|
||||||
|
{
|
||||||
|
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||||
|
|
||||||
|
assert(scon->opengl);
|
||||||
|
|
||||||
|
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
|
||||||
|
surface_gl_update_texture(scon->gls, scon->surface, x, y, w, h);
|
||||||
|
scon->updates++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sdl2_gl_switch(DisplayChangeListener *dcl,
|
||||||
|
DisplaySurface *new_surface)
|
||||||
|
{
|
||||||
|
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||||
|
DisplaySurface *old_surface = scon->surface;
|
||||||
|
|
||||||
|
assert(scon->opengl);
|
||||||
|
|
||||||
|
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
|
||||||
|
surface_gl_destroy_texture(scon->gls, scon->surface);
|
||||||
|
|
||||||
|
scon->surface = new_surface;
|
||||||
|
|
||||||
|
if (!new_surface) {
|
||||||
|
console_gl_fini_context(scon->gls);
|
||||||
|
scon->gls = NULL;
|
||||||
|
sdl2_window_destroy(scon);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!scon->real_window) {
|
||||||
|
sdl2_window_create(scon);
|
||||||
|
scon->gls = console_gl_init_context();
|
||||||
|
} else if (old_surface &&
|
||||||
|
((surface_width(old_surface) != surface_width(new_surface)) ||
|
||||||
|
(surface_height(old_surface) != surface_height(new_surface)))) {
|
||||||
|
sdl2_window_resize(scon);
|
||||||
|
}
|
||||||
|
|
||||||
|
surface_gl_create_texture(scon->gls, scon->surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sdl2_gl_refresh(DisplayChangeListener *dcl)
|
||||||
|
{
|
||||||
|
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||||
|
|
||||||
|
assert(scon->opengl);
|
||||||
|
|
||||||
|
graphic_hw_update(dcl->con);
|
||||||
|
if (scon->updates && scon->surface) {
|
||||||
|
scon->updates = 0;
|
||||||
|
sdl2_gl_render_surface(scon);
|
||||||
|
}
|
||||||
|
sdl2_poll_events(scon);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sdl2_gl_redraw(struct sdl2_console *scon)
|
||||||
|
{
|
||||||
|
assert(scon->opengl);
|
||||||
|
|
||||||
|
if (scon->surface) {
|
||||||
|
sdl2_gl_render_surface(scon);
|
||||||
|
}
|
||||||
|
}
|
65
ui/sdl2.c
65
ui/sdl2.c
|
@ -86,6 +86,9 @@ void sdl2_window_create(struct sdl2_console *scon)
|
||||||
surface_height(scon->surface),
|
surface_height(scon->surface),
|
||||||
flags);
|
flags);
|
||||||
scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
|
scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
|
||||||
|
if (scon->opengl) {
|
||||||
|
scon->winctx = SDL_GL_GetCurrentContext();
|
||||||
|
}
|
||||||
sdl_update_caption(scon);
|
sdl_update_caption(scon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +115,17 @@ void sdl2_window_resize(struct sdl2_console *scon)
|
||||||
surface_height(scon->surface));
|
surface_height(scon->surface));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sdl2_redraw(struct sdl2_console *scon)
|
||||||
|
{
|
||||||
|
if (scon->opengl) {
|
||||||
|
#ifdef CONFIG_OPENGL
|
||||||
|
sdl2_gl_redraw(scon);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
sdl2_2d_redraw(scon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void sdl_update_caption(struct sdl2_console *scon)
|
static void sdl_update_caption(struct sdl2_console *scon)
|
||||||
{
|
{
|
||||||
char win_title[1024];
|
char win_title[1024];
|
||||||
|
@ -310,7 +324,7 @@ static void toggle_full_screen(struct sdl2_console *scon)
|
||||||
}
|
}
|
||||||
SDL_SetWindowFullscreen(scon->real_window, 0);
|
SDL_SetWindowFullscreen(scon->real_window, 0);
|
||||||
}
|
}
|
||||||
sdl2_2d_redraw(scon);
|
sdl2_redraw(scon);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_keydown(SDL_Event *ev)
|
static void handle_keydown(SDL_Event *ev)
|
||||||
|
@ -358,8 +372,10 @@ static void handle_keydown(SDL_Event *ev)
|
||||||
case SDL_SCANCODE_U:
|
case SDL_SCANCODE_U:
|
||||||
sdl2_window_destroy(scon);
|
sdl2_window_destroy(scon);
|
||||||
sdl2_window_create(scon);
|
sdl2_window_create(scon);
|
||||||
/* re-create texture */
|
if (!scon->opengl) {
|
||||||
sdl2_2d_switch(&scon->dcl, scon->surface);
|
/* re-create scon->texture */
|
||||||
|
sdl2_2d_switch(&scon->dcl, scon->surface);
|
||||||
|
}
|
||||||
gui_keysym = 1;
|
gui_keysym = 1;
|
||||||
break;
|
break;
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -378,7 +394,7 @@ static void handle_keydown(SDL_Event *ev)
|
||||||
fprintf(stderr, "%s: scale to %dx%d\n",
|
fprintf(stderr, "%s: scale to %dx%d\n",
|
||||||
__func__, width, height);
|
__func__, width, height);
|
||||||
sdl_scale(scon, width, height);
|
sdl_scale(scon, width, height);
|
||||||
sdl2_2d_redraw(scon);
|
sdl2_redraw(scon);
|
||||||
gui_keysym = 1;
|
gui_keysym = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -514,10 +530,10 @@ static void handle_windowevent(SDL_Event *ev)
|
||||||
info.height = ev->window.data2;
|
info.height = ev->window.data2;
|
||||||
dpy_set_ui_info(scon->dcl.con, &info);
|
dpy_set_ui_info(scon->dcl.con, &info);
|
||||||
}
|
}
|
||||||
sdl2_2d_redraw(scon);
|
sdl2_redraw(scon);
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_EXPOSED:
|
case SDL_WINDOWEVENT_EXPOSED:
|
||||||
sdl2_2d_redraw(scon);
|
sdl2_redraw(scon);
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||||
case SDL_WINDOWEVENT_ENTER:
|
case SDL_WINDOWEVENT_ENTER:
|
||||||
|
@ -671,6 +687,35 @@ static const DisplayChangeListenerOps dcl_2d_ops = {
|
||||||
.dpy_cursor_define = sdl_mouse_define,
|
.dpy_cursor_define = sdl_mouse_define,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_OPENGL
|
||||||
|
static const DisplayChangeListenerOps dcl_gl_ops = {
|
||||||
|
.dpy_name = "sdl2-gl",
|
||||||
|
.dpy_gfx_update = sdl2_gl_update,
|
||||||
|
.dpy_gfx_switch = sdl2_gl_switch,
|
||||||
|
.dpy_gfx_check_format = console_gl_check_format,
|
||||||
|
.dpy_refresh = sdl2_gl_refresh,
|
||||||
|
.dpy_mouse_set = sdl_mouse_warp,
|
||||||
|
.dpy_cursor_define = sdl_mouse_define,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void sdl_display_early_init(int opengl)
|
||||||
|
{
|
||||||
|
switch (opengl) {
|
||||||
|
case -1: /* default */
|
||||||
|
case 0: /* off */
|
||||||
|
break;
|
||||||
|
case 1: /* on */
|
||||||
|
#ifdef CONFIG_OPENGL
|
||||||
|
display_opengl = 1;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_assert_not_reached();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
|
void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
|
@ -716,10 +761,16 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
|
||||||
if (!qemu_console_is_graphic(con)) {
|
if (!qemu_console_is_graphic(con)) {
|
||||||
sdl2_console[i].hidden = true;
|
sdl2_console[i].hidden = true;
|
||||||
}
|
}
|
||||||
|
sdl2_console[i].idx = i;
|
||||||
|
#ifdef CONFIG_OPENGL
|
||||||
|
sdl2_console[i].opengl = display_opengl;
|
||||||
|
sdl2_console[i].dcl.ops = display_opengl ? &dcl_gl_ops : &dcl_2d_ops;
|
||||||
|
#else
|
||||||
|
sdl2_console[i].opengl = 0;
|
||||||
sdl2_console[i].dcl.ops = &dcl_2d_ops;
|
sdl2_console[i].dcl.ops = &dcl_2d_ops;
|
||||||
|
#endif
|
||||||
sdl2_console[i].dcl.con = con;
|
sdl2_console[i].dcl.con = con;
|
||||||
register_displaychangelistener(&sdl2_console[i].dcl);
|
register_displaychangelistener(&sdl2_console[i].dcl);
|
||||||
sdl2_console[i].idx = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load a 32x32x4 image. White pixels are transparent. */
|
/* Load a 32x32x4 image. White pixels are transparent. */
|
||||||
|
|
23
vl.c
23
vl.c
|
@ -130,6 +130,7 @@ static int data_dir_idx;
|
||||||
const char *bios_name = NULL;
|
const char *bios_name = NULL;
|
||||||
enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
|
enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
|
||||||
DisplayType display_type = DT_DEFAULT;
|
DisplayType display_type = DT_DEFAULT;
|
||||||
|
int request_opengl = -1;
|
||||||
int display_opengl;
|
int display_opengl;
|
||||||
static int display_remote;
|
static int display_remote;
|
||||||
const char* keyboard_layout = NULL;
|
const char* keyboard_layout = NULL;
|
||||||
|
@ -1990,6 +1991,15 @@ static DisplayType select_display(const char *p)
|
||||||
} else {
|
} else {
|
||||||
goto invalid_sdl_args;
|
goto invalid_sdl_args;
|
||||||
}
|
}
|
||||||
|
} else if (strstart(opts, ",gl=", &nextopt)) {
|
||||||
|
opts = nextopt;
|
||||||
|
if (strstart(opts, "on", &nextopt)) {
|
||||||
|
request_opengl = 1;
|
||||||
|
} else if (strstart(opts, "off", &nextopt)) {
|
||||||
|
request_opengl = 0;
|
||||||
|
} else {
|
||||||
|
goto invalid_sdl_args;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
invalid_sdl_args:
|
invalid_sdl_args:
|
||||||
fprintf(stderr, "Invalid SDL option string: %s\n", p);
|
fprintf(stderr, "Invalid SDL option string: %s\n", p);
|
||||||
|
@ -4005,6 +4015,19 @@ int main(int argc, char **argv, char **envp)
|
||||||
early_gtk_display_init();
|
early_gtk_display_init();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(CONFIG_SDL)
|
||||||
|
if (display_type == DT_SDL) {
|
||||||
|
sdl_display_early_init(request_opengl);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (request_opengl == 1 && display_opengl == 0) {
|
||||||
|
#if defined(CONFIG_OPENGL)
|
||||||
|
fprintf(stderr, "OpenGL is not supported by the display.\n");
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "QEMU was built without opengl support.\n");
|
||||||
|
#endif
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
socket_init();
|
socket_init();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue