mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 19:49:43 +00:00
sdl2/opengl: add opengl context and scanout support
ui/curses: Fix color attribute of monitor for curses -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAABAgAGBQJWj66aAAoJEEy22O7T6HE4rSgP/iBVMpm5wZrOvxGZ7XV0wx7D /JiQ7J7oS6aWBpz0LFHeiseWMDX1/V2kEDe/3mwHqeNULfeZqlf9PIXwM8N6FX2Q tIO0DB7iTDg/nT10Q2gHsYQtaNcsuw1c8+mwOw20ogcBVTXqHw4tACPhZWthVNDQ sLeIwH0OU/n/Gf6E+tMAfourDH0SIM8wtw9UguGcR1PxbyDnvRv8gEiPty2qOnGq nTdIdmf54eCgll6qQRhZ3+53k1ShrTv7hn5GKRmQZSOFXe5JgBeUfoT6xZf/lIAf D9LdmAU9vuNK7m4TceEsIAzUvNG49jAsVQGUO6Ebk3rT3FSoNLfx7ION/N0xjDvt CAKGN1Ub/vuqPBl57/qb9AxTYcRPW5KgHSrALWrM7TTLY8xLa2cRjEd6kVYfPsvs rhhrfHeac3qiwg9sjKaHeXvcmOCSRX/pTzkER9RK7bIeMHyDu7x+WJvIkW5qdfSe 1G62aXZIeSRlSfKDvdbn1zfu/gZ7uy8xtvG/3CrCcT5Qf3PqEr2KOPsq/S1C1BKN GSCnt+DcLNmdiwyESMluibdVx9Vh7urbOdCh9pebFjgswCPNRSXzyUji0Xkzwe8b BkBoSCqdu5Z0QmiapG83Y2e9e/uWqfyr/DAB/CiFf2wLgoiiP1usof3Euzez96oa i7q5dNgGuBlv25Z8ngT8 =4sRO -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/kraxel/tags/pull-ui-20160108-1' into staging sdl2/opengl: add opengl context and scanout support ui/curses: Fix color attribute of monitor for curses # gpg: Signature made Fri 08 Jan 2016 12:42:02 GMT using RSA key ID D3E87138 # gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>" # gpg: aka "Gerd Hoffmann <gerd@kraxel.org>" # gpg: aka "Gerd Hoffmann (private) <kraxel@gmail.com>" * remotes/kraxel/tags/pull-ui-20160108-1: sdl2/opengl: add opengl context and scanout support ui/curses: Fix color attribute of monitor for curses Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
6bb9ead762
@ -233,8 +233,10 @@ static void jazz_led_text_update(void *opaque, console_ch_t *chardata)
|
||||
|
||||
/* TODO: draw the segments */
|
||||
snprintf(buf, 2, "%02hhx\n", s->segments);
|
||||
console_write_ch(chardata++, 0x00200100 | buf[0]);
|
||||
console_write_ch(chardata++, 0x00200100 | buf[1]);
|
||||
console_write_ch(chardata++, ATTR2CHTYPE(buf[0], QEMU_COLOR_BLUE,
|
||||
QEMU_COLOR_BLACK, 1));
|
||||
console_write_ch(chardata++, ATTR2CHTYPE(buf[1], QEMU_COLOR_BLUE,
|
||||
QEMU_COLOR_BLACK, 1));
|
||||
|
||||
dpy_text_update(s->con, 0, 0, 2, 1);
|
||||
}
|
||||
|
@ -1979,7 +1979,8 @@ static void vga_update_text(void *opaque, console_ch_t *chardata)
|
||||
width = (s->last_width - size) / 2;
|
||||
dst = chardata + s->last_width + width;
|
||||
for (i = 0; i < size; i ++)
|
||||
console_write_ch(dst ++, 0x00200100 | msg_buffer[i]);
|
||||
console_write_ch(dst ++, ATTR2CHTYPE(msg_buffer[i], QEMU_COLOR_BLUE,
|
||||
QEMU_COLOR_BLACK, 1));
|
||||
|
||||
dpy_text_update(s->con, 0, 0, s->last_width, height);
|
||||
}
|
||||
|
@ -30,6 +30,21 @@
|
||||
#define GUI_REFRESH_INTERVAL_DEFAULT 30
|
||||
#define GUI_REFRESH_INTERVAL_IDLE 3000
|
||||
|
||||
/* Color number is match to standard vga palette */
|
||||
enum qemu_color_names {
|
||||
QEMU_COLOR_BLACK = 0,
|
||||
QEMU_COLOR_BLUE = 1,
|
||||
QEMU_COLOR_GREEN = 2,
|
||||
QEMU_COLOR_CYAN = 3,
|
||||
QEMU_COLOR_RED = 4,
|
||||
QEMU_COLOR_MAGENTA = 5,
|
||||
QEMU_COLOR_YELLOW = 6,
|
||||
QEMU_COLOR_WHITE = 7
|
||||
};
|
||||
/* Convert to curses char attributes */
|
||||
#define ATTR2CHTYPE(c, fg, bg, bold) \
|
||||
((bold) << 21 | (bg) << 11 | (fg) << 8 | (c))
|
||||
|
||||
typedef void QEMUPutKBDEvent(void *opaque, int keycode);
|
||||
typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
|
||||
typedef void QEMUPutMouseEvent(void *opaque, int dx, int dy, int dz, int buttons_state);
|
||||
|
@ -15,12 +15,18 @@ struct sdl2_console {
|
||||
SDL_Renderer *real_renderer;
|
||||
int idx;
|
||||
int last_vm_running; /* per console for caption reasons */
|
||||
int x, y;
|
||||
int x, y, w, h;
|
||||
int hidden;
|
||||
int opengl;
|
||||
int updates;
|
||||
SDL_GLContext winctx;
|
||||
#ifdef CONFIG_OPENGL
|
||||
ConsoleGLState *gls;
|
||||
GLuint tex_id;
|
||||
GLuint fbo_id;
|
||||
bool y0_top;
|
||||
bool scanout_mode;
|
||||
#endif
|
||||
};
|
||||
|
||||
void sdl2_window_create(struct sdl2_console *scon);
|
||||
@ -48,4 +54,18 @@ void sdl2_gl_switch(DisplayChangeListener *dcl,
|
||||
void sdl2_gl_refresh(DisplayChangeListener *dcl);
|
||||
void sdl2_gl_redraw(struct sdl2_console *scon);
|
||||
|
||||
QEMUGLContext sdl2_gl_create_context(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params);
|
||||
void sdl2_gl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx);
|
||||
int sdl2_gl_make_context_current(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx);
|
||||
QEMUGLContext sdl2_gl_get_current_context(DisplayChangeListener *dcl);
|
||||
|
||||
void sdl2_gl_scanout(DisplayChangeListener *dcl,
|
||||
uint32_t backing_id, bool backing_y_0_top,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h);
|
||||
void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
||||
|
||||
#endif /* SDL2_H */
|
||||
|
101
ui/console.c
101
ui/console.c
@ -376,42 +376,29 @@ static void vga_bitblt(QemuConsole *con,
|
||||
|
||||
#include "vgafont.h"
|
||||
|
||||
#ifndef CONFIG_CURSES
|
||||
enum color_names {
|
||||
COLOR_BLACK = 0,
|
||||
COLOR_RED = 1,
|
||||
COLOR_GREEN = 2,
|
||||
COLOR_YELLOW = 3,
|
||||
COLOR_BLUE = 4,
|
||||
COLOR_MAGENTA = 5,
|
||||
COLOR_CYAN = 6,
|
||||
COLOR_WHITE = 7
|
||||
};
|
||||
#endif
|
||||
|
||||
#define QEMU_RGB(r, g, b) \
|
||||
{ .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
|
||||
|
||||
static const pixman_color_t color_table_rgb[2][8] = {
|
||||
{ /* dark */
|
||||
QEMU_RGB(0x00, 0x00, 0x00), /* black */
|
||||
QEMU_RGB(0xaa, 0x00, 0x00), /* red */
|
||||
QEMU_RGB(0x00, 0xaa, 0x00), /* green */
|
||||
QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
|
||||
QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
|
||||
QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
|
||||
QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
|
||||
QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
|
||||
[QEMU_COLOR_BLACK] = QEMU_RGB(0x00, 0x00, 0x00), /* black */
|
||||
[QEMU_COLOR_BLUE] = QEMU_RGB(0x00, 0x00, 0xaa), /* blue */
|
||||
[QEMU_COLOR_GREEN] = QEMU_RGB(0x00, 0xaa, 0x00), /* green */
|
||||
[QEMU_COLOR_CYAN] = QEMU_RGB(0x00, 0xaa, 0xaa), /* cyan */
|
||||
[QEMU_COLOR_RED] = QEMU_RGB(0xaa, 0x00, 0x00), /* red */
|
||||
[QEMU_COLOR_MAGENTA] = QEMU_RGB(0xaa, 0x00, 0xaa), /* magenta */
|
||||
[QEMU_COLOR_YELLOW] = QEMU_RGB(0xaa, 0xaa, 0x00), /* yellow */
|
||||
[QEMU_COLOR_WHITE] = QEMU_RGB(0xaa, 0xaa, 0xaa), /* white */
|
||||
},
|
||||
{ /* bright */
|
||||
QEMU_RGB(0x00, 0x00, 0x00), /* black */
|
||||
QEMU_RGB(0xff, 0x00, 0x00), /* red */
|
||||
QEMU_RGB(0x00, 0xff, 0x00), /* green */
|
||||
QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
|
||||
QEMU_RGB(0x00, 0x00, 0xff), /* blue */
|
||||
QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
|
||||
QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
|
||||
QEMU_RGB(0xff, 0xff, 0xff), /* white */
|
||||
[QEMU_COLOR_BLACK] = QEMU_RGB(0x00, 0x00, 0x00), /* black */
|
||||
[QEMU_COLOR_BLUE] = QEMU_RGB(0x00, 0x00, 0xff), /* blue */
|
||||
[QEMU_COLOR_GREEN] = QEMU_RGB(0x00, 0xff, 0x00), /* green */
|
||||
[QEMU_COLOR_CYAN] = QEMU_RGB(0x00, 0xff, 0xff), /* cyan */
|
||||
[QEMU_COLOR_RED] = QEMU_RGB(0xff, 0x00, 0x00), /* red */
|
||||
[QEMU_COLOR_MAGENTA] = QEMU_RGB(0xff, 0x00, 0xff), /* magenta */
|
||||
[QEMU_COLOR_YELLOW] = QEMU_RGB(0xff, 0xff, 0x00), /* yellow */
|
||||
[QEMU_COLOR_WHITE] = QEMU_RGB(0xff, 0xff, 0xff), /* white */
|
||||
}
|
||||
};
|
||||
|
||||
@ -560,7 +547,7 @@ static void console_refresh(QemuConsole *s)
|
||||
}
|
||||
|
||||
vga_fill_rect(s, 0, 0, surface_width(surface), surface_height(surface),
|
||||
color_table_rgb[0][COLOR_BLACK]);
|
||||
color_table_rgb[0][QEMU_COLOR_BLACK]);
|
||||
y1 = s->y_displayed;
|
||||
for (y = 0; y < s->height; y++) {
|
||||
c = s->cells + y1 * s->width;
|
||||
@ -698,53 +685,53 @@ static void console_handle_escape(QemuConsole *s)
|
||||
break;
|
||||
/* set foreground color */
|
||||
case 30:
|
||||
s->t_attrib.fgcol=COLOR_BLACK;
|
||||
s->t_attrib.fgcol = QEMU_COLOR_BLACK;
|
||||
break;
|
||||
case 31:
|
||||
s->t_attrib.fgcol=COLOR_RED;
|
||||
s->t_attrib.fgcol = QEMU_COLOR_RED;
|
||||
break;
|
||||
case 32:
|
||||
s->t_attrib.fgcol=COLOR_GREEN;
|
||||
s->t_attrib.fgcol = QEMU_COLOR_GREEN;
|
||||
break;
|
||||
case 33:
|
||||
s->t_attrib.fgcol=COLOR_YELLOW;
|
||||
s->t_attrib.fgcol = QEMU_COLOR_YELLOW;
|
||||
break;
|
||||
case 34:
|
||||
s->t_attrib.fgcol=COLOR_BLUE;
|
||||
s->t_attrib.fgcol = QEMU_COLOR_BLUE;
|
||||
break;
|
||||
case 35:
|
||||
s->t_attrib.fgcol=COLOR_MAGENTA;
|
||||
s->t_attrib.fgcol = QEMU_COLOR_MAGENTA;
|
||||
break;
|
||||
case 36:
|
||||
s->t_attrib.fgcol=COLOR_CYAN;
|
||||
s->t_attrib.fgcol = QEMU_COLOR_CYAN;
|
||||
break;
|
||||
case 37:
|
||||
s->t_attrib.fgcol=COLOR_WHITE;
|
||||
s->t_attrib.fgcol = QEMU_COLOR_WHITE;
|
||||
break;
|
||||
/* set background color */
|
||||
case 40:
|
||||
s->t_attrib.bgcol=COLOR_BLACK;
|
||||
s->t_attrib.bgcol = QEMU_COLOR_BLACK;
|
||||
break;
|
||||
case 41:
|
||||
s->t_attrib.bgcol=COLOR_RED;
|
||||
s->t_attrib.bgcol = QEMU_COLOR_RED;
|
||||
break;
|
||||
case 42:
|
||||
s->t_attrib.bgcol=COLOR_GREEN;
|
||||
s->t_attrib.bgcol = QEMU_COLOR_GREEN;
|
||||
break;
|
||||
case 43:
|
||||
s->t_attrib.bgcol=COLOR_YELLOW;
|
||||
s->t_attrib.bgcol = QEMU_COLOR_YELLOW;
|
||||
break;
|
||||
case 44:
|
||||
s->t_attrib.bgcol=COLOR_BLUE;
|
||||
s->t_attrib.bgcol = QEMU_COLOR_BLUE;
|
||||
break;
|
||||
case 45:
|
||||
s->t_attrib.bgcol=COLOR_MAGENTA;
|
||||
s->t_attrib.bgcol = QEMU_COLOR_MAGENTA;
|
||||
break;
|
||||
case 46:
|
||||
s->t_attrib.bgcol=COLOR_CYAN;
|
||||
s->t_attrib.bgcol = QEMU_COLOR_CYAN;
|
||||
break;
|
||||
case 47:
|
||||
s->t_attrib.bgcol=COLOR_WHITE;
|
||||
s->t_attrib.bgcol = QEMU_COLOR_WHITE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1165,11 +1152,13 @@ static void text_console_update(void *opaque, console_ch_t *chardata)
|
||||
src = (s->y_base + s->text_y[0]) * s->width;
|
||||
chardata += s->text_y[0] * s->width;
|
||||
for (i = s->text_y[0]; i <= s->text_y[1]; i ++)
|
||||
for (j = 0; j < s->width; j ++, src ++)
|
||||
console_write_ch(chardata ++, s->cells[src].ch |
|
||||
(s->cells[src].t_attrib.fgcol << 12) |
|
||||
(s->cells[src].t_attrib.bgcol << 8) |
|
||||
(s->cells[src].t_attrib.bold << 21));
|
||||
for (j = 0; j < s->width; j++, src++) {
|
||||
console_write_ch(chardata ++,
|
||||
ATTR2CHTYPE(s->cells[src].ch,
|
||||
s->cells[src].t_attrib.fgcol,
|
||||
s->cells[src].t_attrib.bgcol,
|
||||
s->cells[src].t_attrib.bold));
|
||||
}
|
||||
dpy_text_update(s, s->text_x[0], s->text_y[0],
|
||||
s->text_x[1] - s->text_x[0], i - s->text_y[0]);
|
||||
s->text_x[0] = s->width;
|
||||
@ -1306,8 +1295,8 @@ static DisplaySurface *qemu_create_message_surface(int w, int h,
|
||||
const char *msg)
|
||||
{
|
||||
DisplaySurface *surface = qemu_create_displaysurface(w, h);
|
||||
pixman_color_t bg = color_table_rgb[0][COLOR_BLACK];
|
||||
pixman_color_t fg = color_table_rgb[0][COLOR_WHITE];
|
||||
pixman_color_t bg = color_table_rgb[0][QEMU_COLOR_BLACK];
|
||||
pixman_color_t fg = color_table_rgb[0][QEMU_COLOR_WHITE];
|
||||
pixman_image_t *glyph;
|
||||
int len, x, y, i;
|
||||
|
||||
@ -1941,8 +1930,8 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds)
|
||||
s->t_attrib_default.blink = 0;
|
||||
s->t_attrib_default.invers = 0;
|
||||
s->t_attrib_default.unvisible = 0;
|
||||
s->t_attrib_default.fgcol = COLOR_WHITE;
|
||||
s->t_attrib_default.bgcol = COLOR_BLACK;
|
||||
s->t_attrib_default.fgcol = QEMU_COLOR_WHITE;
|
||||
s->t_attrib_default.bgcol = QEMU_COLOR_BLACK;
|
||||
/* set current text attributes to default */
|
||||
s->t_attrib = s->t_attrib_default;
|
||||
text_console_resize(s);
|
||||
@ -1951,7 +1940,7 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds)
|
||||
char msg[128];
|
||||
int len;
|
||||
|
||||
s->t_attrib.bgcol = COLOR_BLUE;
|
||||
s->t_attrib.bgcol = QEMU_COLOR_BLUE;
|
||||
len = snprintf(msg, sizeof(msg), "%s console\r\n", chr->label);
|
||||
console_puts(chr, (uint8_t*)msg, len);
|
||||
s->t_attrib = s->t_attrib_default;
|
||||
|
13
ui/curses.c
13
ui/curses.c
@ -333,8 +333,14 @@ static void curses_atexit(void)
|
||||
static void curses_setup(void)
|
||||
{
|
||||
int i, colour_default[8] = {
|
||||
COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
|
||||
COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE,
|
||||
[QEMU_COLOR_BLACK] = COLOR_BLACK,
|
||||
[QEMU_COLOR_BLUE] = COLOR_BLUE,
|
||||
[QEMU_COLOR_GREEN] = COLOR_GREEN,
|
||||
[QEMU_COLOR_CYAN] = COLOR_CYAN,
|
||||
[QEMU_COLOR_RED] = COLOR_RED,
|
||||
[QEMU_COLOR_MAGENTA] = COLOR_MAGENTA,
|
||||
[QEMU_COLOR_YELLOW] = COLOR_YELLOW,
|
||||
[QEMU_COLOR_WHITE] = COLOR_WHITE,
|
||||
};
|
||||
|
||||
/* input as raw as possible, let everything be interpreted
|
||||
@ -343,10 +349,11 @@ static void curses_setup(void)
|
||||
nodelay(stdscr, TRUE); nonl(); keypad(stdscr, TRUE);
|
||||
start_color(); raw(); scrollok(stdscr, FALSE);
|
||||
|
||||
/* Make color pair to match color format (3bits bg:3bits fg) */
|
||||
for (i = 0; i < 64; i++) {
|
||||
init_pair(i, colour_default[i & 7], colour_default[i >> 3]);
|
||||
}
|
||||
/* Set default color for more than 64. (monitor uses 0x74xx for example) */
|
||||
/* Set default color for more than 64 for safety. */
|
||||
for (i = 64; i < COLOR_PAIRS; i++) {
|
||||
init_pair(i, COLOR_WHITE, COLOR_BLACK);
|
||||
}
|
||||
|
135
ui/sdl2-gl.c
135
ui/sdl2-gl.c
@ -31,11 +31,37 @@
|
||||
#include "ui/sdl2.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
|
||||
#include <epoxy/gl.h>
|
||||
|
||||
static void sdl2_set_scanout_mode(struct sdl2_console *scon, bool scanout)
|
||||
{
|
||||
if (scon->scanout_mode == scanout) {
|
||||
return;
|
||||
}
|
||||
|
||||
scon->scanout_mode = scanout;
|
||||
if (!scon->scanout_mode) {
|
||||
if (scon->fbo_id) {
|
||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
|
||||
GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_TEXTURE_2D, 0, 0);
|
||||
glDeleteFramebuffers(1, &scon->fbo_id);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
|
||||
scon->fbo_id = 0;
|
||||
}
|
||||
if (scon->surface) {
|
||||
surface_gl_destroy_texture(scon->gls, scon->surface);
|
||||
surface_gl_create_texture(scon->gls, scon->surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void sdl2_gl_render_surface(struct sdl2_console *scon)
|
||||
{
|
||||
int ww, wh;
|
||||
|
||||
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
|
||||
sdl2_set_scanout_mode(scon, false);
|
||||
|
||||
SDL_GetWindowSize(scon->real_window, &ww, &wh);
|
||||
surface_gl_setup_viewport(scon->gls, scon->surface, ww, wh);
|
||||
@ -110,3 +136,112 @@ void sdl2_gl_redraw(struct sdl2_console *scon)
|
||||
sdl2_gl_render_surface(scon);
|
||||
}
|
||||
}
|
||||
|
||||
QEMUGLContext sdl2_gl_create_context(DisplayChangeListener *dcl,
|
||||
QEMUGLParams *params)
|
||||
{
|
||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||
SDL_GLContext ctx;
|
||||
|
||||
assert(scon->opengl);
|
||||
|
||||
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
|
||||
SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, params->major_ver);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, params->minor_ver);
|
||||
|
||||
ctx = SDL_GL_CreateContext(scon->real_window);
|
||||
return (QEMUGLContext)ctx;
|
||||
}
|
||||
|
||||
void sdl2_gl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx)
|
||||
{
|
||||
SDL_GLContext sdlctx = (SDL_GLContext)ctx;
|
||||
|
||||
SDL_GL_DeleteContext(sdlctx);
|
||||
}
|
||||
|
||||
int sdl2_gl_make_context_current(DisplayChangeListener *dcl,
|
||||
QEMUGLContext ctx)
|
||||
{
|
||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||
SDL_GLContext sdlctx = (SDL_GLContext)ctx;
|
||||
|
||||
assert(scon->opengl);
|
||||
|
||||
return SDL_GL_MakeCurrent(scon->real_window, sdlctx);
|
||||
}
|
||||
|
||||
QEMUGLContext sdl2_gl_get_current_context(DisplayChangeListener *dcl)
|
||||
{
|
||||
SDL_GLContext sdlctx;
|
||||
|
||||
sdlctx = SDL_GL_GetCurrentContext();
|
||||
return (QEMUGLContext)sdlctx;
|
||||
}
|
||||
|
||||
void sdl2_gl_scanout(DisplayChangeListener *dcl,
|
||||
uint32_t backing_id, bool backing_y_0_top,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h)
|
||||
{
|
||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||
|
||||
assert(scon->opengl);
|
||||
scon->x = x;
|
||||
scon->y = y;
|
||||
scon->w = w;
|
||||
scon->h = h;
|
||||
scon->tex_id = backing_id;
|
||||
scon->y0_top = backing_y_0_top;
|
||||
|
||||
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
|
||||
|
||||
if (scon->tex_id == 0 || scon->w == 0 || scon->h == 0) {
|
||||
sdl2_set_scanout_mode(scon, false);
|
||||
return;
|
||||
}
|
||||
|
||||
sdl2_set_scanout_mode(scon, true);
|
||||
if (!scon->fbo_id) {
|
||||
glGenFramebuffers(1, &scon->fbo_id);
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, scon->fbo_id);
|
||||
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
||||
GL_TEXTURE_2D, scon->tex_id, 0);
|
||||
}
|
||||
|
||||
void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h)
|
||||
{
|
||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||
int ww, wh, y1, y2;
|
||||
|
||||
assert(scon->opengl);
|
||||
if (!scon->scanout_mode) {
|
||||
return;
|
||||
}
|
||||
if (!scon->fbo_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, scon->fbo_id);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
|
||||
SDL_GetWindowSize(scon->real_window, &ww, &wh);
|
||||
glViewport(0, 0, ww, wh);
|
||||
y1 = scon->y0_top ? 0 : scon->h;
|
||||
y2 = scon->y0_top ? scon->h : 0;
|
||||
glBlitFramebuffer(0, y1, scon->w, y2,
|
||||
0, 0, ww, wh,
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, scon->fbo_id);
|
||||
|
||||
SDL_GL_SwapWindow(scon->real_window);
|
||||
}
|
||||
|
@ -700,6 +700,13 @@ static const DisplayChangeListenerOps dcl_gl_ops = {
|
||||
.dpy_refresh = sdl2_gl_refresh,
|
||||
.dpy_mouse_set = sdl_mouse_warp,
|
||||
.dpy_cursor_define = sdl_mouse_define,
|
||||
|
||||
.dpy_gl_ctx_create = sdl2_gl_create_context,
|
||||
.dpy_gl_ctx_destroy = sdl2_gl_destroy_context,
|
||||
.dpy_gl_ctx_make_current = sdl2_gl_make_context_current,
|
||||
.dpy_gl_ctx_get_current = sdl2_gl_get_current_context,
|
||||
.dpy_gl_scanout = sdl2_gl_scanout,
|
||||
.dpy_gl_update = sdl2_gl_scanout_flush,
|
||||
};
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user