Import QEMU upstream snapshot d2e570c
Upstream: https://gitlab.com/qemu-project/qemu.git Upstream-Commit: d2e570cc0f97b936902a5b1b86b73c0f5998b475
This commit is contained in:
commit
cf256aa081
11315 files changed
+3598369
No files matched your search
@@ -0,0 +1,294 @@
|
||||
#ifndef QEMU_CLIPBOARD_H
|
||||
#define QEMU_CLIPBOARD_H
|
||||
|
||||
#include "qemu/notify.h"
|
||||
#include "migration/vmstate.h"
|
||||
|
||||
/**
|
||||
* DOC: Introduction
|
||||
*
|
||||
* The header ``ui/clipboard.h`` declares the qemu clipboard interface.
|
||||
*
|
||||
* All qemu elements which want use the clipboard can register as
|
||||
* clipboard peer. Subsequently they can set the clipboard content
|
||||
* and get notifications for clipboard updates.
|
||||
*
|
||||
* Typical users are user interfaces (gtk), remote access protocols
|
||||
* (vnc) and devices talking to the guest (vdagent).
|
||||
*
|
||||
* Even though the design allows different data types only plain text
|
||||
* is supported for now.
|
||||
*/
|
||||
|
||||
typedef enum QemuClipboardType QemuClipboardType;
|
||||
typedef enum QemuClipboardNotifyType QemuClipboardNotifyType;
|
||||
typedef enum QemuClipboardSelection QemuClipboardSelection;
|
||||
typedef struct QemuClipboardPeer QemuClipboardPeer;
|
||||
typedef struct QemuClipboardNotify QemuClipboardNotify;
|
||||
typedef struct QemuClipboardInfo QemuClipboardInfo;
|
||||
typedef struct QemuClipboardContent QemuClipboardContent;
|
||||
|
||||
extern const VMStateDescription vmstate_cbinfo;
|
||||
|
||||
/**
|
||||
* enum QemuClipboardType
|
||||
*
|
||||
* @QEMU_CLIPBOARD_TYPE_TEXT: text/plain; charset=utf-8
|
||||
* @QEMU_CLIPBOARD_TYPE__COUNT: type count.
|
||||
*/
|
||||
enum QemuClipboardType {
|
||||
QEMU_CLIPBOARD_TYPE_TEXT,
|
||||
QEMU_CLIPBOARD_TYPE__COUNT,
|
||||
};
|
||||
|
||||
/* same as VD_AGENT_CLIPBOARD_SELECTION_* */
|
||||
/**
|
||||
* enum QemuClipboardSelection
|
||||
*
|
||||
* @QEMU_CLIPBOARD_SELECTION_CLIPBOARD: clipboard (explitcit cut+paste).
|
||||
* @QEMU_CLIPBOARD_SELECTION_PRIMARY: primary selection (select + middle mouse button).
|
||||
* @QEMU_CLIPBOARD_SELECTION_SECONDARY: secondary selection (dunno).
|
||||
* @QEMU_CLIPBOARD_SELECTION__COUNT: selection count.
|
||||
*/
|
||||
enum QemuClipboardSelection {
|
||||
QEMU_CLIPBOARD_SELECTION_CLIPBOARD,
|
||||
QEMU_CLIPBOARD_SELECTION_PRIMARY,
|
||||
QEMU_CLIPBOARD_SELECTION_SECONDARY,
|
||||
QEMU_CLIPBOARD_SELECTION__COUNT,
|
||||
};
|
||||
|
||||
/**
|
||||
* struct QemuClipboardPeer
|
||||
*
|
||||
* @name: peer name.
|
||||
* @notifier: notifier for clipboard updates.
|
||||
* @request: callback for clipboard data requests.
|
||||
*
|
||||
* Clipboard peer description.
|
||||
*/
|
||||
struct QemuClipboardPeer {
|
||||
const char *name;
|
||||
Notifier notifier;
|
||||
void (*request)(QemuClipboardInfo *info,
|
||||
QemuClipboardType type);
|
||||
};
|
||||
|
||||
/**
|
||||
* enum QemuClipboardNotifyType
|
||||
*
|
||||
* @QEMU_CLIPBOARD_UPDATE_INFO: clipboard info update
|
||||
* @QEMU_CLIPBOARD_RESET_SERIAL: reset clipboard serial
|
||||
*
|
||||
* Clipboard notify type.
|
||||
*/
|
||||
enum QemuClipboardNotifyType {
|
||||
QEMU_CLIPBOARD_UPDATE_INFO,
|
||||
QEMU_CLIPBOARD_RESET_SERIAL,
|
||||
};
|
||||
|
||||
/**
|
||||
* struct QemuClipboardNotify
|
||||
*
|
||||
* @type: the type of event.
|
||||
* @info: a QemuClipboardInfo event.
|
||||
*
|
||||
* Clipboard notify data.
|
||||
*/
|
||||
struct QemuClipboardNotify {
|
||||
QemuClipboardNotifyType type;
|
||||
union {
|
||||
QemuClipboardInfo *info;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* struct QemuClipboardContent
|
||||
*
|
||||
* @available: whether the data is available
|
||||
* @requested: whether the data was requested
|
||||
* @size: the size of the @data
|
||||
* @data: the clipboard data
|
||||
*
|
||||
* Clipboard content.
|
||||
*/
|
||||
struct QemuClipboardContent {
|
||||
bool available;
|
||||
bool requested;
|
||||
uint32_t size;
|
||||
void *data;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct QemuClipboardInfo
|
||||
*
|
||||
* @refcount: reference counter.
|
||||
* @owner: clipboard owner.
|
||||
* @selection: clipboard selection.
|
||||
* @types: clipboard data array (one entry per type).
|
||||
* @has_serial: whether @serial is available.
|
||||
* @serial: the grab serial counter.
|
||||
*
|
||||
* Clipboard content data and metadata.
|
||||
*/
|
||||
struct QemuClipboardInfo {
|
||||
uint32_t refcount;
|
||||
QemuClipboardPeer *owner;
|
||||
int selection; /* QemuClipboardSelection */
|
||||
bool has_serial;
|
||||
uint32_t serial;
|
||||
QemuClipboardContent types[QEMU_CLIPBOARD_TYPE__COUNT];
|
||||
};
|
||||
|
||||
/**
|
||||
* qemu_clipboard_peer_register
|
||||
*
|
||||
* @peer: peer information.
|
||||
*
|
||||
* Register clipboard peer. Registering is needed for both active
|
||||
* (set+grab clipboard) and passive (watch clipboard for updates)
|
||||
* interaction with the qemu clipboard.
|
||||
*/
|
||||
void qemu_clipboard_peer_register(QemuClipboardPeer *peer);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_peer_unregister
|
||||
*
|
||||
* @peer: peer information.
|
||||
*
|
||||
* Unregister clipboard peer.
|
||||
*/
|
||||
void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_peer_owns
|
||||
*
|
||||
* @peer: peer information.
|
||||
* @selection: clipboard selection.
|
||||
*
|
||||
* Return TRUE if the peer owns the clipboard.
|
||||
*/
|
||||
bool qemu_clipboard_peer_owns(QemuClipboardPeer *peer,
|
||||
QemuClipboardSelection selection);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_peer_release
|
||||
*
|
||||
* @peer: peer information.
|
||||
* @selection: clipboard selection.
|
||||
*
|
||||
* If the peer owns the clipboard, release it.
|
||||
*/
|
||||
void qemu_clipboard_peer_release(QemuClipboardPeer *peer,
|
||||
QemuClipboardSelection selection);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_info
|
||||
*
|
||||
* @selection: clipboard selection.
|
||||
*
|
||||
* Return the current clipboard data & owner information.
|
||||
*/
|
||||
QemuClipboardInfo *qemu_clipboard_info(QemuClipboardSelection selection);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_check_serial
|
||||
*
|
||||
* @info: clipboard info.
|
||||
* @client: whether to check from the client context and priority.
|
||||
*
|
||||
* Return TRUE if the @info has a higher serial than the current clipboard.
|
||||
*/
|
||||
bool qemu_clipboard_check_serial(QemuClipboardInfo *info, bool client);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_info_new
|
||||
*
|
||||
* @owner: clipboard owner.
|
||||
* @selection: clipboard selection.
|
||||
*
|
||||
* Allocate a new QemuClipboardInfo and initialize it with the given
|
||||
* @owner and @selection.
|
||||
*
|
||||
* QemuClipboardInfo is a reference-counted struct. The new struct is
|
||||
* returned with a reference already taken (i.e. reference count is
|
||||
* one).
|
||||
*/
|
||||
QemuClipboardInfo *qemu_clipboard_info_new(QemuClipboardPeer *owner,
|
||||
QemuClipboardSelection selection);
|
||||
/**
|
||||
* qemu_clipboard_info_ref
|
||||
*
|
||||
* @info: clipboard info.
|
||||
*
|
||||
* Increase @info reference count.
|
||||
*/
|
||||
QemuClipboardInfo *qemu_clipboard_info_ref(QemuClipboardInfo *info);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_info_unref
|
||||
*
|
||||
* @info: clipboard info.
|
||||
*
|
||||
* Decrease @info reference count. When the count goes down to zero
|
||||
* free the @info struct itself and all clipboard data.
|
||||
*/
|
||||
void qemu_clipboard_info_unref(QemuClipboardInfo *info);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_update
|
||||
*
|
||||
* @info: clipboard info.
|
||||
*
|
||||
* Update the qemu clipboard. Notify all registered peers (including
|
||||
* the clipboard owner) that the qemu clipboard has been updated.
|
||||
*
|
||||
* This is used for both new completely clipboard content and for
|
||||
* clipboard data updates in response to qemu_clipboard_request()
|
||||
* calls.
|
||||
*/
|
||||
void qemu_clipboard_update(QemuClipboardInfo *info);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_reset_serial
|
||||
*
|
||||
* Reset the clipboard serial.
|
||||
*/
|
||||
void qemu_clipboard_reset_serial(void);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_request
|
||||
*
|
||||
* @info: clipboard info.
|
||||
* @type: clipboard data type.
|
||||
*
|
||||
* Request clipboard content. Typically the clipboard owner only
|
||||
* advertises the available data types and provides the actual data
|
||||
* only on request.
|
||||
*/
|
||||
void qemu_clipboard_request(QemuClipboardInfo *info,
|
||||
QemuClipboardType type);
|
||||
|
||||
/**
|
||||
* qemu_clipboard_set_data
|
||||
*
|
||||
* @peer: clipboard peer.
|
||||
* @info: clipboard info.
|
||||
* @type: clipboard data type.
|
||||
* @size: data size.
|
||||
* @data: data blob.
|
||||
* @update: notify peers about the update.
|
||||
*
|
||||
* Set clipboard content for the given @type. This function will make
|
||||
* a copy of the content data and store that.
|
||||
*/
|
||||
void qemu_clipboard_set_data(QemuClipboardPeer *peer,
|
||||
QemuClipboardInfo *info,
|
||||
QemuClipboardType type,
|
||||
uint32_t size,
|
||||
const void *data,
|
||||
bool update);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuClipboardInfo, qemu_clipboard_info_unref)
|
||||
|
||||
#endif /* QEMU_CLIPBOARD_H */
|
||||
@@ -0,0 +1,457 @@
|
||||
#ifndef CONSOLE_H
|
||||
#define CONSOLE_H
|
||||
|
||||
#include "ui/qemu-pixman.h"
|
||||
#include "qom/object.h"
|
||||
#include "qemu/notify.h"
|
||||
#include "qapi/qapi-types-ui.h"
|
||||
#include "ui/input.h"
|
||||
#include "ui/surface.h"
|
||||
#include "ui/dmabuf.h"
|
||||
|
||||
#define TYPE_QEMU_CONSOLE "qemu-console"
|
||||
OBJECT_DECLARE_TYPE(QemuConsole, QemuConsoleClass, QEMU_CONSOLE)
|
||||
|
||||
#define TYPE_QEMU_GRAPHIC_CONSOLE "qemu-graphic-console"
|
||||
OBJECT_DECLARE_SIMPLE_TYPE(QemuGraphicConsole, QEMU_GRAPHIC_CONSOLE)
|
||||
|
||||
#define TYPE_QEMU_TEXT_CONSOLE "qemu-text-console"
|
||||
OBJECT_DECLARE_SIMPLE_TYPE(QemuTextConsole, QEMU_TEXT_CONSOLE)
|
||||
|
||||
#define TYPE_QEMU_FIXED_TEXT_CONSOLE "qemu-fixed-text-console"
|
||||
OBJECT_DECLARE_SIMPLE_TYPE(QemuFixedTextConsole, QEMU_FIXED_TEXT_CONSOLE)
|
||||
|
||||
#define QEMU_IS_GRAPHIC_CONSOLE(c) \
|
||||
object_dynamic_cast(OBJECT(c), TYPE_QEMU_GRAPHIC_CONSOLE)
|
||||
|
||||
#define QEMU_IS_TEXT_CONSOLE(c) \
|
||||
object_dynamic_cast(OBJECT(c), TYPE_QEMU_TEXT_CONSOLE)
|
||||
|
||||
#define QEMU_IS_FIXED_TEXT_CONSOLE(c) \
|
||||
object_dynamic_cast(OBJECT(c), TYPE_QEMU_FIXED_TEXT_CONSOLE)
|
||||
|
||||
/* identical to the ps/2 keyboard bits */
|
||||
#define QEMU_SCROLL_LOCK_LED (1 << 0)
|
||||
#define QEMU_NUM_LOCK_LED (1 << 1)
|
||||
#define QEMU_CAPS_LOCK_LED (1 << 2)
|
||||
|
||||
/* in ms */
|
||||
#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))
|
||||
|
||||
bool qemu_mouse_set(int index, Error **errp);
|
||||
|
||||
/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
|
||||
constants) */
|
||||
#define QEMU_KEY_ESC1(c) ((c) | 0xe100)
|
||||
#define QEMU_KEY_TAB 0x0009
|
||||
#define QEMU_KEY_BACKSPACE 0x007f
|
||||
#define QEMU_KEY_UP QEMU_KEY_ESC1('A')
|
||||
#define QEMU_KEY_DOWN QEMU_KEY_ESC1('B')
|
||||
#define QEMU_KEY_RIGHT QEMU_KEY_ESC1('C')
|
||||
#define QEMU_KEY_LEFT QEMU_KEY_ESC1('D')
|
||||
#define QEMU_KEY_HOME QEMU_KEY_ESC1(1)
|
||||
#define QEMU_KEY_END QEMU_KEY_ESC1(4)
|
||||
#define QEMU_KEY_PAGEUP QEMU_KEY_ESC1(5)
|
||||
#define QEMU_KEY_PAGEDOWN QEMU_KEY_ESC1(6)
|
||||
#define QEMU_KEY_DELETE QEMU_KEY_ESC1(3)
|
||||
|
||||
#define QEMU_KEY_CTRL_UP 0xe400
|
||||
#define QEMU_KEY_CTRL_DOWN 0xe401
|
||||
#define QEMU_KEY_CTRL_LEFT 0xe402
|
||||
#define QEMU_KEY_CTRL_RIGHT 0xe403
|
||||
#define QEMU_KEY_CTRL_HOME 0xe404
|
||||
#define QEMU_KEY_CTRL_END 0xe405
|
||||
#define QEMU_KEY_CTRL_PAGEUP 0xe406
|
||||
#define QEMU_KEY_CTRL_PAGEDOWN 0xe407
|
||||
|
||||
void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym);
|
||||
bool qemu_text_console_put_linux(QemuTextConsole *s, unsigned int lnx,
|
||||
bool ctrl);
|
||||
void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len);
|
||||
|
||||
/* consoles */
|
||||
|
||||
struct QemuConsoleClass {
|
||||
ObjectClass parent_class;
|
||||
|
||||
char * (*get_label)(const QemuConsole *con);
|
||||
};
|
||||
|
||||
typedef struct ScanoutTexture {
|
||||
uint32_t backing_id;
|
||||
bool backing_y_0_top;
|
||||
uint32_t backing_width;
|
||||
uint32_t backing_height;
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
void *d3d_tex2d;
|
||||
} ScanoutTexture;
|
||||
|
||||
typedef struct QemuUIInfo {
|
||||
/* physical dimension */
|
||||
uint16_t width_mm;
|
||||
uint16_t height_mm;
|
||||
/* geometry */
|
||||
int xoff;
|
||||
int yoff;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t refresh_rate;
|
||||
} QemuUIInfo;
|
||||
|
||||
/* cursor data format is 32bit RGBA */
|
||||
typedef struct QEMUCursor {
|
||||
uint16_t width, height;
|
||||
int hot_x, hot_y;
|
||||
int refcount;
|
||||
uint32_t data[];
|
||||
} QEMUCursor;
|
||||
|
||||
QEMUCursor *cursor_alloc(uint16_t width, uint16_t height);
|
||||
QEMUCursor *cursor_ref(QEMUCursor *c);
|
||||
void cursor_unref(QEMUCursor *c);
|
||||
QEMUCursor *cursor_builtin_hidden(void);
|
||||
QEMUCursor *cursor_builtin_left_ptr(void);
|
||||
void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
|
||||
int cursor_get_mono_bpl(QEMUCursor *c);
|
||||
void cursor_set_mono(QEMUCursor *c,
|
||||
uint32_t foreground, uint32_t background, uint8_t *image,
|
||||
int transparent, uint8_t *mask);
|
||||
void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
|
||||
|
||||
typedef void *QEMUGLContext;
|
||||
typedef struct QEMUGLParams QEMUGLParams;
|
||||
|
||||
struct QEMUGLParams {
|
||||
int major_ver;
|
||||
int minor_ver;
|
||||
};
|
||||
|
||||
enum display_scanout {
|
||||
SCANOUT_NONE,
|
||||
SCANOUT_SURFACE,
|
||||
SCANOUT_TEXTURE,
|
||||
SCANOUT_DMABUF,
|
||||
};
|
||||
|
||||
typedef struct DisplayScanout {
|
||||
enum display_scanout kind;
|
||||
union {
|
||||
/* DisplaySurface *surface; is kept in QemuConsole */
|
||||
ScanoutTexture texture;
|
||||
QemuDmaBuf *dmabuf;
|
||||
};
|
||||
} DisplayScanout;
|
||||
|
||||
typedef struct DisplayState DisplayState;
|
||||
typedef struct DisplayGLCtx DisplayGLCtx;
|
||||
|
||||
typedef struct DisplayChangeListenerOps {
|
||||
const char *dpy_name;
|
||||
|
||||
/* optional */
|
||||
void (*dpy_refresh)(DisplayChangeListener *dcl);
|
||||
|
||||
/* optional */
|
||||
void (*dpy_gfx_update)(DisplayChangeListener *dcl,
|
||||
int x, int y, int w, int h);
|
||||
/* optional */
|
||||
void (*dpy_gfx_switch)(DisplayChangeListener *dcl,
|
||||
struct DisplaySurface *new_surface);
|
||||
/* optional */
|
||||
bool (*dpy_gfx_check_format)(DisplayChangeListener *dcl,
|
||||
pixman_format_code_t format);
|
||||
|
||||
/* optional */
|
||||
void (*dpy_text_cursor)(DisplayChangeListener *dcl,
|
||||
int x, int y);
|
||||
/* optional */
|
||||
void (*dpy_text_resize)(DisplayChangeListener *dcl,
|
||||
int w, int h);
|
||||
/* optional */
|
||||
void (*dpy_text_update)(DisplayChangeListener *dcl,
|
||||
int x, int y, int w, int h);
|
||||
|
||||
/* optional */
|
||||
void (*dpy_mouse_set)(DisplayChangeListener *dcl,
|
||||
int x, int y, bool on);
|
||||
/* optional */
|
||||
void (*dpy_cursor_define)(DisplayChangeListener *dcl,
|
||||
QEMUCursor *cursor);
|
||||
|
||||
/* required if GL */
|
||||
void (*dpy_gl_scanout_disable)(DisplayChangeListener *dcl);
|
||||
/* required if GL */
|
||||
void (*dpy_gl_scanout_texture)(DisplayChangeListener *dcl,
|
||||
uint32_t backing_id,
|
||||
bool backing_y_0_top,
|
||||
uint32_t backing_width,
|
||||
uint32_t backing_height,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h,
|
||||
void *d3d_tex2d);
|
||||
/* optional (default to true if has dpy_gl_scanout_dmabuf) */
|
||||
bool (*dpy_has_dmabuf)(DisplayChangeListener *dcl);
|
||||
/* optional */
|
||||
void (*dpy_gl_scanout_dmabuf)(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf);
|
||||
/* optional */
|
||||
void (*dpy_gl_cursor_dmabuf)(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf, bool have_hot,
|
||||
uint32_t hot_x, uint32_t hot_y);
|
||||
/* optional */
|
||||
void (*dpy_gl_cursor_position)(DisplayChangeListener *dcl,
|
||||
uint32_t pos_x, uint32_t pos_y);
|
||||
/* optional */
|
||||
void (*dpy_gl_release_dmabuf)(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf);
|
||||
/* required if GL */
|
||||
void (*dpy_gl_update)(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
||||
|
||||
} DisplayChangeListenerOps;
|
||||
|
||||
struct DisplayChangeListener {
|
||||
uint64_t update_interval;
|
||||
const DisplayChangeListenerOps *ops;
|
||||
DisplayState *ds;
|
||||
QemuConsole *con;
|
||||
|
||||
QLIST_ENTRY(DisplayChangeListener) next;
|
||||
};
|
||||
|
||||
typedef struct DisplayGLCtxOps {
|
||||
bool (*dpy_gl_ctx_is_compatible_dcl)(DisplayGLCtx *dgc,
|
||||
DisplayChangeListener *dcl);
|
||||
QEMUGLContext (*dpy_gl_ctx_create)(DisplayGLCtx *dgc,
|
||||
QEMUGLParams *params);
|
||||
void (*dpy_gl_ctx_destroy)(DisplayGLCtx *dgc,
|
||||
QEMUGLContext ctx);
|
||||
int (*dpy_gl_ctx_make_current)(DisplayGLCtx *dgc,
|
||||
QEMUGLContext ctx);
|
||||
void (*dpy_gl_ctx_create_texture)(DisplayGLCtx *dgc,
|
||||
DisplaySurface *surface);
|
||||
void (*dpy_gl_ctx_destroy_texture)(DisplayGLCtx *dgc,
|
||||
DisplaySurface *surface);
|
||||
void (*dpy_gl_ctx_update_texture)(DisplayGLCtx *dgc,
|
||||
DisplaySurface *surface,
|
||||
int x, int y, int w, int h);
|
||||
} DisplayGLCtxOps;
|
||||
|
||||
struct DisplayGLCtx {
|
||||
const DisplayGLCtxOps *ops;
|
||||
#ifdef CONFIG_OPENGL
|
||||
QemuGLShader *gls; /* optional shared shader */
|
||||
#endif
|
||||
};
|
||||
|
||||
DisplayState *init_displaystate(void);
|
||||
|
||||
void qemu_console_register_listener(QemuConsole *con,
|
||||
DisplayChangeListener *dcl,
|
||||
const DisplayChangeListenerOps *ops);
|
||||
void qemu_console_listener_set_refresh(DisplayChangeListener *dcl,
|
||||
uint64_t interval);
|
||||
void qemu_console_unregister_listener(DisplayChangeListener *dcl);
|
||||
|
||||
bool qemu_console_ui_info_supported(const QemuConsole *con);
|
||||
const QemuUIInfo *qemu_console_get_ui_info(const QemuConsole *con);
|
||||
int qemu_console_set_ui_info(QemuConsole *con, QemuUIInfo *info, bool delay);
|
||||
|
||||
void qemu_console_update(QemuConsole *con, int x, int y, int w, int h);
|
||||
void qemu_console_update_full(QemuConsole *con);
|
||||
void qemu_console_set_surface(QemuConsole *con,
|
||||
DisplaySurface *surface);
|
||||
void qemu_console_text_set_cursor(QemuConsole *con, int x, int y);
|
||||
void qemu_console_text_update(QemuConsole *con, int x, int y, int w, int h);
|
||||
void qemu_console_text_resize(QemuConsole *con, int w, int h);
|
||||
void qemu_console_set_mouse(QemuConsole *con, int x, int y, bool on);
|
||||
void qemu_console_set_cursor(QemuConsole *con, QEMUCursor *cursor);
|
||||
bool qemu_console_check_format(QemuConsole *con,
|
||||
pixman_format_code_t format);
|
||||
|
||||
void qemu_console_gl_scanout_disable(QemuConsole *con);
|
||||
void qemu_console_gl_scanout_texture(QemuConsole *con,
|
||||
uint32_t backing_id, bool backing_y_0_top,
|
||||
uint32_t backing_width, uint32_t backing_height,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h,
|
||||
void *d3d_tex2d);
|
||||
void qemu_console_gl_scanout_dmabuf(QemuConsole *con,
|
||||
QemuDmaBuf *dmabuf);
|
||||
void qemu_console_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf,
|
||||
bool have_hot, uint32_t hot_x, uint32_t hot_y);
|
||||
void qemu_console_gl_cursor_position(QemuConsole *con,
|
||||
uint32_t pos_x, uint32_t pos_y);
|
||||
void qemu_console_gl_release_dmabuf(QemuConsole *con,
|
||||
QemuDmaBuf *dmabuf);
|
||||
void qemu_console_gl_update(QemuConsole *con,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
||||
|
||||
QEMUGLContext qemu_console_gl_ctx_create(QemuConsole *con,
|
||||
QEMUGLParams *params);
|
||||
void qemu_console_gl_ctx_destroy(QemuConsole *con, QEMUGLContext ctx);
|
||||
int qemu_console_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx);
|
||||
|
||||
bool qemu_console_has_gl(QemuConsole *con);
|
||||
|
||||
enum {
|
||||
GRAPHIC_FLAGS_NONE = 0,
|
||||
/* require a console/display with GL callbacks */
|
||||
GRAPHIC_FLAGS_GL = 1 << 0,
|
||||
/* require a console/display with DMABUF import */
|
||||
GRAPHIC_FLAGS_DMABUF = 1 << 1,
|
||||
};
|
||||
|
||||
typedef struct GraphicHwOps {
|
||||
int (*get_flags)(void *opaque); /* optional, default 0 */
|
||||
void (*invalidate)(void *opaque);
|
||||
/*
|
||||
* Returns true if the update is handled synchronously, false if deferred
|
||||
* and graphic_hw_update_done() will be called when ready (to resume waiting
|
||||
* tasks/coroutines).
|
||||
* Optional.
|
||||
*/
|
||||
bool (*gfx_update)(void *opaque);
|
||||
void (*text_update)(void *opaque, uint32_t *text);
|
||||
void (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
|
||||
void (*gl_block)(void *opaque, bool block);
|
||||
} GraphicHwOps;
|
||||
|
||||
QemuConsole *qemu_graphic_console_create(DeviceState *dev, uint32_t head,
|
||||
const GraphicHwOps *ops,
|
||||
void *opaque);
|
||||
void qemu_graphic_console_set_hwops(QemuConsole *con,
|
||||
const GraphicHwOps *hw_ops,
|
||||
void *opaque);
|
||||
void qemu_graphic_console_close(QemuConsole *con);
|
||||
|
||||
void qemu_console_hw_update(QemuConsole *con);
|
||||
void qemu_console_hw_update_done(QemuConsole *con);
|
||||
void qemu_console_hw_invalidate(QemuConsole *con);
|
||||
void qemu_console_hw_text_update(QemuConsole *con, uint32_t *chardata);
|
||||
void qemu_console_hw_gl_block(QemuConsole *con, bool block);
|
||||
|
||||
void qemu_console_early_init(void);
|
||||
|
||||
void qemu_console_set_display_gl_ctx(QemuConsole *con, DisplayGLCtx *ctx);
|
||||
|
||||
QemuConsole *qemu_console_lookup_default(void);
|
||||
QemuConsole *qemu_console_lookup_by_index(unsigned int index);
|
||||
QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
|
||||
QemuConsole *qemu_console_lookup_by_device_name(const char *device_id,
|
||||
uint32_t head, Error **errp);
|
||||
QEMUCursor *qemu_console_get_cursor(QemuConsole *con);
|
||||
bool qemu_console_is_graphic(QemuConsole *con);
|
||||
bool qemu_console_is_fixedsize(QemuConsole *con);
|
||||
bool qemu_console_is_gl_blocked(QemuConsole *con);
|
||||
char *qemu_console_get_label(QemuConsole *con);
|
||||
int qemu_console_get_index(QemuConsole *con);
|
||||
uint32_t qemu_console_get_head(QemuConsole *con);
|
||||
int qemu_console_get_width(QemuConsole *con, int fallback);
|
||||
int qemu_console_get_height(QemuConsole *con, int fallback);
|
||||
/* Return the low-level window id for the console */
|
||||
int qemu_console_get_window_id(QemuConsole *con);
|
||||
/* Set the low-level window id for the console */
|
||||
void qemu_console_set_window_id(QemuConsole *con, int window_id);
|
||||
|
||||
void qemu_console_resize(QemuConsole *con, int width, int height);
|
||||
DisplaySurface *qemu_console_surface(QemuConsole *con);
|
||||
void coroutine_fn qemu_console_co_wait_update(QemuConsole *con);
|
||||
|
||||
/* console-gl.c */
|
||||
#ifdef CONFIG_OPENGL
|
||||
bool console_gl_check_format(DisplayChangeListener *dcl,
|
||||
pixman_format_code_t format);
|
||||
void surface_gl_create_texture(QemuGLShader *gls,
|
||||
DisplaySurface *surface);
|
||||
bool surface_gl_create_texture_from_fd(DisplaySurface *surface,
|
||||
int fd, uint32_t *texture,
|
||||
uint32_t *mem_obj);
|
||||
void surface_gl_update_texture(QemuGLShader *gls,
|
||||
DisplaySurface *surface,
|
||||
int x, int y, int w, int h);
|
||||
void surface_gl_render_texture(QemuGLShader *gls,
|
||||
DisplaySurface *surface);
|
||||
void surface_gl_destroy_texture(QemuGLShader *gls,
|
||||
DisplaySurface *surface);
|
||||
void surface_gl_setup_viewport(QemuGLShader *gls,
|
||||
DisplaySurface *surface,
|
||||
int ww, int wh);
|
||||
#endif
|
||||
|
||||
typedef struct QemuDisplay QemuDisplay;
|
||||
|
||||
struct QemuDisplay {
|
||||
DisplayType type;
|
||||
void (*early_init)(DisplayOptions *opts);
|
||||
void (*init)(DisplayState *ds, DisplayOptions *opts);
|
||||
void (*cleanup)(void);
|
||||
const char *vc;
|
||||
};
|
||||
|
||||
void qemu_display_register(QemuDisplay *ui);
|
||||
bool qemu_display_find_default(DisplayOptions *opts);
|
||||
void qemu_display_early_init(DisplayOptions *opts);
|
||||
void qemu_display_init(DisplayState *ds, DisplayOptions *opts);
|
||||
const char *qemu_display_get_vc(DisplayOptions *opts);
|
||||
void qemu_display_cleanup(void);
|
||||
void qemu_display_help(void);
|
||||
|
||||
/*
|
||||
* Console notifications:
|
||||
* Handlers must be idempotent, it may notify multiple times.
|
||||
*/
|
||||
typedef enum {
|
||||
QEMU_CONSOLE_ADDED,
|
||||
QEMU_CONSOLE_REMOVED,
|
||||
} QemuConsoleEventType;
|
||||
|
||||
typedef struct QemuConsoleEvent {
|
||||
QemuConsoleEventType type;
|
||||
QemuConsole *con;
|
||||
} QemuConsoleEvent;
|
||||
|
||||
void qemu_console_add_notifier(Notifier *notifier);
|
||||
void qemu_console_remove_notifier(Notifier *notifier);
|
||||
void qemu_console_notify(QemuConsoleEventType type, QemuConsole *con);
|
||||
|
||||
/* vnc.c */
|
||||
void vnc_display_add_client(const char *id, int csock, bool skipauth);
|
||||
int vnc_display_password(const char *id, const char *password, Error **errp);
|
||||
int vnc_display_pw_expire(const char *id, time_t expires);
|
||||
void vnc_parse(const char *str);
|
||||
int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp);
|
||||
bool vnc_display_reload_certs(const char *id, Error **errp);
|
||||
bool vnc_display_update(DisplayUpdateOptionsVNC *arg, Error **errp);
|
||||
void vnc_cleanup(void);
|
||||
|
||||
#ifdef CONFIG_LINUX
|
||||
/* udmabuf.c */
|
||||
int udmabuf_fd(void);
|
||||
#endif
|
||||
|
||||
/* util.c */
|
||||
bool qemu_console_fill_device_address(QemuConsole *con,
|
||||
char *device_address,
|
||||
size_t size,
|
||||
Error **errp);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef DBUS_DISPLAY_H
|
||||
#define DBUS_DISPLAY_H
|
||||
|
||||
#include "qapi/error.h"
|
||||
#include "ui/dbus-module.h"
|
||||
|
||||
static inline bool qemu_using_dbus_display(Error **errp)
|
||||
{
|
||||
if (!using_dbus_display) {
|
||||
error_set(errp, ERROR_CLASS_DEVICE_NOT_ACTIVE,
|
||||
"D-Bus display is not in use");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* DBUS_DISPLAY_H */
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef DBUS_MODULE_H
|
||||
#define DBUS_MODULE_H
|
||||
|
||||
struct QemuDBusDisplayOps {
|
||||
bool (*add_client)(int csock, Error **errp);
|
||||
};
|
||||
|
||||
extern int using_dbus_display;
|
||||
extern struct QemuDBusDisplayOps qemu_dbus_display;
|
||||
|
||||
#endif /* DBUS_MODULE_H */
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*
|
||||
* QemuDmaBuf struct and helpers used for accessing its data
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#ifndef DMABUF_H
|
||||
#define DMABUF_H
|
||||
|
||||
#define DMABUF_MAX_PLANES 4
|
||||
|
||||
typedef struct QemuDmaBuf QemuDmaBuf;
|
||||
|
||||
QemuDmaBuf *qemu_dmabuf_new(uint32_t width, uint32_t height,
|
||||
const uint32_t *offset, const uint32_t *stride,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t backing_width, uint32_t backing_height,
|
||||
uint32_t fourcc, uint64_t modifier,
|
||||
const int32_t *dmabuf_fd, uint32_t num_planes,
|
||||
bool allow_fences, bool y0_top);
|
||||
void qemu_dmabuf_free(QemuDmaBuf *dmabuf);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuDmaBuf, qemu_dmabuf_free);
|
||||
|
||||
const int *qemu_dmabuf_get_fds(QemuDmaBuf *dmabuf, int *nfds);
|
||||
void qemu_dmabuf_dup_fds(QemuDmaBuf *dmabuf, int *fds, int nfds);
|
||||
void qemu_dmabuf_close(QemuDmaBuf *dmabuf);
|
||||
uint32_t qemu_dmabuf_get_width(QemuDmaBuf *dmabuf);
|
||||
uint32_t qemu_dmabuf_get_height(QemuDmaBuf *dmabuf);
|
||||
const uint32_t *qemu_dmabuf_get_offsets(QemuDmaBuf *dmabuf, int *noffsets);
|
||||
const uint32_t *qemu_dmabuf_get_strides(QemuDmaBuf *dmabuf, int *nstrides);
|
||||
uint32_t qemu_dmabuf_get_num_planes(QemuDmaBuf *dmabuf);
|
||||
uint32_t qemu_dmabuf_get_fourcc(QemuDmaBuf *dmabuf);
|
||||
uint64_t qemu_dmabuf_get_modifier(QemuDmaBuf *dmabuf);
|
||||
uint32_t qemu_dmabuf_get_texture(QemuDmaBuf *dmabuf);
|
||||
uint32_t qemu_dmabuf_get_x(QemuDmaBuf *dmabuf);
|
||||
uint32_t qemu_dmabuf_get_y(QemuDmaBuf *dmabuf);
|
||||
uint32_t qemu_dmabuf_get_backing_width(QemuDmaBuf *dmabuf);
|
||||
uint32_t qemu_dmabuf_get_backing_height(QemuDmaBuf *dmabuf);
|
||||
bool qemu_dmabuf_get_y0_top(QemuDmaBuf *dmabuf);
|
||||
void *qemu_dmabuf_get_sync(QemuDmaBuf *dmabuf);
|
||||
int32_t qemu_dmabuf_get_fence_fd(QemuDmaBuf *dmabuf);
|
||||
bool qemu_dmabuf_get_allow_fences(QemuDmaBuf *dmabuf);
|
||||
bool qemu_dmabuf_get_draw_submitted(QemuDmaBuf *dmabuf);
|
||||
void qemu_dmabuf_set_texture(QemuDmaBuf *dmabuf, uint32_t texture);
|
||||
void qemu_dmabuf_set_fence_fd(QemuDmaBuf *dmabuf, int32_t fence_fd);
|
||||
void qemu_dmabuf_set_sync(QemuDmaBuf *dmabuf, void *sync);
|
||||
void qemu_dmabuf_set_draw_submitted(QemuDmaBuf *dmabuf, bool draw_submitted);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef EGL_CONTEXT_H
|
||||
#define EGL_CONTEXT_H
|
||||
|
||||
#include "ui/console.h"
|
||||
#include "ui/egl-helpers.h"
|
||||
|
||||
QEMUGLContext qemu_egl_create_context(DisplayGLCtx *dgc,
|
||||
QEMUGLParams *params,
|
||||
EGLContext share_context);
|
||||
void qemu_egl_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx);
|
||||
int qemu_egl_make_context_current(DisplayGLCtx *dgc,
|
||||
QEMUGLContext ctx);
|
||||
|
||||
#endif /* EGL_CONTEXT_H */
|
||||
@@ -0,0 +1,88 @@
|
||||
#ifndef EGL_HELPERS_H
|
||||
#define EGL_HELPERS_H
|
||||
|
||||
#include <epoxy/gl.h>
|
||||
#include <epoxy/egl.h>
|
||||
#ifdef CONFIG_GBM
|
||||
#include <gbm.h>
|
||||
#endif
|
||||
#include "ui/console.h"
|
||||
#include "ui/shader.h"
|
||||
|
||||
extern EGLDisplay qemu_egl_display;
|
||||
extern EGLConfig qemu_egl_config;
|
||||
extern DisplayGLMode qemu_egl_mode;
|
||||
extern bool qemu_egl_angle_d3d;
|
||||
|
||||
typedef struct egl_fb {
|
||||
int width;
|
||||
int height;
|
||||
int x;
|
||||
int y;
|
||||
GLuint texture;
|
||||
GLuint framebuffer;
|
||||
bool delete_texture;
|
||||
QemuDmaBuf *dmabuf;
|
||||
} egl_fb;
|
||||
|
||||
#define EGL_FB_INIT { 0, }
|
||||
|
||||
void egl_fb_destroy(egl_fb *fb);
|
||||
void egl_fb_setup_default(egl_fb *fb, int width, int height, int x, int y);
|
||||
void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
|
||||
GLuint texture, bool delete);
|
||||
void egl_fb_setup_new_tex(egl_fb *fb, int width, int height);
|
||||
void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip);
|
||||
void egl_fb_read(DisplaySurface *dst, egl_fb *src);
|
||||
void egl_fb_read_rect(DisplaySurface *dst, egl_fb *src, int x, int y, int w, int h);
|
||||
|
||||
void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip);
|
||||
void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
|
||||
int x, int y, double scale_x, double scale_y);
|
||||
|
||||
extern EGLContext qemu_egl_rn_ctx;
|
||||
|
||||
#ifdef CONFIG_GBM
|
||||
|
||||
extern int qemu_egl_rn_fd;
|
||||
extern struct gbm_device *qemu_egl_rn_gbm_dev;
|
||||
|
||||
int egl_rendernode_init(const char *rendernode, DisplayGLMode mode);
|
||||
bool egl_dmabuf_export_texture(uint32_t tex_id, int *fd, EGLint *offset,
|
||||
EGLint *stride, EGLint *fourcc, int *num_planes,
|
||||
EGLuint64KHR *modifier);
|
||||
|
||||
void egl_dmabuf_import_texture(QemuDmaBuf *dmabuf);
|
||||
void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf);
|
||||
void egl_dmabuf_create_sync(QemuDmaBuf *dmabuf);
|
||||
void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf);
|
||||
|
||||
#endif
|
||||
|
||||
EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win);
|
||||
|
||||
#if defined(CONFIG_X11) || defined(CONFIG_GBM) || defined(WIN32)
|
||||
EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
|
||||
EGLenum platform);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_X11) || defined(CONFIG_GBM)
|
||||
|
||||
int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy, DisplayGLMode mode);
|
||||
int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
int qemu_egl_init_dpy_win32(EGLNativeDisplayType dpy, DisplayGLMode mode);
|
||||
#endif
|
||||
|
||||
EGLContext qemu_egl_init_ctx(void);
|
||||
bool qemu_egl_has_dmabuf(void);
|
||||
|
||||
bool egl_init(const char *rendernode, DisplayGLMode mode, Error **errp);
|
||||
void egl_cleanup(void);
|
||||
|
||||
const char *qemu_egl_get_error_string(void);
|
||||
|
||||
#endif /* EGL_HELPERS_H */
|
||||
@@ -0,0 +1,234 @@
|
||||
#ifndef UI_GTK_H
|
||||
#define UI_GTK_H
|
||||
|
||||
/* Work around an -Wstrict-prototypes warning in GTK headers */
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
|
||||
#include <gtk/gtk.h>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
#include <gdk/gdkx.h>
|
||||
#include <X11/XKBlib.h>
|
||||
#endif
|
||||
|
||||
#ifdef GDK_WINDOWING_WAYLAND
|
||||
#include <gdk/gdkwayland.h>
|
||||
#endif
|
||||
|
||||
#include "ui/clipboard.h"
|
||||
#include "ui/console.h"
|
||||
#include "ui/kbd-state.h"
|
||||
#if defined(CONFIG_OPENGL)
|
||||
#include "ui/egl-helpers.h"
|
||||
#include "ui/egl-context.h"
|
||||
#endif
|
||||
#ifdef CONFIG_VTE
|
||||
#include "qemu/fifo8.h"
|
||||
#endif
|
||||
|
||||
#define MAX_VCS 10
|
||||
|
||||
typedef struct GtkDisplayState GtkDisplayState;
|
||||
|
||||
typedef struct VirtualGfxConsole {
|
||||
GtkWidget *drawing_area;
|
||||
DisplayGLCtx dgc;
|
||||
DisplayChangeListener dcl;
|
||||
QKbdState *kbd;
|
||||
DisplaySurface *ds;
|
||||
pixman_image_t *convert;
|
||||
cairo_surface_t *surface;
|
||||
double preferred_scale;
|
||||
double scale_x;
|
||||
double scale_y;
|
||||
#if defined(CONFIG_OPENGL)
|
||||
QemuGLShader *gls;
|
||||
EGLContext ectx;
|
||||
EGLSurface esurface;
|
||||
int glupdates;
|
||||
int x, y, w, h;
|
||||
egl_fb guest_fb;
|
||||
egl_fb win_fb;
|
||||
egl_fb cursor_fb;
|
||||
int cursor_x;
|
||||
int cursor_y;
|
||||
bool y0_top;
|
||||
bool scanout_mode;
|
||||
bool has_dmabuf;
|
||||
#endif
|
||||
} VirtualGfxConsole;
|
||||
|
||||
#if defined(CONFIG_VTE)
|
||||
typedef struct VirtualVteConsole {
|
||||
GtkWidget *box;
|
||||
GtkWidget *scrollbar;
|
||||
GtkWidget *terminal;
|
||||
Chardev *chr;
|
||||
Fifo8 out_fifo;
|
||||
bool echo;
|
||||
} VirtualVteConsole;
|
||||
#endif
|
||||
|
||||
typedef enum VirtualConsoleType {
|
||||
GD_VC_GFX,
|
||||
GD_VC_VTE,
|
||||
} VirtualConsoleType;
|
||||
|
||||
typedef struct VirtualConsole {
|
||||
GtkDisplayState *s;
|
||||
char *label;
|
||||
GtkWidget *window;
|
||||
GtkWidget *menu_item;
|
||||
GtkWidget *tab_item;
|
||||
GtkWidget *focus;
|
||||
VirtualConsoleType type;
|
||||
union {
|
||||
VirtualGfxConsole gfx;
|
||||
#if defined(CONFIG_VTE)
|
||||
VirtualVteConsole vte;
|
||||
#endif
|
||||
};
|
||||
} VirtualConsole;
|
||||
|
||||
struct GtkDisplayState {
|
||||
GtkWidget *window;
|
||||
|
||||
GtkWidget *menu_bar;
|
||||
|
||||
GtkAccelGroup *accel_group;
|
||||
|
||||
GtkWidget *machine_menu_item;
|
||||
GtkWidget *machine_menu;
|
||||
GtkWidget *pause_item;
|
||||
GtkWidget *reset_item;
|
||||
GtkWidget *powerdown_item;
|
||||
GtkWidget *quit_item;
|
||||
|
||||
GtkWidget *view_menu_item;
|
||||
GtkWidget *view_menu;
|
||||
GtkWidget *full_screen_item;
|
||||
GtkWidget *copy_item;
|
||||
GtkWidget *zoom_in_item;
|
||||
GtkWidget *zoom_out_item;
|
||||
GtkWidget *zoom_fixed_item;
|
||||
GtkWidget *zoom_fit_item;
|
||||
GtkWidget *grab_item;
|
||||
GtkWidget *grab_on_hover_item;
|
||||
|
||||
GPtrArray *vcs;
|
||||
|
||||
GtkWidget *vc_menu_separator;
|
||||
GtkWidget *show_tabs_item;
|
||||
GtkWidget *untabify_item;
|
||||
GtkWidget *show_menubar_item;
|
||||
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *notebook;
|
||||
int button_mask;
|
||||
gboolean last_set;
|
||||
int last_x;
|
||||
int last_y;
|
||||
int grab_x_root;
|
||||
int grab_y_root;
|
||||
VirtualConsole *kbd_owner;
|
||||
VirtualConsole *ptr_owner;
|
||||
|
||||
gboolean full_screen;
|
||||
|
||||
GdkCursor *null_cursor;
|
||||
Notifier mouse_mode_notifier;
|
||||
VMChangeStateEntry *vmse;
|
||||
Notifier console_notifier;
|
||||
gboolean free_scale;
|
||||
gboolean keep_aspect_ratio;
|
||||
|
||||
bool external_pause_update;
|
||||
|
||||
QemuClipboardPeer cbpeer;
|
||||
uint32_t cbpending[QEMU_CLIPBOARD_SELECTION__COUNT];
|
||||
GtkClipboard *gtkcb[QEMU_CLIPBOARD_SELECTION__COUNT];
|
||||
bool cbowner[QEMU_CLIPBOARD_SELECTION__COUNT];
|
||||
|
||||
DisplayOptions *opts;
|
||||
};
|
||||
|
||||
extern bool gtk_use_gl_area;
|
||||
|
||||
/* ui/gtk.c */
|
||||
void gd_update_windowsize(VirtualConsole *vc);
|
||||
void gd_update_monitor_refresh_rate(VirtualConsole *vc, GtkWidget *widget);
|
||||
void gd_hw_gl_flushed(void *vc);
|
||||
|
||||
/* ui/gtk-egl.c */
|
||||
void gd_egl_init(VirtualConsole *vc);
|
||||
void gd_egl_draw(VirtualConsole *vc);
|
||||
void gd_egl_update(DisplayChangeListener *dcl,
|
||||
int x, int y, int w, int h);
|
||||
void gd_egl_refresh(DisplayChangeListener *dcl);
|
||||
void gd_egl_switch(DisplayChangeListener *dcl,
|
||||
DisplaySurface *surface);
|
||||
QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc,
|
||||
QEMUGLParams *params);
|
||||
void gd_egl_scanout_disable(DisplayChangeListener *dcl);
|
||||
void gd_egl_scanout_texture(DisplayChangeListener *dcl,
|
||||
uint32_t backing_id,
|
||||
bool backing_y_0_top,
|
||||
uint32_t backing_width,
|
||||
uint32_t backing_height,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h,
|
||||
void *d3d_tex2d);
|
||||
void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf);
|
||||
void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf, bool have_hot,
|
||||
uint32_t hot_x, uint32_t hot_y);
|
||||
void gd_egl_cursor_position(DisplayChangeListener *dcl,
|
||||
uint32_t pos_x, uint32_t pos_y);
|
||||
void gd_egl_flush(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
||||
void gd_egl_scanout_flush(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
||||
void gtk_egl_init(DisplayGLMode mode);
|
||||
int gd_egl_make_current(DisplayGLCtx *dgc,
|
||||
QEMUGLContext ctx);
|
||||
|
||||
/* ui/gtk-gl-area.c */
|
||||
void gd_gl_area_init(VirtualConsole *vc);
|
||||
void gd_gl_area_draw(VirtualConsole *vc);
|
||||
void gd_gl_area_update(DisplayChangeListener *dcl,
|
||||
int x, int y, int w, int h);
|
||||
void gd_gl_area_refresh(DisplayChangeListener *dcl);
|
||||
void gd_gl_area_switch(DisplayChangeListener *dcl,
|
||||
DisplaySurface *surface);
|
||||
QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
|
||||
QEMUGLParams *params);
|
||||
void gd_gl_area_destroy_context(DisplayGLCtx *dgc,
|
||||
QEMUGLContext ctx);
|
||||
void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf);
|
||||
void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
|
||||
uint32_t backing_id,
|
||||
bool backing_y_0_top,
|
||||
uint32_t backing_width,
|
||||
uint32_t backing_height,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h,
|
||||
void *d3d_tex2d);
|
||||
void gd_gl_area_scanout_disable(DisplayChangeListener *dcl);
|
||||
void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
||||
void gtk_gl_area_init(void);
|
||||
int gd_gl_area_make_current(DisplayGLCtx *dgc,
|
||||
QEMUGLContext ctx);
|
||||
|
||||
/* gtk-clipboard.c */
|
||||
void gd_clipboard_init(GtkDisplayState *gd);
|
||||
void gd_clipboard_cleanup(GtkDisplayState *gd);
|
||||
|
||||
void gd_update_scale(VirtualConsole *vc, int ww, int wh, int fbw, int fbh);
|
||||
|
||||
#endif /* UI_GTK_H */
|
||||
@@ -0,0 +1,166 @@
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#include "qapi/qapi-types-ui.h"
|
||||
#include "qemu/notify.h"
|
||||
|
||||
#define INPUT_EVENT_MASK_KEY (1<<INPUT_EVENT_KIND_KEY)
|
||||
#define INPUT_EVENT_MASK_BTN (1<<INPUT_EVENT_KIND_BTN)
|
||||
#define INPUT_EVENT_MASK_REL (1<<INPUT_EVENT_KIND_REL)
|
||||
#define INPUT_EVENT_MASK_ABS (1<<INPUT_EVENT_KIND_ABS)
|
||||
#define INPUT_EVENT_MASK_MTT (1<<INPUT_EVENT_KIND_MTT)
|
||||
|
||||
#define INPUT_EVENT_ABS_MIN 0x0000
|
||||
#define INPUT_EVENT_ABS_MAX 0x7FFF
|
||||
#define INPUT_EVENT_SLOTS_MIN 0x0
|
||||
#define INPUT_EVENT_SLOTS_MAX 0xa
|
||||
|
||||
typedef struct QemuInputHandler QemuInputHandler;
|
||||
typedef struct QemuInputHandlerState QemuInputHandlerState;
|
||||
|
||||
typedef struct QemuInputKeyEvent {
|
||||
unsigned int key;
|
||||
bool down;
|
||||
} QemuInputKeyEvent;
|
||||
|
||||
typedef struct QemuInputEvent {
|
||||
InputEventKind type;
|
||||
union {
|
||||
QemuInputKeyEvent key;
|
||||
InputBtnEvent btn;
|
||||
InputMoveEvent rel;
|
||||
InputMoveEvent abs;
|
||||
InputMultiTouchEvent mtt;
|
||||
};
|
||||
} QemuInputEvent;
|
||||
|
||||
typedef void (*QemuInputHandlerEvent)(DeviceState *dev, QemuConsole *src,
|
||||
QemuInputEvent *evt);
|
||||
typedef void (*QemuInputHandlerSync)(DeviceState *dev);
|
||||
|
||||
struct QemuInputHandler {
|
||||
const char *name;
|
||||
uint32_t mask;
|
||||
QemuInputHandlerEvent event;
|
||||
QemuInputHandlerSync sync;
|
||||
};
|
||||
|
||||
G_GNUC_WARN_UNUSED_RESULT
|
||||
QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
|
||||
const QemuInputHandler *handler);
|
||||
void qemu_input_handler_activate(QemuInputHandlerState *s);
|
||||
void qemu_input_handler_deactivate(QemuInputHandlerState *s);
|
||||
void qemu_input_handler_unregister(QemuInputHandlerState *s);
|
||||
void qemu_input_handler_bind(QemuInputHandlerState *s,
|
||||
const char *device_id, int head,
|
||||
Error **errp);
|
||||
void qemu_input_event_send(QemuConsole *src, QemuInputEvent *evt);
|
||||
void qemu_input_event_send_impl(QemuConsole *src, QemuInputEvent *evt);
|
||||
void qemu_input_event_sync(void);
|
||||
void qemu_input_event_sync_impl(void);
|
||||
|
||||
void qemu_input_event_send_key_linux(QemuConsole *src, unsigned int lnx,
|
||||
bool down);
|
||||
void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down);
|
||||
void qemu_input_event_send_key_delay(uint32_t delay_ms);
|
||||
int qemu_input_key_number_to_qcode(unsigned int nr);
|
||||
unsigned int qemu_input_key_number_to_linux(unsigned int nr);
|
||||
unsigned int qemu_input_key_value_to_linux(const KeyValue *value);
|
||||
int qemu_input_linux_to_scancode(unsigned int lnx, bool down, int *codes);
|
||||
int qemu_input_linux_to_qcode(unsigned int lnx);
|
||||
|
||||
void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down);
|
||||
void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
|
||||
uint32_t button_old, uint32_t button_new);
|
||||
|
||||
bool qemu_input_is_absolute(const QemuConsole *con);
|
||||
int qemu_input_scale_axis(int value,
|
||||
int min_in, int max_in,
|
||||
int min_out, int max_out);
|
||||
void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value);
|
||||
void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value,
|
||||
int min_in, int max_in);
|
||||
void qemu_input_queue_mtt(QemuConsole *src, InputMultiTouchType type, int slot,
|
||||
int tracking_id);
|
||||
void qemu_input_queue_mtt_abs(QemuConsole *src, InputAxis axis, int value,
|
||||
int min_in, int max_in,
|
||||
int slot, int tracking_id);
|
||||
|
||||
/* Touch devices */
|
||||
typedef struct touch_slot {
|
||||
int x;
|
||||
int y;
|
||||
int tracking_id;
|
||||
} touch_slot;
|
||||
|
||||
void qemu_input_touch_event(QemuConsole *con,
|
||||
struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX],
|
||||
uint64_t num_slot,
|
||||
int width, int height,
|
||||
double x, double y,
|
||||
InputMultiTouchType type,
|
||||
Error **errp);
|
||||
|
||||
void qemu_add_mouse_mode_change_notifier(Notifier *notify);
|
||||
void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
|
||||
|
||||
extern const guint qemu_input_map_atset1_to_linux_len;
|
||||
extern const guint16 qemu_input_map_atset1_to_linux[];
|
||||
|
||||
extern const guint qemu_input_map_linux_to_qcode_len;
|
||||
extern const guint16 qemu_input_map_linux_to_qcode[];
|
||||
|
||||
extern const guint qemu_input_map_linux_to_atset1_len;
|
||||
extern const guint16 qemu_input_map_linux_to_atset1[];
|
||||
|
||||
extern const guint qemu_input_map_linux_to_atset2_len;
|
||||
extern const guint16 qemu_input_map_linux_to_atset2[];
|
||||
|
||||
extern const guint qemu_input_map_linux_to_atset3_len;
|
||||
extern const guint16 qemu_input_map_linux_to_atset3[];
|
||||
|
||||
extern const guint qemu_input_map_qcode_to_linux_len;
|
||||
extern const guint16 qemu_input_map_qcode_to_linux[];
|
||||
|
||||
extern const guint qemu_input_map_linux_to_qnum_len;
|
||||
extern const guint16 qemu_input_map_linux_to_qnum[];
|
||||
|
||||
extern const guint qemu_input_map_linux_to_sun_len;
|
||||
extern const guint16 qemu_input_map_linux_to_sun[];
|
||||
|
||||
extern const guint qemu_input_map_qnum_to_linux_len;
|
||||
extern const guint16 qemu_input_map_qnum_to_linux[];
|
||||
|
||||
extern const guint qemu_input_map_usb_to_linux_len;
|
||||
extern const guint16 qemu_input_map_usb_to_linux[];
|
||||
|
||||
extern const guint qemu_input_map_win32_to_linux_len;
|
||||
extern const guint16 qemu_input_map_win32_to_linux[];
|
||||
|
||||
extern const guint qemu_input_map_x11_to_linux_len;
|
||||
extern const guint16 qemu_input_map_x11_to_linux[];
|
||||
|
||||
extern const guint qemu_input_map_xorgkbd_to_linux_len;
|
||||
extern const guint16 qemu_input_map_xorgkbd_to_linux[];
|
||||
|
||||
extern const guint qemu_input_map_xorgxquartz_to_linux_len;
|
||||
extern const guint16 qemu_input_map_xorgxquartz_to_linux[];
|
||||
|
||||
extern const guint qemu_input_map_xorgxwin_to_linux_len;
|
||||
extern const guint16 qemu_input_map_xorgxwin_to_linux[];
|
||||
|
||||
extern const guint qemu_input_map_osx_to_linux_len;
|
||||
extern const guint16 qemu_input_map_osx_to_linux[];
|
||||
|
||||
/**
|
||||
* qemu_input_get_leds_mask() - get the LED mask for the given console
|
||||
* @con: a QemuConsole or NULL
|
||||
*
|
||||
* If @con is NULL, returns the LED state mask for the default console.
|
||||
*/
|
||||
uint32_t qemu_input_get_leds_mask(const QemuConsole *con);
|
||||
void qemu_input_handler_set_leds_mask(QemuInputHandlerState *s, uint32_t leds_mask);
|
||||
void qemu_input_led_notifier_add(Notifier *n);
|
||||
void qemu_input_led_notifier_remove(Notifier *n);
|
||||
|
||||
#endif /* INPUT_H */
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or
|
||||
* (at your option) any later version. See the COPYING file in the
|
||||
* top-level directory.
|
||||
*/
|
||||
|
||||
#ifndef QEMU_UI_KBD_STATE_H
|
||||
#define QEMU_UI_KBD_STATE_H
|
||||
|
||||
#include "qapi/qapi-types-ui.h"
|
||||
|
||||
typedef enum QKbdModifier QKbdModifier;
|
||||
|
||||
enum QKbdModifier {
|
||||
QKBD_MOD_NONE = 0,
|
||||
|
||||
QKBD_MOD_SHIFT,
|
||||
QKBD_MOD_CTRL,
|
||||
QKBD_MOD_ALT,
|
||||
QKBD_MOD_ALTGR,
|
||||
|
||||
QKBD_MOD_NUMLOCK,
|
||||
QKBD_MOD_CAPSLOCK,
|
||||
|
||||
QKBD_MOD__MAX
|
||||
};
|
||||
|
||||
typedef struct QKbdState QKbdState;
|
||||
|
||||
/**
|
||||
* qkbd_state_init: init keyboard state tracker.
|
||||
*
|
||||
* Allocates and initializes keyboard state struct.
|
||||
*
|
||||
* @con: QemuConsole for this state tracker. Gets passed down to
|
||||
* qemu_input_*() functions when sending key events to the guest.
|
||||
*/
|
||||
QKbdState *qkbd_state_init(QemuConsole *con);
|
||||
|
||||
/**
|
||||
* qkbd_state_free: free keyboard tracker state.
|
||||
*
|
||||
* @kbd: state tracker state.
|
||||
*/
|
||||
void qkbd_state_free(QKbdState *kbd);
|
||||
|
||||
/**
|
||||
* qkbd_state_key_event: process key event.
|
||||
*
|
||||
* Update keyboard state, send event to the guest.
|
||||
*
|
||||
* This function takes care to not send suspious events (keyup event
|
||||
* for a key not pressed for example).
|
||||
*
|
||||
* This function drops events with key codes outside the defined range.
|
||||
*
|
||||
* @kbd: state tracker state.
|
||||
* @lnx: the key pressed or released.
|
||||
* @down: true for key down events, false otherwise.
|
||||
*/
|
||||
void qkbd_state_key_event(QKbdState *kbd, unsigned int lnx, bool down);
|
||||
|
||||
/**
|
||||
* qkbd_state_set_delay: set key press delay.
|
||||
*
|
||||
* When set the specified delay will be added after each key event,
|
||||
* using qemu_input_event_send_key_delay().
|
||||
*
|
||||
* @kbd: state tracker state.
|
||||
* @delay_ms: the delay in milliseconds.
|
||||
*/
|
||||
void qkbd_state_set_delay(QKbdState *kbd, int delay_ms);
|
||||
|
||||
/**
|
||||
* qkbd_state_key_get: get key state.
|
||||
*
|
||||
* Returns true when the key code is in the defined range and the key is down.
|
||||
*
|
||||
* @kbd: state tracker state.
|
||||
* @lnx: the key to query.
|
||||
*/
|
||||
bool qkbd_state_key_get(QKbdState *kbd, unsigned int lnx);
|
||||
|
||||
/**
|
||||
* qkbd_state_modifier_get: get modifier state.
|
||||
*
|
||||
* Returns true when the modifier is active.
|
||||
*
|
||||
* @kbd: state tracker state.
|
||||
* @mod: the modifier to query.
|
||||
*/
|
||||
bool qkbd_state_modifier_get(QKbdState *kbd, QKbdModifier mod);
|
||||
|
||||
/**
|
||||
* qkbd_state_lift_all_keys: lift all pressed keys.
|
||||
*
|
||||
* This sends key up events to the guest for all keys which are in
|
||||
* down state.
|
||||
*
|
||||
* @kbd: state tracker state.
|
||||
*/
|
||||
void qkbd_state_lift_all_keys(QKbdState *kbd);
|
||||
|
||||
/**
|
||||
* qkbd_state_switch_console: Switch console.
|
||||
*
|
||||
* This sends key up events to the previous console for all keys which are in
|
||||
* down state to prevent keys being stuck, and remembers the new console.
|
||||
*
|
||||
* @kbd: state tracker state.
|
||||
* @con: new QemuConsole for this state tracker.
|
||||
*/
|
||||
void qkbd_state_switch_console(QKbdState *kbd, QemuConsole *con);
|
||||
|
||||
#endif /* QEMU_UI_KBD_STATE_H */
|
||||
@@ -0,0 +1,53 @@
|
||||
static inline unsigned int rgb_to_pixel8(unsigned int r, unsigned int g,
|
||||
unsigned int b)
|
||||
{
|
||||
return ((r >> 5) << 5) | ((g >> 5) << 2) | (b >> 6);
|
||||
}
|
||||
|
||||
static inline unsigned int rgb_to_pixel15(unsigned int r, unsigned int g,
|
||||
unsigned int b)
|
||||
{
|
||||
return ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3);
|
||||
}
|
||||
|
||||
static inline unsigned int rgb_to_pixel15bgr(unsigned int r, unsigned int g,
|
||||
unsigned int b)
|
||||
{
|
||||
return ((b >> 3) << 10) | ((g >> 3) << 5) | (r >> 3);
|
||||
}
|
||||
|
||||
static inline unsigned int rgb_to_pixel16(unsigned int r, unsigned int g,
|
||||
unsigned int b)
|
||||
{
|
||||
return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
|
||||
}
|
||||
|
||||
static inline unsigned int rgb_to_pixel16bgr(unsigned int r, unsigned int g,
|
||||
unsigned int b)
|
||||
{
|
||||
return ((b >> 3) << 11) | ((g >> 2) << 5) | (r >> 3);
|
||||
}
|
||||
|
||||
static inline unsigned int rgb_to_pixel24(unsigned int r, unsigned int g,
|
||||
unsigned int b)
|
||||
{
|
||||
return (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
static inline unsigned int rgb_to_pixel24bgr(unsigned int r, unsigned int g,
|
||||
unsigned int b)
|
||||
{
|
||||
return (b << 16) | (g << 8) | r;
|
||||
}
|
||||
|
||||
static inline unsigned int rgb_to_pixel32(unsigned int r, unsigned int g,
|
||||
unsigned int b)
|
||||
{
|
||||
return (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
static inline unsigned int rgb_to_pixel32bgr(unsigned int r, unsigned int g,
|
||||
unsigned int b)
|
||||
{
|
||||
return (b << 16) | (g << 8) | r;
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Tiny subset of PIXMAN API commonly used by QEMU.
|
||||
*
|
||||
* Copyright 1987, 1988, 1989, 1998 The Open Group
|
||||
* Copyright 1987, 1988, 1989 Digital Equipment Corporation
|
||||
* Copyright 1999, 2004, 2008 Keith Packard
|
||||
* Copyright 2000 SuSE, Inc.
|
||||
* Copyright 2000 Keith Packard, member of The XFree86 Project, Inc.
|
||||
* Copyright 2004, 2005, 2007, 2008, 2009, 2010 Red Hat, Inc.
|
||||
* Copyright 2004 Nicholas Miell
|
||||
* Copyright 2005 Lars Knoll & Zack Rusin, Trolltech
|
||||
* Copyright 2005 Trolltech AS
|
||||
* Copyright 2007 Luca Barbato
|
||||
* Copyright 2008 Aaron Plattner, NVIDIA Corporation
|
||||
* Copyright 2008 Rodrigo Kumpera
|
||||
* Copyright 2008 André Tupinambá
|
||||
* Copyright 2008 Mozilla Corporation
|
||||
* Copyright 2008 Frederic Plourde
|
||||
* Copyright 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright 2009, 2010 Nokia Corporation
|
||||
*
|
||||
* 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 (including the next
|
||||
* paragraph) 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.
|
||||
*/
|
||||
|
||||
#ifndef PIXMAN_MINIMAL_H
|
||||
#define PIXMAN_MINIMAL_H
|
||||
|
||||
#define PIXMAN_TYPE_OTHER 0
|
||||
#define PIXMAN_TYPE_ARGB 2
|
||||
#define PIXMAN_TYPE_ABGR 3
|
||||
#define PIXMAN_TYPE_BGRA 8
|
||||
#define PIXMAN_TYPE_RGBA 9
|
||||
|
||||
#define PIXMAN_FORMAT(bpp, type, a, r, g, b) (((bpp) << 24) | \
|
||||
((type) << 16) | \
|
||||
((a) << 12) | \
|
||||
((r) << 8) | \
|
||||
((g) << 4) | \
|
||||
((b)))
|
||||
|
||||
#define PIXMAN_FORMAT_RESHIFT(val, ofs, num) \
|
||||
(((val >> (ofs)) & ((1 << (num)) - 1)) << ((val >> 22) & 3))
|
||||
|
||||
#define PIXMAN_FORMAT_BPP(f) PIXMAN_FORMAT_RESHIFT(f, 24, 8)
|
||||
#define PIXMAN_FORMAT_TYPE(f) (((f) >> 16) & 0x3f)
|
||||
#define PIXMAN_FORMAT_A(f) PIXMAN_FORMAT_RESHIFT(f, 12, 4)
|
||||
#define PIXMAN_FORMAT_R(f) PIXMAN_FORMAT_RESHIFT(f, 8, 4)
|
||||
#define PIXMAN_FORMAT_G(f) PIXMAN_FORMAT_RESHIFT(f, 4, 4)
|
||||
#define PIXMAN_FORMAT_B(f) PIXMAN_FORMAT_RESHIFT(f, 0, 4)
|
||||
#define PIXMAN_FORMAT_DEPTH(f) (PIXMAN_FORMAT_A(f) + \
|
||||
PIXMAN_FORMAT_R(f) + \
|
||||
PIXMAN_FORMAT_G(f) + \
|
||||
PIXMAN_FORMAT_B(f))
|
||||
|
||||
typedef enum {
|
||||
/* 32bpp formats */
|
||||
PIXMAN_a8r8g8b8 = PIXMAN_FORMAT(32, PIXMAN_TYPE_ARGB, 8, 8, 8, 8),
|
||||
PIXMAN_x8r8g8b8 = PIXMAN_FORMAT(32, PIXMAN_TYPE_ARGB, 0, 8, 8, 8),
|
||||
PIXMAN_a8b8g8r8 = PIXMAN_FORMAT(32, PIXMAN_TYPE_ABGR, 8, 8, 8, 8),
|
||||
PIXMAN_x8b8g8r8 = PIXMAN_FORMAT(32, PIXMAN_TYPE_ABGR, 0, 8, 8, 8),
|
||||
PIXMAN_b8g8r8a8 = PIXMAN_FORMAT(32, PIXMAN_TYPE_BGRA, 8, 8, 8, 8),
|
||||
PIXMAN_b8g8r8x8 = PIXMAN_FORMAT(32, PIXMAN_TYPE_BGRA, 0, 8, 8, 8),
|
||||
PIXMAN_r8g8b8a8 = PIXMAN_FORMAT(32, PIXMAN_TYPE_RGBA, 8, 8, 8, 8),
|
||||
PIXMAN_r8g8b8x8 = PIXMAN_FORMAT(32, PIXMAN_TYPE_RGBA, 0, 8, 8, 8),
|
||||
/* 24bpp formats */
|
||||
PIXMAN_r8g8b8 = PIXMAN_FORMAT(24, PIXMAN_TYPE_ARGB, 0, 8, 8, 8),
|
||||
PIXMAN_b8g8r8 = PIXMAN_FORMAT(24, PIXMAN_TYPE_ABGR, 0, 8, 8, 8),
|
||||
/* 16bpp formats */
|
||||
PIXMAN_r5g6b5 = PIXMAN_FORMAT(16, PIXMAN_TYPE_ARGB, 0, 5, 6, 5),
|
||||
PIXMAN_a1r5g5b5 = PIXMAN_FORMAT(16, PIXMAN_TYPE_ARGB, 1, 5, 5, 5),
|
||||
PIXMAN_x1r5g5b5 = PIXMAN_FORMAT(16, PIXMAN_TYPE_ARGB, 0, 5, 5, 5),
|
||||
} pixman_format_code_t;
|
||||
|
||||
typedef struct pixman_image pixman_image_t;
|
||||
|
||||
typedef void (*pixman_image_destroy_func_t)(pixman_image_t *image, void *data);
|
||||
|
||||
struct pixman_image {
|
||||
int ref_count;
|
||||
pixman_format_code_t format;
|
||||
int width;
|
||||
int height;
|
||||
int stride;
|
||||
uint32_t *data;
|
||||
uint32_t *free_me;
|
||||
pixman_image_destroy_func_t destroy_func;
|
||||
void *destroy_data;
|
||||
};
|
||||
|
||||
typedef struct pixman_color {
|
||||
uint16_t red;
|
||||
uint16_t green;
|
||||
uint16_t blue;
|
||||
uint16_t alpha;
|
||||
} pixman_color_t;
|
||||
|
||||
#include "qemu-pixman-helpers.h"
|
||||
|
||||
static inline uint32_t *create_bits(pixman_format_code_t format,
|
||||
int width,
|
||||
int height,
|
||||
int *rowstride_bytes)
|
||||
{
|
||||
int stride = 0;
|
||||
size_t buf_size = 0;
|
||||
|
||||
if (!qemu_pixman_image_calc_size(format, width, height,
|
||||
&stride, &buf_size)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (rowstride_bytes) {
|
||||
*rowstride_bytes = stride;
|
||||
}
|
||||
|
||||
return g_malloc0(buf_size);
|
||||
}
|
||||
|
||||
static inline pixman_image_t *pixman_image_create_bits(pixman_format_code_t format,
|
||||
int width,
|
||||
int height,
|
||||
uint32_t *bits,
|
||||
int rowstride_bytes)
|
||||
{
|
||||
pixman_image_t *i = g_new0(pixman_image_t, 1);
|
||||
|
||||
i->width = width;
|
||||
i->height = height;
|
||||
i->format = format;
|
||||
if (bits) {
|
||||
i->data = bits;
|
||||
} else {
|
||||
i->free_me = i->data =
|
||||
create_bits(format, width, height, &rowstride_bytes);
|
||||
if (width && height) {
|
||||
assert(i->data);
|
||||
}
|
||||
}
|
||||
i->stride = rowstride_bytes ? rowstride_bytes :
|
||||
width * DIV_ROUND_UP(PIXMAN_FORMAT_BPP(format), 8);
|
||||
i->ref_count = 1;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static inline pixman_image_t *pixman_image_ref(pixman_image_t *i)
|
||||
{
|
||||
i->ref_count++;
|
||||
return i;
|
||||
}
|
||||
|
||||
static inline bool pixman_image_unref(pixman_image_t *i)
|
||||
{
|
||||
i->ref_count--;
|
||||
|
||||
if (i->ref_count == 0) {
|
||||
if (i->destroy_func) {
|
||||
i->destroy_func(i, i->destroy_data);
|
||||
}
|
||||
g_free(i->free_me);
|
||||
g_free(i);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void pixman_image_set_destroy_function(pixman_image_t *i,
|
||||
pixman_image_destroy_func_t func,
|
||||
void *data)
|
||||
|
||||
{
|
||||
i->destroy_func = func;
|
||||
i->destroy_data = data;
|
||||
}
|
||||
|
||||
static inline uint32_t *pixman_image_get_data(pixman_image_t *i)
|
||||
{
|
||||
return i->data;
|
||||
}
|
||||
|
||||
static inline int pixman_image_get_height(pixman_image_t *i)
|
||||
{
|
||||
return i->height;
|
||||
}
|
||||
|
||||
static inline int pixman_image_get_width(pixman_image_t *i)
|
||||
{
|
||||
return i->width;
|
||||
}
|
||||
|
||||
static inline int pixman_image_get_stride(pixman_image_t *i)
|
||||
{
|
||||
return i->stride;
|
||||
}
|
||||
|
||||
static inline pixman_format_code_t pixman_image_get_format(pixman_image_t *i)
|
||||
{
|
||||
return i->format;
|
||||
}
|
||||
|
||||
#endif /* PIXMAN_MINIMAL_H */
|
||||
@@ -0,0 +1,49 @@
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
/*
|
||||
* Pixman stride and buffer size helpers.
|
||||
* Expects PIXMAN_FORMAT_BPP() and pixman_format_code_t to be
|
||||
* already defined (by either <pixman.h> or "pixman-minimal.h").
|
||||
*/
|
||||
|
||||
#ifndef QEMU_PIXMAN_HELPERS_H
|
||||
#define QEMU_PIXMAN_HELPERS_H
|
||||
|
||||
/*
|
||||
* Compute the row stride for a pixman image, aligned to sizeof(uint32_t),
|
||||
* as pixman does. Returns -1 on integer overflow.
|
||||
*/
|
||||
static inline int qemu_pixman_stride(pixman_format_code_t format, int width)
|
||||
{
|
||||
int stride;
|
||||
|
||||
if (unlikely(__builtin_mul_overflow(width, PIXMAN_FORMAT_BPP(format),
|
||||
&stride)) ||
|
||||
unlikely(__builtin_add_overflow(stride, 31, &stride))) {
|
||||
return -1;
|
||||
}
|
||||
return (stride / 32) * sizeof(uint32_t);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute stride and buffer size for a pixman image.
|
||||
* If *rowstride_bytes is 0, compute it from format and width
|
||||
* (aligned to sizeof(uint32_t), as pixman does).
|
||||
* Returns false on integer overflow.
|
||||
*/
|
||||
static inline bool qemu_pixman_image_calc_size(pixman_format_code_t format,
|
||||
int width, int height,
|
||||
int *rowstride_bytes,
|
||||
size_t *buf_size)
|
||||
{
|
||||
if (!*rowstride_bytes) {
|
||||
*rowstride_bytes = qemu_pixman_stride(format, width);
|
||||
if (*rowstride_bytes < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return likely(!__builtin_mul_overflow((size_t)height,
|
||||
(size_t)*rowstride_bytes, buf_size));
|
||||
}
|
||||
|
||||
#endif /* QEMU_PIXMAN_HELPERS_H */
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#ifndef QEMU_PIXMAN_H
|
||||
#define QEMU_PIXMAN_H
|
||||
|
||||
#ifdef CONFIG_PIXMAN
|
||||
#include <pixman.h>
|
||||
#include "qemu-pixman-helpers.h"
|
||||
#else
|
||||
#include "pixman-minimal.h"
|
||||
#endif
|
||||
|
||||
#include "qapi/error.h"
|
||||
|
||||
/*
|
||||
* pixman image formats are defined to be native endian,
|
||||
* that means host byte order on qemu. So we go define
|
||||
* fixed formats here for cases where it is needed, like
|
||||
* feeding libjpeg / libpng and writing screenshots.
|
||||
*/
|
||||
|
||||
#if HOST_BIG_ENDIAN
|
||||
# define PIXMAN_BE_r8g8b8 PIXMAN_r8g8b8
|
||||
# define PIXMAN_BE_x8r8g8b8 PIXMAN_x8r8g8b8
|
||||
# define PIXMAN_BE_a8r8g8b8 PIXMAN_a8r8g8b8
|
||||
# define PIXMAN_BE_b8g8r8x8 PIXMAN_b8g8r8x8
|
||||
# define PIXMAN_BE_b8g8r8a8 PIXMAN_b8g8r8a8
|
||||
# define PIXMAN_BE_r8g8b8x8 PIXMAN_r8g8b8x8
|
||||
# define PIXMAN_BE_r8g8b8a8 PIXMAN_r8g8b8a8
|
||||
# define PIXMAN_BE_x8b8g8r8 PIXMAN_x8b8g8r8
|
||||
# define PIXMAN_BE_a8b8g8r8 PIXMAN_a8b8g8r8
|
||||
# define PIXMAN_LE_r8g8b8 PIXMAN_b8g8r8
|
||||
# define PIXMAN_LE_a8r8g8b8 PIXMAN_b8g8r8a8
|
||||
# define PIXMAN_LE_x8r8g8b8 PIXMAN_b8g8r8x8
|
||||
# define PIXMAN_LE_a8b8g8r8 PIXMAN_r8g8b8a8
|
||||
# define PIXMAN_LE_x8b8g8r8 PIXMAN_r8g8b8x8
|
||||
#else
|
||||
# define PIXMAN_BE_r8g8b8 PIXMAN_b8g8r8
|
||||
# define PIXMAN_BE_x8r8g8b8 PIXMAN_b8g8r8x8
|
||||
# define PIXMAN_BE_a8r8g8b8 PIXMAN_b8g8r8a8
|
||||
# define PIXMAN_BE_b8g8r8x8 PIXMAN_x8r8g8b8
|
||||
# define PIXMAN_BE_b8g8r8a8 PIXMAN_a8r8g8b8
|
||||
# define PIXMAN_BE_r8g8b8x8 PIXMAN_x8b8g8r8
|
||||
# define PIXMAN_BE_r8g8b8a8 PIXMAN_a8b8g8r8
|
||||
# define PIXMAN_BE_x8b8g8r8 PIXMAN_r8g8b8x8
|
||||
# define PIXMAN_BE_a8b8g8r8 PIXMAN_r8g8b8a8
|
||||
# define PIXMAN_LE_r8g8b8 PIXMAN_r8g8b8
|
||||
# define PIXMAN_LE_a8r8g8b8 PIXMAN_a8r8g8b8
|
||||
# define PIXMAN_LE_x8r8g8b8 PIXMAN_x8r8g8b8
|
||||
# define PIXMAN_LE_a8b8g8r8 PIXMAN_a8b8g8r8
|
||||
# define PIXMAN_LE_x8b8g8r8 PIXMAN_x8b8g8r8
|
||||
#endif
|
||||
|
||||
#define QEMU_PIXMAN_COLOR(r, g, b) \
|
||||
{ .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff }
|
||||
|
||||
#define QEMU_PIXMAN_COLOR_BLACK QEMU_PIXMAN_COLOR(0x00, 0x00, 0x00)
|
||||
#define QEMU_PIXMAN_COLOR_GRAY QEMU_PIXMAN_COLOR(0xaa, 0xaa, 0xaa)
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
typedef struct PixelFormat {
|
||||
uint8_t bits_per_pixel;
|
||||
uint8_t bytes_per_pixel;
|
||||
uint8_t depth; /* color depth in bits */
|
||||
uint32_t rmask, gmask, bmask, amask;
|
||||
uint8_t rshift, gshift, bshift, ashift;
|
||||
uint8_t rmax, gmax, bmax, amax;
|
||||
uint8_t rbits, gbits, bbits, abits;
|
||||
} PixelFormat;
|
||||
|
||||
PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format);
|
||||
pixman_format_code_t qemu_default_pixman_format(int bpp, bool native_endian);
|
||||
|
||||
static inline PixelFormat qemu_default_pixelformat(int bpp)
|
||||
{
|
||||
pixman_format_code_t fmt = qemu_default_pixman_format(bpp, true);
|
||||
PixelFormat pf = qemu_pixelformat_from_pixman(fmt);
|
||||
return pf;
|
||||
}
|
||||
|
||||
pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format);
|
||||
uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman);
|
||||
int qemu_pixman_get_type(int rshift, int gshift, int bshift, int endian);
|
||||
bool qemu_pixman_check_format(DisplayChangeListener *dcl,
|
||||
pixman_format_code_t format);
|
||||
|
||||
#ifdef CONFIG_PIXMAN
|
||||
pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf, int endian);
|
||||
pixman_image_t *qemu_pixman_linebuf_create(pixman_format_code_t format,
|
||||
int width);
|
||||
void qemu_pixman_linebuf_fill(pixman_image_t *linebuf, pixman_image_t *fb,
|
||||
int width, int x, int y);
|
||||
pixman_image_t *qemu_pixman_mirror_create(pixman_format_code_t format,
|
||||
pixman_image_t *image);
|
||||
|
||||
pixman_image_t *qemu_pixman_glyph_from_vgafont(int height, const uint8_t *font,
|
||||
unsigned int ch);
|
||||
void qemu_pixman_glyph_render(pixman_image_t *glyph,
|
||||
pixman_image_t *surface,
|
||||
pixman_color_t *fgcol,
|
||||
pixman_color_t *bgcol,
|
||||
int x, int y, int cw, int ch);
|
||||
#endif
|
||||
|
||||
void qemu_pixman_image_unref(pixman_image_t *image);
|
||||
|
||||
#ifdef WIN32
|
||||
typedef HANDLE qemu_pixman_shareable;
|
||||
#define SHAREABLE_NONE (NULL)
|
||||
#define SHAREABLE_TO_PTR(handle) (handle)
|
||||
#define PTR_TO_SHAREABLE(ptr) (ptr)
|
||||
#else
|
||||
typedef int qemu_pixman_shareable;
|
||||
#define SHAREABLE_NONE (-1)
|
||||
#define SHAREABLE_TO_PTR(handle) GINT_TO_POINTER(handle)
|
||||
#define PTR_TO_SHAREABLE(ptr) GPOINTER_TO_INT(ptr)
|
||||
#endif
|
||||
|
||||
bool qemu_pixman_image_new_shareable(
|
||||
pixman_image_t **image,
|
||||
qemu_pixman_shareable *handle,
|
||||
const char *name,
|
||||
pixman_format_code_t format,
|
||||
int width,
|
||||
int height,
|
||||
int rowstride_bytes,
|
||||
Error **errp);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(pixman_image_t, qemu_pixman_image_unref)
|
||||
|
||||
#endif /* QEMU_PIXMAN_H */
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 or
|
||||
* (at your option) version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QEMU_SPICE_MODULE_H
|
||||
#define QEMU_SPICE_MODULE_H
|
||||
|
||||
#ifdef CONFIG_SPICE
|
||||
#include <spice.h>
|
||||
#endif
|
||||
|
||||
typedef struct SpiceInfo SpiceInfo;
|
||||
|
||||
struct QemuSpiceOps {
|
||||
void (*init)(void);
|
||||
void (*cleanup)(void);
|
||||
void (*display_init)(void);
|
||||
int (*migrate_info)(const char *h, int p, int t, const char *s);
|
||||
int (*set_passwd)(const char *passwd,
|
||||
bool fail_if_connected, bool disconnect_if_connected,
|
||||
Error **errp);
|
||||
int (*set_pw_expire)(time_t expires);
|
||||
int (*display_add_client)(int csock, int skipauth, int tls);
|
||||
#ifdef CONFIG_SPICE
|
||||
int (*add_interface)(SpiceBaseInstance *sin);
|
||||
SpiceInfo* (*qmp_query)(Error **errp);
|
||||
#endif
|
||||
};
|
||||
|
||||
extern int using_spice;
|
||||
extern struct QemuSpiceOps qemu_spice;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 or
|
||||
* (at your option) version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QEMU_SPICE_H
|
||||
#define QEMU_SPICE_H
|
||||
|
||||
#include "qapi/error.h"
|
||||
#include "ui/qemu-spice-module.h"
|
||||
|
||||
#ifdef CONFIG_SPICE
|
||||
|
||||
#include <spice.h>
|
||||
#include "qemu/config-file.h"
|
||||
|
||||
void qemu_spice_input_init(void);
|
||||
void qemu_spice_input_cleanup(void);
|
||||
void qemu_spice_display_init(void);
|
||||
void qemu_spice_display_cleanup(void);
|
||||
void qemu_spice_display_init_done(void);
|
||||
bool qemu_spice_have_display_interface(QemuConsole *con);
|
||||
int qemu_spice_add_display_interface(QXLInstance *qxlin, QemuConsole *con);
|
||||
int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
|
||||
const char *subject);
|
||||
#endif /* CONFIG_SPICE */
|
||||
|
||||
static inline bool qemu_using_spice(Error **errp)
|
||||
{
|
||||
if (!using_spice) {
|
||||
error_set(errp, ERROR_CLASS_DEVICE_NOT_ACTIVE,
|
||||
"SPICE is not in use");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* QEMU_SPICE_H */
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#ifndef QEMU_RECT_H
|
||||
#define QEMU_RECT_H
|
||||
|
||||
|
||||
typedef struct QemuRect {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
} QemuRect;
|
||||
|
||||
static inline void qemu_rect_init(QemuRect *rect,
|
||||
int16_t x, int16_t y,
|
||||
uint16_t width, uint16_t height)
|
||||
{
|
||||
rect->x = x;
|
||||
rect->y = y;
|
||||
rect->width = width;
|
||||
rect->height = height;
|
||||
}
|
||||
|
||||
static inline void qemu_rect_translate(QemuRect *rect,
|
||||
int16_t dx, int16_t dy)
|
||||
{
|
||||
rect->x += dx;
|
||||
rect->y += dy;
|
||||
}
|
||||
|
||||
static inline bool qemu_rect_intersect(const QemuRect *a, const QemuRect *b,
|
||||
QemuRect *res)
|
||||
{
|
||||
int16_t x1, x2, y1, y2;
|
||||
|
||||
x1 = MAX(a->x, b->x);
|
||||
y1 = MAX(a->y, b->y);
|
||||
x2 = MIN(a->x + a->width, b->x + b->width);
|
||||
y2 = MIN(a->y + a->height, b->y + b->height);
|
||||
|
||||
if (x1 >= x2 || y1 >= y2) {
|
||||
if (res) {
|
||||
qemu_rect_init(res, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (res) {
|
||||
qemu_rect_init(res, x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
#ifndef SDL2_H
|
||||
#define SDL2_H
|
||||
|
||||
/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
/* with Alpine / muslc SDL headers pull in directfb headers
|
||||
* which in turn trigger warning about redundant decls for
|
||||
* direct_waitqueue_deinit.
|
||||
*/
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wredundant-decls"
|
||||
|
||||
#include <SDL_syswm.h>
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#ifdef CONFIG_SDL_IMAGE
|
||||
# include <SDL_image.h>
|
||||
#endif
|
||||
|
||||
#include "ui/kbd-state.h"
|
||||
#ifdef CONFIG_OPENGL
|
||||
# include "ui/egl-helpers.h"
|
||||
#endif
|
||||
|
||||
struct sdl2_console {
|
||||
DisplayGLCtx dgc;
|
||||
DisplayChangeListener dcl;
|
||||
DisplaySurface *surface;
|
||||
DisplayOptions *opts;
|
||||
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, w, h;
|
||||
int hidden;
|
||||
int opengl;
|
||||
int updates;
|
||||
int idle_counter;
|
||||
int ignore_hotkeys;
|
||||
bool gui_keysym;
|
||||
SDL_GLContext winctx;
|
||||
QKbdState *kbd;
|
||||
bool has_dmabuf;
|
||||
#ifdef CONFIG_OPENGL
|
||||
QemuGLShader *gls;
|
||||
egl_fb guest_fb;
|
||||
egl_fb win_fb;
|
||||
bool y0_top;
|
||||
bool scanout_mode;
|
||||
#endif
|
||||
};
|
||||
|
||||
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_process_key(struct sdl2_console *scon,
|
||||
SDL_KeyboardEvent *ev);
|
||||
void sdl2_release_modifiers(struct sdl2_console *scon);
|
||||
|
||||
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);
|
||||
bool sdl2_2d_check_format(DisplayChangeListener *dcl,
|
||||
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);
|
||||
|
||||
QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc,
|
||||
QEMUGLParams *params);
|
||||
void sdl2_gl_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx);
|
||||
int sdl2_gl_make_context_current(DisplayGLCtx *dgc,
|
||||
QEMUGLContext ctx);
|
||||
|
||||
void sdl2_gl_scanout_disable(DisplayChangeListener *dcl);
|
||||
void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
|
||||
uint32_t backing_id,
|
||||
bool backing_y_0_top,
|
||||
uint32_t backing_width,
|
||||
uint32_t backing_height,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t w, uint32_t h,
|
||||
void *d3d_tex2d);
|
||||
void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
|
||||
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
|
||||
void sdl2_gl_scanout_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf);
|
||||
void sdl2_gl_release_dmabuf(DisplayChangeListener *dcl,
|
||||
QemuDmaBuf *dmabuf);
|
||||
bool sdl2_gl_has_dmabuf(DisplayChangeListener *dcl);
|
||||
void sdl2_gl_console_init(struct sdl2_console *scon);
|
||||
|
||||
#endif /* SDL2_H */
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef QEMU_SHADER_H
|
||||
#define QEMU_SHADER_H
|
||||
|
||||
typedef struct QemuGLShader QemuGLShader;
|
||||
|
||||
void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip);
|
||||
|
||||
QemuGLShader *qemu_gl_init_shader(void);
|
||||
void qemu_gl_fini_shader(QemuGLShader *gls);
|
||||
|
||||
#endif /* QEMU_SHADER_H */
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 or
|
||||
* (at your option) version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UI_SPICE_DISPLAY_H
|
||||
#define UI_SPICE_DISPLAY_H
|
||||
|
||||
#include <spice.h>
|
||||
#include <spice/ipc_ring.h>
|
||||
#include <spice/enums.h>
|
||||
#include <spice/qxl_dev.h>
|
||||
|
||||
#include "qemu/thread.h"
|
||||
#include "ui/qemu-pixman.h"
|
||||
#include "ui/console.h"
|
||||
|
||||
#if defined(CONFIG_OPENGL) && defined(CONFIG_GBM)
|
||||
# define HAVE_SPICE_GL 1
|
||||
# include "ui/egl-helpers.h"
|
||||
# include "ui/egl-context.h"
|
||||
#endif
|
||||
|
||||
#define NUM_MEMSLOTS 8
|
||||
#define MEMSLOT_GENERATION_BITS 8
|
||||
#define MEMSLOT_SLOT_BITS 8
|
||||
|
||||
#define MEMSLOT_GROUP_HOST 0
|
||||
#define MEMSLOT_GROUP_GUEST 1
|
||||
#define NUM_MEMSLOTS_GROUPS 2
|
||||
|
||||
/*
|
||||
* Internal enum to differentiate between options for
|
||||
* io calls that have a sync (old) version and an _async (new)
|
||||
* version:
|
||||
* QXL_SYNC: use the old version
|
||||
* QXL_ASYNC: use the new version and make sure there are no two
|
||||
* happening at the same time. This is used for guest initiated
|
||||
* calls
|
||||
*/
|
||||
typedef enum qxl_async_io {
|
||||
QXL_SYNC,
|
||||
QXL_ASYNC,
|
||||
} qxl_async_io;
|
||||
|
||||
enum {
|
||||
QXL_COOKIE_TYPE_IO,
|
||||
QXL_COOKIE_TYPE_RENDER_UPDATE_AREA,
|
||||
QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG,
|
||||
QXL_COOKIE_TYPE_GL_DRAW_DONE,
|
||||
};
|
||||
|
||||
typedef struct QXLCookie {
|
||||
int type;
|
||||
uint64_t io;
|
||||
union {
|
||||
uint32_t surface_id;
|
||||
QXLRect area;
|
||||
struct {
|
||||
QXLRect area;
|
||||
int redraw;
|
||||
} render;
|
||||
void *data;
|
||||
} u;
|
||||
} QXLCookie;
|
||||
|
||||
QXLCookie *qxl_cookie_new(int type, uint64_t io);
|
||||
|
||||
typedef struct SimpleSpiceDisplay SimpleSpiceDisplay;
|
||||
typedef struct SimpleSpiceUpdate SimpleSpiceUpdate;
|
||||
typedef struct SimpleSpiceCursor SimpleSpiceCursor;
|
||||
|
||||
struct SimpleSpiceDisplay {
|
||||
DisplaySurface *ds;
|
||||
DisplayGLCtx dgc;
|
||||
DisplayChangeListener dcl;
|
||||
void *buf;
|
||||
int bufsize;
|
||||
QXLInstance qxl;
|
||||
uint32_t unique;
|
||||
pixman_image_t *surface;
|
||||
pixman_image_t *mirror;
|
||||
int32_t num_surfaces;
|
||||
|
||||
QXLRect dirty;
|
||||
int notify;
|
||||
|
||||
/*
|
||||
* All struct members below this comment can be accessed from
|
||||
* both spice server and qemu (iothread) context and any access
|
||||
* to them must be protected by the lock.
|
||||
*/
|
||||
QemuMutex lock;
|
||||
QTAILQ_HEAD(, SimpleSpiceUpdate) updates;
|
||||
|
||||
/* cursor (without qxl): displaychangelistener -> spice server */
|
||||
SimpleSpiceCursor *ptr_define;
|
||||
SimpleSpiceCursor *ptr_move;
|
||||
int16_t ptr_x, ptr_y;
|
||||
int16_t hot_x, hot_y;
|
||||
|
||||
/* cursor (with qxl): qxl local renderer -> displaychangelistener */
|
||||
QEMUCursor *cursor;
|
||||
int mouse_x, mouse_y;
|
||||
QEMUBH *cursor_bh;
|
||||
|
||||
#ifdef HAVE_SPICE_GL
|
||||
/* opengl rendering */
|
||||
QEMUBH *gl_unblock_bh;
|
||||
QEMUTimer *gl_unblock_timer;
|
||||
QemuGLShader *gls;
|
||||
GLuint gl_surface_mem_obj;
|
||||
int gl_updates;
|
||||
bool have_scanout;
|
||||
bool have_surface;
|
||||
|
||||
QemuDmaBuf *guest_dmabuf;
|
||||
bool guest_dmabuf_refresh;
|
||||
bool render_cursor;
|
||||
|
||||
egl_fb guest_fb;
|
||||
egl_fb blit_fb;
|
||||
egl_fb cursor_fb;
|
||||
bool backing_y_0_top;
|
||||
bool blit_scanout_texture;
|
||||
bool new_scanout_texture;
|
||||
bool have_hot;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct SimpleSpiceUpdate {
|
||||
QXLDrawable drawable;
|
||||
QXLImage image;
|
||||
QXLCommandExt ext;
|
||||
uint8_t *bitmap;
|
||||
QTAILQ_ENTRY(SimpleSpiceUpdate) next;
|
||||
};
|
||||
|
||||
struct SimpleSpiceCursor {
|
||||
QXLCursorCmd cmd;
|
||||
QXLCommandExt ext;
|
||||
QXLCursor cursor;
|
||||
};
|
||||
|
||||
extern bool spice_opengl;
|
||||
extern bool spice_remote_client;
|
||||
extern int spice_max_refresh_rate;
|
||||
|
||||
int qemu_spice_rect_is_empty(const QXLRect* r);
|
||||
void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);
|
||||
|
||||
void qemu_spice_destroy_update(SimpleSpiceDisplay *sdpy, SimpleSpiceUpdate *update);
|
||||
void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd);
|
||||
void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd);
|
||||
void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd);
|
||||
void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd);
|
||||
|
||||
void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
|
||||
int x, int y, int w, int h);
|
||||
void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
|
||||
DisplaySurface *surface);
|
||||
void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd);
|
||||
void qemu_spice_cursor_refresh_bh(void *opaque);
|
||||
|
||||
void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot,
|
||||
qxl_async_io async);
|
||||
void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid,
|
||||
uint32_t sid);
|
||||
void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
|
||||
QXLDevSurfaceCreate *surface,
|
||||
qxl_async_io async);
|
||||
void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd,
|
||||
uint32_t id, qxl_async_io async);
|
||||
void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
|
||||
void qemu_spice_display_start(void);
|
||||
void qemu_spice_display_stop(void);
|
||||
int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
* QEMU UI Console
|
||||
*/
|
||||
#ifndef SURFACE_H
|
||||
#define SURFACE_H
|
||||
|
||||
#include "ui/qemu-pixman.h"
|
||||
|
||||
#ifdef CONFIG_OPENGL
|
||||
# include "ui/shader.h"
|
||||
#endif
|
||||
|
||||
#define QEMU_ALLOCATED_FLAG 0x01
|
||||
#define QEMU_PLACEHOLDER_FLAG 0x02
|
||||
|
||||
typedef struct DisplaySurface {
|
||||
pixman_image_t *image;
|
||||
uint8_t flags;
|
||||
#ifdef CONFIG_OPENGL
|
||||
uint32_t texture;
|
||||
#endif
|
||||
qemu_pixman_shareable share_handle;
|
||||
uint32_t share_handle_offset;
|
||||
} DisplaySurface;
|
||||
|
||||
DisplaySurface *qemu_create_displaysurface_from(int width, int height,
|
||||
pixman_format_code_t format,
|
||||
int linesize, uint8_t *data);
|
||||
DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image);
|
||||
DisplaySurface *qemu_create_placeholder_surface(int w, int h,
|
||||
const char *msg);
|
||||
|
||||
void qemu_displaysurface_set_share_handle(DisplaySurface *surface,
|
||||
qemu_pixman_shareable handle,
|
||||
uint32_t offset);
|
||||
|
||||
DisplaySurface *qemu_create_displaysurface(int width, int height);
|
||||
void qemu_free_displaysurface(DisplaySurface *surface);
|
||||
|
||||
static inline int surface_is_allocated(DisplaySurface *surface)
|
||||
{
|
||||
return surface->flags & QEMU_ALLOCATED_FLAG;
|
||||
}
|
||||
|
||||
static inline int surface_is_placeholder(DisplaySurface *surface)
|
||||
{
|
||||
return surface->flags & QEMU_PLACEHOLDER_FLAG;
|
||||
}
|
||||
|
||||
static inline int surface_stride(DisplaySurface *s)
|
||||
{
|
||||
return pixman_image_get_stride(s->image);
|
||||
}
|
||||
|
||||
static inline void *surface_data(DisplaySurface *s)
|
||||
{
|
||||
return pixman_image_get_data(s->image);
|
||||
}
|
||||
|
||||
static inline int surface_width(DisplaySurface *s)
|
||||
{
|
||||
return pixman_image_get_width(s->image);
|
||||
}
|
||||
|
||||
static inline int surface_height(DisplaySurface *s)
|
||||
{
|
||||
return pixman_image_get_height(s->image);
|
||||
}
|
||||
|
||||
static inline pixman_format_code_t surface_format(DisplaySurface *s)
|
||||
{
|
||||
return pixman_image_get_format(s->image);
|
||||
}
|
||||
|
||||
static inline int surface_bits_per_pixel(DisplaySurface *s)
|
||||
{
|
||||
int bits = PIXMAN_FORMAT_BPP(surface_format(s));
|
||||
return bits;
|
||||
}
|
||||
|
||||
static inline int surface_bytes_per_pixel(DisplaySurface *s)
|
||||
{
|
||||
int bits = PIXMAN_FORMAT_BPP(surface_format(s));
|
||||
return DIV_ROUND_UP(bits, 8);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#ifndef UI_WIN32_KBD_HOOK_H
|
||||
#define UI_WIN32_KBD_HOOK_H
|
||||
|
||||
void win32_kbd_set_window(void *hwnd);
|
||||
void win32_kbd_set_grab(bool grab);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user