mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/kraxel/tags/pull-sdl-20141219-1' into staging
sdl2: fixes, cleanups and opengl preparation. # gpg: Signature made Fri 19 Dec 2014 09:06:07 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-sdl-20141219-1: sdl2: Work around SDL2 SDL_ShowWindow() bug sdl2: Use correct sdl2_console for window events sdl2: move sdl2_2d_refresh to sdl2-2d.c sdl2: factor out sdl2_poll_events sdl2: add+use sdl2_2d_redraw function. sdl2: move sdl_switch to sdl2-2d.c sdl2: overhaul window size handling sdl2: move sdl_update to new sdl2-2d.c sdl2: turn on keyboard grabs sdl2: move keyboard input code to new sdl2-input.c sdl2: rename sdl2_state to sdl2_console, move to header file sdl: move version logic from source code to makefile Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#ifndef SDL2_H
|
||||
#define SDL2_H
|
||||
|
||||
struct sdl2_console {
|
||||
DisplayChangeListener dcl;
|
||||
DisplaySurface *surface;
|
||||
SDL_Texture *texture;
|
||||
SDL_Window *real_window;
|
||||
SDL_Renderer *real_renderer;
|
||||
int idx;
|
||||
int last_vm_running; /* per console for caption reasons */
|
||||
int x, y;
|
||||
int hidden;
|
||||
};
|
||||
|
||||
void sdl2_window_create(struct sdl2_console *scon);
|
||||
void sdl2_window_destroy(struct sdl2_console *scon);
|
||||
void sdl2_window_resize(struct sdl2_console *scon);
|
||||
void sdl2_poll_events(struct sdl2_console *scon);
|
||||
|
||||
void sdl2_reset_keys(struct sdl2_console *scon);
|
||||
void sdl2_process_key(struct sdl2_console *scon,
|
||||
SDL_KeyboardEvent *ev);
|
||||
|
||||
void sdl2_2d_update(DisplayChangeListener *dcl,
|
||||
int x, int y, int w, int h);
|
||||
void sdl2_2d_switch(DisplayChangeListener *dcl,
|
||||
DisplaySurface *new_surface);
|
||||
void sdl2_2d_refresh(DisplayChangeListener *dcl);
|
||||
void sdl2_2d_redraw(struct sdl2_console *scon);
|
||||
|
||||
#endif /* SDL2_H */
|
||||
+6
-1
@@ -16,7 +16,12 @@ common-obj-$(CONFIG_CURSES) += curses.o
|
||||
common-obj-$(CONFIG_VNC) += $(vnc-obj-y)
|
||||
common-obj-$(CONFIG_GTK) += gtk.o x_keymap.o
|
||||
|
||||
sdl.mo-objs := sdl.o sdl_zoom.o sdl2.o
|
||||
ifeq ($(CONFIG_SDLABI),1.2)
|
||||
sdl.mo-objs := sdl.o sdl_zoom.o
|
||||
endif
|
||||
ifeq ($(CONFIG_SDLABI),2.0)
|
||||
sdl.mo-objs := sdl2.o sdl2-input.o sdl2-2d.o
|
||||
endif
|
||||
sdl.mo-cflags := $(SDL_CFLAGS)
|
||||
|
||||
gtk.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS)
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#if SDL_MAJOR_VERSION == 1
|
||||
#include <SDL_syswm.h>
|
||||
|
||||
#include "qemu-common.h"
|
||||
@@ -958,4 +956,3 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
|
||||
|
||||
atexit(sdl_cleanup);
|
||||
}
|
||||
#endif
|
||||
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* QEMU SDL display driver
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
/* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
|
||||
|
||||
/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_syswm.h>
|
||||
|
||||
#include "qemu-common.h"
|
||||
#include "ui/console.h"
|
||||
#include "ui/input.h"
|
||||
#include "ui/sdl2.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
|
||||
void sdl2_2d_update(DisplayChangeListener *dcl,
|
||||
int x, int y, int w, int h)
|
||||
{
|
||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||
DisplaySurface *surf = qemu_console_surface(dcl->con);
|
||||
SDL_Rect rect;
|
||||
|
||||
if (!surf) {
|
||||
return;
|
||||
}
|
||||
if (!scon->texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
rect.x = x;
|
||||
rect.y = y;
|
||||
rect.w = w;
|
||||
rect.h = h;
|
||||
|
||||
SDL_UpdateTexture(scon->texture, NULL, surface_data(surf),
|
||||
surface_stride(surf));
|
||||
SDL_RenderCopy(scon->real_renderer, scon->texture, &rect, &rect);
|
||||
SDL_RenderPresent(scon->real_renderer);
|
||||
}
|
||||
|
||||
void sdl2_2d_switch(DisplayChangeListener *dcl,
|
||||
DisplaySurface *new_surface)
|
||||
{
|
||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||
DisplaySurface *old_surface = scon->surface;
|
||||
int format = 0;
|
||||
|
||||
scon->surface = new_surface;
|
||||
|
||||
if (scon->texture) {
|
||||
SDL_DestroyTexture(scon->texture);
|
||||
scon->texture = NULL;
|
||||
}
|
||||
|
||||
if (!new_surface) {
|
||||
sdl2_window_destroy(scon);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!scon->real_window) {
|
||||
sdl2_window_create(scon);
|
||||
} else if (old_surface &&
|
||||
((surface_width(old_surface) != surface_width(new_surface)) ||
|
||||
(surface_height(old_surface) != surface_height(new_surface)))) {
|
||||
sdl2_window_resize(scon);
|
||||
}
|
||||
|
||||
SDL_RenderSetLogicalSize(scon->real_renderer,
|
||||
surface_width(new_surface),
|
||||
surface_height(new_surface));
|
||||
|
||||
if (surface_bits_per_pixel(scon->surface) == 16) {
|
||||
format = SDL_PIXELFORMAT_RGB565;
|
||||
} else if (surface_bits_per_pixel(scon->surface) == 32) {
|
||||
format = SDL_PIXELFORMAT_ARGB8888;
|
||||
}
|
||||
scon->texture = SDL_CreateTexture(scon->real_renderer, format,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
surface_width(new_surface),
|
||||
surface_height(new_surface));
|
||||
sdl2_2d_redraw(scon);
|
||||
}
|
||||
|
||||
void sdl2_2d_refresh(DisplayChangeListener *dcl)
|
||||
{
|
||||
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
|
||||
|
||||
graphic_hw_update(dcl->con);
|
||||
sdl2_poll_events(scon);
|
||||
}
|
||||
|
||||
void sdl2_2d_redraw(struct sdl2_console *scon)
|
||||
{
|
||||
if (!scon->surface) {
|
||||
return;
|
||||
}
|
||||
sdl2_2d_update(&scon->dcl, 0, 0,
|
||||
surface_width(scon->surface),
|
||||
surface_height(scon->surface));
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* QEMU SDL display driver
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
/* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
|
||||
|
||||
/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_syswm.h>
|
||||
|
||||
#include "qemu-common.h"
|
||||
#include "ui/console.h"
|
||||
#include "ui/input.h"
|
||||
#include "ui/sdl2.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
|
||||
#include "sdl2-keymap.h"
|
||||
|
||||
static uint8_t modifiers_state[SDL_NUM_SCANCODES];
|
||||
|
||||
void sdl2_reset_keys(struct sdl2_console *scon)
|
||||
{
|
||||
QemuConsole *con = scon ? scon->dcl.con : NULL;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < SDL_NUM_SCANCODES; i++) {
|
||||
if (modifiers_state[i]) {
|
||||
int qcode = sdl2_scancode_to_qcode[i];
|
||||
qemu_input_event_send_key_qcode(con, qcode, false);
|
||||
modifiers_state[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sdl2_process_key(struct sdl2_console *scon,
|
||||
SDL_KeyboardEvent *ev)
|
||||
{
|
||||
int qcode = sdl2_scancode_to_qcode[ev->keysym.scancode];
|
||||
QemuConsole *con = scon ? scon->dcl.con : NULL;
|
||||
|
||||
if (!qemu_console_is_graphic(con)) {
|
||||
if (ev->type == SDL_KEYDOWN) {
|
||||
switch (ev->keysym.scancode) {
|
||||
case SDL_SCANCODE_RETURN:
|
||||
kbd_put_keysym_console(con, '\n');
|
||||
break;
|
||||
case SDL_SCANCODE_BACKSPACE:
|
||||
kbd_put_keysym_console(con, QEMU_KEY_BACKSPACE);
|
||||
break;
|
||||
default:
|
||||
kbd_put_qcode_console(con, qcode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ev->keysym.scancode) {
|
||||
#if 0
|
||||
case SDL_SCANCODE_NUMLOCKCLEAR:
|
||||
case SDL_SCANCODE_CAPSLOCK:
|
||||
/* SDL does not send the key up event, so we generate it */
|
||||
qemu_input_event_send_key_qcode(con, qcode, true);
|
||||
qemu_input_event_send_key_qcode(con, qcode, false);
|
||||
return;
|
||||
#endif
|
||||
case SDL_SCANCODE_LCTRL:
|
||||
case SDL_SCANCODE_LSHIFT:
|
||||
case SDL_SCANCODE_LALT:
|
||||
case SDL_SCANCODE_LGUI:
|
||||
case SDL_SCANCODE_RCTRL:
|
||||
case SDL_SCANCODE_RSHIFT:
|
||||
case SDL_SCANCODE_RALT:
|
||||
case SDL_SCANCODE_RGUI:
|
||||
if (ev->type == SDL_KEYUP) {
|
||||
modifiers_state[ev->keysym.scancode] = 0;
|
||||
} else {
|
||||
modifiers_state[ev->keysym.scancode] = 1;
|
||||
}
|
||||
/* fall though */
|
||||
default:
|
||||
qemu_input_event_send_key_qcode(con, qcode,
|
||||
ev->type == SDL_KEYDOWN);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user