2021-07-15 10:53:53 +03:00
|
|
|
/*
|
|
|
|
* QEMU DBus display console
|
|
|
|
*
|
|
|
|
* Copyright (c) 2021 Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
2023-02-10 14:19:31 +03:00
|
|
|
#include "qemu/error-report.h"
|
2023-06-06 14:56:58 +03:00
|
|
|
#include "qapi/error.h"
|
2021-07-15 10:53:53 +03:00
|
|
|
#include "sysemu/sysemu.h"
|
|
|
|
#include "dbus.h"
|
2023-06-06 14:56:40 +03:00
|
|
|
#ifdef G_OS_UNIX
|
2021-07-15 10:53:53 +03:00
|
|
|
#include <gio/gunixfdlist.h>
|
2023-06-06 14:56:40 +03:00
|
|
|
#endif
|
2023-06-06 14:56:58 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <d3d11.h>
|
|
|
|
#include <dxgi1_2.h>
|
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
|
2022-08-11 17:25:16 +03:00
|
|
|
#ifdef CONFIG_OPENGL
|
2021-07-15 10:53:53 +03:00
|
|
|
#include "ui/shader.h"
|
|
|
|
#include "ui/egl-helpers.h"
|
|
|
|
#include "ui/egl-context.h"
|
2023-08-30 12:38:37 +03:00
|
|
|
#include "ui/qemu-pixman.h"
|
2022-08-11 17:25:16 +03:00
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
#include "trace.h"
|
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
static void dbus_gfx_switch(DisplayChangeListener *dcl,
|
|
|
|
struct DisplaySurface *new_surface);
|
|
|
|
|
2023-06-06 14:56:58 +03:00
|
|
|
enum share_kind {
|
|
|
|
SHARE_KIND_NONE,
|
|
|
|
SHARE_KIND_MAPPED,
|
|
|
|
SHARE_KIND_D3DTEX,
|
|
|
|
};
|
|
|
|
|
2021-07-15 10:53:53 +03:00
|
|
|
struct _DBusDisplayListener {
|
|
|
|
GObject parent;
|
|
|
|
|
|
|
|
char *bus_name;
|
|
|
|
DBusDisplayConsole *console;
|
|
|
|
GDBusConnection *conn;
|
|
|
|
|
|
|
|
QemuDBusDisplay1Listener *proxy;
|
|
|
|
|
2023-08-30 12:38:37 +03:00
|
|
|
#ifdef CONFIG_PIXMAN
|
2023-08-14 15:58:02 +03:00
|
|
|
/* Keep track of the damage region */
|
|
|
|
pixman_region32_t gl_damage;
|
2023-08-30 12:38:37 +03:00
|
|
|
#else
|
|
|
|
int gl_damage;
|
2023-08-14 15:58:02 +03:00
|
|
|
#endif
|
|
|
|
|
2021-07-15 10:53:53 +03:00
|
|
|
DisplayChangeListener dcl;
|
|
|
|
DisplaySurface *ds;
|
2023-06-06 14:56:58 +03:00
|
|
|
enum share_kind ds_share;
|
|
|
|
|
2023-06-06 14:56:48 +03:00
|
|
|
bool ds_mapped;
|
|
|
|
bool can_share_map;
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
QemuDBusDisplay1ListenerWin32Map *map_proxy;
|
2023-06-06 14:56:58 +03:00
|
|
|
QemuDBusDisplay1ListenerWin32D3d11 *d3d11_proxy;
|
2023-06-06 14:56:48 +03:00
|
|
|
HANDLE peer_process;
|
2023-06-06 14:56:58 +03:00
|
|
|
ID3D11Texture2D *d3d_texture;
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
egl_fb fb;
|
|
|
|
#endif
|
2023-06-06 14:56:48 +03:00
|
|
|
#endif
|
2024-03-07 17:21:13 +03:00
|
|
|
|
|
|
|
guint dbus_filter;
|
|
|
|
guint32 out_serial_to_discard;
|
2021-07-15 10:53:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(DBusDisplayListener, dbus_display_listener, G_TYPE_OBJECT)
|
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
static void dbus_gfx_update(DisplayChangeListener *dcl,
|
|
|
|
int x, int y, int w, int h);
|
|
|
|
|
2024-03-07 17:21:13 +03:00
|
|
|
static void ddl_discard_pending_messages(DBusDisplayListener *ddl)
|
|
|
|
{
|
|
|
|
ddl->out_serial_to_discard = g_dbus_connection_get_last_serial(
|
|
|
|
g_dbus_proxy_get_connection(G_DBUS_PROXY(ddl->proxy)));
|
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_OPENGL
|
|
|
|
static void dbus_scanout_disable(DisplayChangeListener *dcl)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
|
|
|
|
qemu_dbus_display1_listener_call_disable(
|
|
|
|
ddl->proxy, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:58 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
static bool d3d_texture2d_share(ID3D11Texture2D *d3d_texture,
|
|
|
|
HANDLE *handle, Error **errp)
|
|
|
|
{
|
|
|
|
IDXGIResource1 *dxgiResource = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = d3d_texture->lpVtbl->QueryInterface(d3d_texture,
|
|
|
|
&IID_IDXGIResource1,
|
|
|
|
(void **)&dxgiResource);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = dxgiResource->lpVtbl->CreateSharedHandle(
|
|
|
|
dxgiResource,
|
|
|
|
NULL,
|
|
|
|
DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE,
|
|
|
|
NULL,
|
|
|
|
handle
|
|
|
|
);
|
|
|
|
|
|
|
|
dxgiResource->lpVtbl->Release(dxgiResource);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
error_setg_win32(errp, GetLastError(), "failed to create shared handle");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d_texture2d_acquire0(ID3D11Texture2D *d3d_texture, Error **errp)
|
|
|
|
{
|
|
|
|
IDXGIKeyedMutex *dxgiMutex = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = d3d_texture->lpVtbl->QueryInterface(d3d_texture,
|
|
|
|
&IID_IDXGIKeyedMutex,
|
|
|
|
(void **)&dxgiMutex);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = dxgiMutex->lpVtbl->AcquireSync(dxgiMutex, 0, INFINITE);
|
|
|
|
|
|
|
|
dxgiMutex->lpVtbl->Release(dxgiMutex);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
error_setg_win32(errp, GetLastError(), "failed to acquire texture mutex");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool d3d_texture2d_release0(ID3D11Texture2D *d3d_texture, Error **errp)
|
|
|
|
{
|
|
|
|
IDXGIKeyedMutex *dxgiMutex = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = d3d_texture->lpVtbl->QueryInterface(d3d_texture,
|
|
|
|
&IID_IDXGIKeyedMutex,
|
|
|
|
(void **)&dxgiMutex);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = dxgiMutex->lpVtbl->ReleaseSync(dxgiMutex, 0);
|
|
|
|
|
|
|
|
dxgiMutex->lpVtbl->Release(dxgiMutex);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
error_setg_win32(errp, GetLastError(), "failed to release texture mutex");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif /* WIN32 */
|
|
|
|
|
2023-06-30 20:38:06 +03:00
|
|
|
#if defined(CONFIG_GBM) || defined(WIN32)
|
2021-07-15 10:53:53 +03:00
|
|
|
static void dbus_update_gl_cb(GObject *source_object,
|
2023-06-06 14:56:58 +03:00
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
2021-07-15 10:53:53 +03:00
|
|
|
{
|
|
|
|
g_autoptr(GError) err = NULL;
|
|
|
|
DBusDisplayListener *ddl = user_data;
|
2023-06-06 14:56:58 +03:00
|
|
|
bool success;
|
|
|
|
|
|
|
|
#ifdef CONFIG_GBM
|
|
|
|
success = qemu_dbus_display1_listener_call_update_dmabuf_finish(
|
|
|
|
ddl->proxy, res, &err);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
success = qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d_finish(
|
|
|
|
ddl->d3d11_proxy, res, &err);
|
|
|
|
d3d_texture2d_acquire0(ddl->d3d_texture, &error_warn);
|
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
|
2023-06-06 14:56:58 +03:00
|
|
|
if (!success) {
|
2021-07-15 10:53:53 +03:00
|
|
|
error_report("Failed to call update: %s", err->message);
|
|
|
|
}
|
|
|
|
|
|
|
|
graphic_hw_gl_block(ddl->dcl.con, false);
|
|
|
|
g_object_unref(ddl);
|
|
|
|
}
|
2023-06-30 20:38:06 +03:00
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
static void dbus_call_update_gl(DisplayChangeListener *dcl,
|
2021-07-15 10:53:53 +03:00
|
|
|
int x, int y, int w, int h)
|
|
|
|
{
|
2023-06-30 20:38:06 +03:00
|
|
|
#if defined(CONFIG_GBM) || defined(WIN32)
|
2023-06-06 14:56:52 +03:00
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
2023-06-30 20:38:06 +03:00
|
|
|
#endif
|
2023-06-06 14:56:52 +03:00
|
|
|
|
2023-06-06 14:56:53 +03:00
|
|
|
trace_dbus_update_gl(x, y, w, h);
|
|
|
|
|
2021-07-15 10:53:53 +03:00
|
|
|
glFlush();
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_GBM
|
|
|
|
graphic_hw_gl_block(ddl->dcl.con, true);
|
2021-07-15 10:53:53 +03:00
|
|
|
qemu_dbus_display1_listener_call_update_dmabuf(ddl->proxy,
|
|
|
|
x, y, w, h,
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
DBUS_DEFAULT_TIMEOUT, NULL,
|
|
|
|
dbus_update_gl_cb,
|
|
|
|
g_object_ref(ddl));
|
2023-06-06 14:56:52 +03:00
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef WIN32
|
2023-06-06 14:56:58 +03:00
|
|
|
switch (ddl->ds_share) {
|
|
|
|
case SHARE_KIND_MAPPED:
|
|
|
|
egl_fb_read_rect(ddl->ds, &ddl->fb, x, y, w, h);
|
|
|
|
dbus_gfx_update(dcl, x, y, w, h);
|
|
|
|
break;
|
2023-07-26 18:12:21 +03:00
|
|
|
case SHARE_KIND_D3DTEX: {
|
2023-06-06 14:56:58 +03:00
|
|
|
Error *err = NULL;
|
|
|
|
assert(ddl->d3d_texture);
|
|
|
|
|
|
|
|
graphic_hw_gl_block(ddl->dcl.con, true);
|
|
|
|
if (!d3d_texture2d_release0(ddl->d3d_texture, &err)) {
|
|
|
|
error_report_err(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d(
|
|
|
|
ddl->d3d11_proxy,
|
|
|
|
x, y, w, h,
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
DBUS_DEFAULT_TIMEOUT, NULL,
|
|
|
|
dbus_update_gl_cb,
|
|
|
|
g_object_ref(ddl));
|
|
|
|
break;
|
2023-07-26 18:12:21 +03:00
|
|
|
}
|
2023-06-06 14:56:58 +03:00
|
|
|
default:
|
|
|
|
g_warn_if_reached();
|
|
|
|
}
|
2023-06-06 14:56:52 +03:00
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_GBM
|
2021-07-15 10:53:53 +03:00
|
|
|
static void dbus_scanout_dmabuf(DisplayChangeListener *dcl,
|
|
|
|
QemuDmaBuf *dmabuf)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
g_autoptr(GError) err = NULL;
|
|
|
|
g_autoptr(GUnixFDList) fd_list = NULL;
|
2024-05-08 20:54:00 +03:00
|
|
|
int fd;
|
|
|
|
uint32_t width, height, stride, fourcc;
|
|
|
|
uint64_t modifier;
|
|
|
|
bool y0_top;
|
2021-07-15 10:53:53 +03:00
|
|
|
|
2024-05-08 20:54:00 +03:00
|
|
|
fd = qemu_dmabuf_get_fd(dmabuf);
|
2021-07-15 10:53:53 +03:00
|
|
|
fd_list = g_unix_fd_list_new();
|
2024-05-08 20:54:00 +03:00
|
|
|
if (g_unix_fd_list_append(fd_list, fd, &err) != 0) {
|
2021-07-15 10:53:53 +03:00
|
|
|
error_report("Failed to setup dmabuf fdlist: %s", err->message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-07 17:21:13 +03:00
|
|
|
ddl_discard_pending_messages(ddl);
|
|
|
|
|
2024-05-08 20:54:00 +03:00
|
|
|
width = qemu_dmabuf_get_width(dmabuf);
|
|
|
|
height = qemu_dmabuf_get_height(dmabuf);
|
|
|
|
stride = qemu_dmabuf_get_stride(dmabuf);
|
|
|
|
fourcc = qemu_dmabuf_get_fourcc(dmabuf);
|
|
|
|
modifier = qemu_dmabuf_get_modifier(dmabuf);
|
|
|
|
y0_top = qemu_dmabuf_get_y0_top(dmabuf);
|
|
|
|
|
2023-05-15 16:25:36 +03:00
|
|
|
/* FIXME: add missing x/y/w/h support */
|
2021-07-15 10:53:53 +03:00
|
|
|
qemu_dbus_display1_listener_call_scanout_dmabuf(
|
2024-05-08 20:54:00 +03:00
|
|
|
ddl->proxy, g_variant_new_handle(0),
|
|
|
|
width, height, stride, fourcc, modifier,
|
|
|
|
y0_top, G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
-1, fd_list, NULL, NULL, NULL);
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
2023-06-06 14:56:52 +03:00
|
|
|
#endif /* GBM */
|
|
|
|
#endif /* OPENGL */
|
2023-06-06 14:56:48 +03:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
static bool dbus_scanout_map(DBusDisplayListener *ddl)
|
|
|
|
{
|
|
|
|
g_autoptr(GError) err = NULL;
|
|
|
|
BOOL success;
|
|
|
|
HANDLE target_handle;
|
|
|
|
|
2023-06-06 14:56:58 +03:00
|
|
|
if (ddl->ds_share == SHARE_KIND_MAPPED) {
|
2023-06-06 14:56:48 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ddl->can_share_map || !ddl->ds->handle) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = DuplicateHandle(
|
|
|
|
GetCurrentProcess(),
|
|
|
|
ddl->ds->handle,
|
|
|
|
ddl->peer_process,
|
|
|
|
&target_handle,
|
|
|
|
FILE_MAP_READ | SECTION_QUERY,
|
|
|
|
FALSE, 0);
|
|
|
|
if (!success) {
|
|
|
|
g_autofree char *msg = g_win32_error_message(GetLastError());
|
|
|
|
g_debug("Failed to DuplicateHandle: %s", msg);
|
|
|
|
ddl->can_share_map = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-03-07 17:21:13 +03:00
|
|
|
ddl_discard_pending_messages(ddl);
|
|
|
|
|
2023-06-06 14:56:48 +03:00
|
|
|
if (!qemu_dbus_display1_listener_win32_map_call_scanout_map_sync(
|
|
|
|
ddl->map_proxy,
|
|
|
|
GPOINTER_TO_UINT(target_handle),
|
|
|
|
ddl->ds->handle_offset,
|
|
|
|
surface_width(ddl->ds),
|
|
|
|
surface_height(ddl->ds),
|
|
|
|
surface_stride(ddl->ds),
|
|
|
|
surface_format(ddl->ds),
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
DBUS_DEFAULT_TIMEOUT,
|
|
|
|
NULL,
|
|
|
|
&err)) {
|
|
|
|
g_debug("Failed to call ScanoutMap: %s", err->message);
|
|
|
|
ddl->can_share_map = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:58 +03:00
|
|
|
ddl->ds_share = SHARE_KIND_MAPPED;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-07-25 14:25:40 +03:00
|
|
|
#ifdef CONFIG_OPENGL
|
2023-06-06 14:56:58 +03:00
|
|
|
static bool
|
|
|
|
dbus_scanout_share_d3d_texture(
|
|
|
|
DBusDisplayListener *ddl,
|
|
|
|
ID3D11Texture2D *tex,
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
Error *err = NULL;
|
|
|
|
BOOL success;
|
|
|
|
HANDLE share_handle, target_handle;
|
|
|
|
|
|
|
|
if (!d3d_texture2d_release0(tex, &err)) {
|
|
|
|
error_report_err(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d3d_texture2d_share(tex, &share_handle, &err)) {
|
|
|
|
error_report_err(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = DuplicateHandle(
|
|
|
|
GetCurrentProcess(),
|
|
|
|
share_handle,
|
|
|
|
ddl->peer_process,
|
|
|
|
&target_handle,
|
|
|
|
0,
|
|
|
|
FALSE, DUPLICATE_SAME_ACCESS);
|
|
|
|
if (!success) {
|
|
|
|
g_autofree char *msg = g_win32_error_message(GetLastError());
|
|
|
|
g_debug("Failed to DuplicateHandle: %s", msg);
|
|
|
|
CloseHandle(share_handle);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-03-07 17:21:13 +03:00
|
|
|
ddl_discard_pending_messages(ddl);
|
|
|
|
|
2023-06-06 14:56:58 +03:00
|
|
|
qemu_dbus_display1_listener_win32_d3d11_call_scanout_texture2d(
|
|
|
|
ddl->d3d11_proxy,
|
|
|
|
GPOINTER_TO_INT(target_handle),
|
|
|
|
backing_width,
|
|
|
|
backing_height,
|
|
|
|
backing_y_0_top,
|
|
|
|
x, y, w, h,
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
-1,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
|
|
|
CloseHandle(share_handle);
|
|
|
|
|
|
|
|
if (!d3d_texture2d_acquire0(tex, &err)) {
|
|
|
|
error_report_err(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ddl->d3d_texture = tex;
|
|
|
|
ddl->ds_share = SHARE_KIND_D3DTEX;
|
2023-06-06 14:56:48 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2023-07-25 14:25:40 +03:00
|
|
|
#endif /* CONFIG_OPENGL */
|
|
|
|
#endif /* WIN32 */
|
2021-07-15 10:53:53 +03:00
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_OPENGL
|
2021-07-15 10:53:53 +03:00
|
|
|
static void dbus_scanout_texture(DisplayChangeListener *dcl,
|
|
|
|
uint32_t tex_id,
|
|
|
|
bool backing_y_0_top,
|
|
|
|
uint32_t backing_width,
|
|
|
|
uint32_t backing_height,
|
|
|
|
uint32_t x, uint32_t y,
|
2023-06-06 14:56:56 +03:00
|
|
|
uint32_t w, uint32_t h,
|
|
|
|
void *d3d_tex2d)
|
2021-07-15 10:53:53 +03:00
|
|
|
{
|
2023-06-06 14:56:53 +03:00
|
|
|
trace_dbus_scanout_texture(tex_id, backing_y_0_top,
|
|
|
|
backing_width, backing_height, x, y, w, h);
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_GBM
|
2024-05-08 20:54:02 +03:00
|
|
|
g_autoptr(QemuDmaBuf) dmabuf = NULL;
|
|
|
|
int fd;
|
|
|
|
uint32_t stride, fourcc;
|
|
|
|
uint64_t modifier;
|
2021-07-15 10:53:53 +03:00
|
|
|
|
|
|
|
assert(tex_id);
|
2024-05-08 20:54:02 +03:00
|
|
|
fd = egl_get_fd_for_texture(tex_id, (EGLint *)&stride, (EGLint *)&fourcc,
|
|
|
|
&modifier);
|
|
|
|
if (fd < 0) {
|
2021-07-15 10:53:53 +03:00
|
|
|
error_report("%s: failed to get fd for texture", __func__);
|
|
|
|
return;
|
|
|
|
}
|
2024-05-08 20:54:02 +03:00
|
|
|
dmabuf = qemu_dmabuf_new(w, h, stride, x, y, backing_width,
|
|
|
|
backing_height, fourcc, modifier, fd,
|
|
|
|
false, backing_y_0_top);
|
2021-07-15 10:53:53 +03:00
|
|
|
|
2024-05-08 20:54:02 +03:00
|
|
|
dbus_scanout_dmabuf(dcl, dmabuf);
|
|
|
|
qemu_dmabuf_close(dmabuf);
|
2023-06-06 14:56:52 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
|
|
|
|
/* there must be a matching gfx_switch before */
|
|
|
|
assert(surface_width(ddl->ds) == w);
|
|
|
|
assert(surface_height(ddl->ds) == h);
|
2023-06-06 14:56:58 +03:00
|
|
|
|
|
|
|
if (d3d_tex2d) {
|
|
|
|
dbus_scanout_share_d3d_texture(ddl, d3d_tex2d, backing_y_0_top,
|
|
|
|
backing_width, backing_height, x, y, w, h);
|
|
|
|
} else {
|
|
|
|
dbus_scanout_map(ddl);
|
|
|
|
egl_fb_setup_for_tex(&ddl->fb, backing_width, backing_height, tex_id, false);
|
|
|
|
}
|
2023-06-06 14:56:52 +03:00
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_GBM
|
2021-07-15 10:53:53 +03:00
|
|
|
static void dbus_cursor_dmabuf(DisplayChangeListener *dcl,
|
|
|
|
QemuDmaBuf *dmabuf, bool have_hot,
|
|
|
|
uint32_t hot_x, uint32_t hot_y)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
DisplaySurface *ds;
|
|
|
|
GVariant *v_data = NULL;
|
2023-02-14 18:15:09 +03:00
|
|
|
egl_fb cursor_fb = EGL_FB_INIT;
|
2024-05-08 20:54:00 +03:00
|
|
|
uint32_t width, height, texture;
|
2021-07-15 10:53:53 +03:00
|
|
|
|
|
|
|
if (!dmabuf) {
|
|
|
|
qemu_dbus_display1_listener_call_mouse_set(
|
|
|
|
ddl->proxy, 0, 0, false,
|
|
|
|
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
egl_dmabuf_import_texture(dmabuf);
|
2024-05-08 20:54:00 +03:00
|
|
|
texture = qemu_dmabuf_get_texture(dmabuf);
|
|
|
|
if (!texture) {
|
2021-07-15 10:53:53 +03:00
|
|
|
return;
|
|
|
|
}
|
2024-05-08 20:54:00 +03:00
|
|
|
|
|
|
|
width = qemu_dmabuf_get_width(dmabuf);
|
|
|
|
height = qemu_dmabuf_get_height(dmabuf);
|
|
|
|
|
|
|
|
egl_fb_setup_for_tex(&cursor_fb, width, height, texture, false);
|
|
|
|
ds = qemu_create_displaysurface(width, height);
|
2021-07-15 10:53:53 +03:00
|
|
|
egl_fb_read(ds, &cursor_fb);
|
|
|
|
|
|
|
|
v_data = g_variant_new_from_data(
|
|
|
|
G_VARIANT_TYPE("ay"),
|
|
|
|
surface_data(ds),
|
|
|
|
surface_width(ds) * surface_height(ds) * 4,
|
|
|
|
TRUE,
|
|
|
|
(GDestroyNotify)qemu_free_displaysurface,
|
|
|
|
ds);
|
|
|
|
qemu_dbus_display1_listener_call_cursor_define(
|
|
|
|
ddl->proxy,
|
|
|
|
surface_width(ds),
|
|
|
|
surface_height(ds),
|
|
|
|
hot_x,
|
|
|
|
hot_y,
|
|
|
|
v_data,
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
static void dbus_release_dmabuf(DisplayChangeListener *dcl,
|
|
|
|
QemuDmaBuf *dmabuf)
|
|
|
|
{
|
|
|
|
dbus_scanout_disable(dcl);
|
|
|
|
}
|
|
|
|
#endif /* GBM */
|
|
|
|
|
|
|
|
static void dbus_gl_cursor_position(DisplayChangeListener *dcl,
|
2021-07-15 10:53:53 +03:00
|
|
|
uint32_t pos_x, uint32_t pos_y)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
|
|
|
|
qemu_dbus_display1_listener_call_mouse_set(
|
|
|
|
ddl->proxy, pos_x, pos_y, true,
|
|
|
|
G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dbus_scanout_update(DisplayChangeListener *dcl,
|
|
|
|
uint32_t x, uint32_t y,
|
|
|
|
uint32_t w, uint32_t h)
|
|
|
|
{
|
2023-06-06 14:56:52 +03:00
|
|
|
dbus_call_update_gl(dcl, x, y, w, h);
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dbus_gl_refresh(DisplayChangeListener *dcl)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
|
|
|
|
graphic_hw_update(dcl->con);
|
|
|
|
|
|
|
|
if (!ddl->ds || qemu_console_is_gl_blocked(ddl->dcl.con)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-30 12:38:37 +03:00
|
|
|
#ifdef CONFIG_PIXMAN
|
2023-08-14 15:58:02 +03:00
|
|
|
int n_rects = pixman_region32_n_rects(&ddl->gl_damage);
|
|
|
|
|
|
|
|
for (int i = 0; i < n_rects; i++) {
|
|
|
|
pixman_box32_t *box;
|
|
|
|
box = pixman_region32_rectangles(&ddl->gl_damage, NULL) + i;
|
|
|
|
/* TODO: Add a UpdateList call to send multiple updates at once */
|
|
|
|
dbus_call_update_gl(dcl, box->x1, box->y1,
|
|
|
|
box->x2 - box->x1, box->y2 - box->y1);
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
2023-08-14 15:58:02 +03:00
|
|
|
pixman_region32_clear(&ddl->gl_damage);
|
2023-08-30 12:38:37 +03:00
|
|
|
#else
|
|
|
|
if (ddl->gl_damage) {
|
|
|
|
dbus_call_update_gl(dcl, 0, 0,
|
|
|
|
surface_width(ddl->ds), surface_height(ddl->ds));
|
|
|
|
ddl->gl_damage = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
2023-06-06 14:56:52 +03:00
|
|
|
#endif /* OPENGL */
|
2021-07-15 10:53:53 +03:00
|
|
|
|
|
|
|
static void dbus_refresh(DisplayChangeListener *dcl)
|
|
|
|
{
|
|
|
|
graphic_hw_update(dcl->con);
|
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_OPENGL
|
2021-07-15 10:53:53 +03:00
|
|
|
static void dbus_gl_gfx_update(DisplayChangeListener *dcl,
|
|
|
|
int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
|
2023-08-30 12:38:37 +03:00
|
|
|
#ifdef CONFIG_PIXMAN
|
2023-08-14 15:58:02 +03:00
|
|
|
pixman_region32_t rect_region;
|
|
|
|
pixman_region32_init_rect(&rect_region, x, y, w, h);
|
|
|
|
pixman_region32_union(&ddl->gl_damage, &ddl->gl_damage, &rect_region);
|
|
|
|
pixman_region32_fini(&rect_region);
|
2023-08-30 12:38:37 +03:00
|
|
|
#else
|
|
|
|
ddl->gl_damage++;
|
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
2022-08-11 17:25:16 +03:00
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
|
2023-08-30 12:38:37 +03:00
|
|
|
static void dbus_gfx_update_sub(DBusDisplayListener *ddl,
|
|
|
|
int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
pixman_image_t *img;
|
|
|
|
size_t stride;
|
|
|
|
GVariant *v_data;
|
|
|
|
|
|
|
|
/* make a copy, since gvariant only handles linear data */
|
|
|
|
stride = w * DIV_ROUND_UP(PIXMAN_FORMAT_BPP(surface_format(ddl->ds)), 8);
|
|
|
|
img = pixman_image_create_bits(surface_format(ddl->ds),
|
|
|
|
w, h, NULL, stride);
|
|
|
|
#ifdef CONFIG_PIXMAN
|
|
|
|
pixman_image_composite(PIXMAN_OP_SRC, ddl->ds->image, NULL, img,
|
|
|
|
x, y, 0, 0, 0, 0, w, h);
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
uint8_t *src = (uint8_t *)pixman_image_get_data(ddl->ds->image);
|
|
|
|
uint8_t *dst = (uint8_t *)pixman_image_get_data(img);
|
|
|
|
int bp = PIXMAN_FORMAT_BPP(surface_format(ddl->ds)) / 8;
|
|
|
|
int hh;
|
|
|
|
|
|
|
|
for (hh = 0; hh < h; hh++) {
|
|
|
|
memcpy(&dst[stride * hh],
|
|
|
|
&src[surface_stride(ddl->ds) * (hh + y) + x * bp],
|
|
|
|
stride);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
v_data = g_variant_new_from_data(
|
|
|
|
G_VARIANT_TYPE("ay"),
|
|
|
|
pixman_image_get_data(img),
|
|
|
|
pixman_image_get_stride(img) * h,
|
|
|
|
TRUE,
|
|
|
|
(GDestroyNotify)pixman_image_unref,
|
|
|
|
img);
|
|
|
|
qemu_dbus_display1_listener_call_update(ddl->proxy,
|
|
|
|
x, y, w, h, pixman_image_get_stride(img), pixman_image_get_format(img),
|
|
|
|
v_data,
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
DBUS_DEFAULT_TIMEOUT, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2024-03-07 17:04:31 +03:00
|
|
|
static void ddl_scanout(DBusDisplayListener *ddl)
|
|
|
|
{
|
|
|
|
GVariant *v_data;
|
|
|
|
|
|
|
|
v_data = g_variant_new_from_data(
|
|
|
|
G_VARIANT_TYPE("ay"), surface_data(ddl->ds),
|
|
|
|
surface_stride(ddl->ds) * surface_height(ddl->ds), TRUE,
|
|
|
|
(GDestroyNotify)pixman_image_unref, pixman_image_ref(ddl->ds->image));
|
|
|
|
|
2024-03-07 17:21:13 +03:00
|
|
|
ddl_discard_pending_messages(ddl);
|
|
|
|
|
2024-03-07 17:04:31 +03:00
|
|
|
qemu_dbus_display1_listener_call_scanout(
|
|
|
|
ddl->proxy, surface_width(ddl->ds), surface_height(ddl->ds),
|
|
|
|
surface_stride(ddl->ds), surface_format(ddl->ds), v_data,
|
|
|
|
G_DBUS_CALL_FLAGS_NONE, DBUS_DEFAULT_TIMEOUT, NULL, NULL,
|
|
|
|
g_object_ref(ddl));
|
|
|
|
}
|
|
|
|
|
2021-07-15 10:53:53 +03:00
|
|
|
static void dbus_gfx_update(DisplayChangeListener *dcl,
|
|
|
|
int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
|
|
|
|
assert(ddl->ds);
|
|
|
|
|
|
|
|
trace_dbus_update(x, y, w, h);
|
|
|
|
|
2023-06-06 14:56:48 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
if (dbus_scanout_map(ddl)) {
|
|
|
|
qemu_dbus_display1_listener_win32_map_call_update_map(
|
|
|
|
ddl->map_proxy,
|
|
|
|
x, y, w, h,
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
DBUS_DEFAULT_TIMEOUT, NULL, NULL, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-20 22:57:00 +03:00
|
|
|
if (x == 0 && y == 0 && w == surface_width(ddl->ds) && h == surface_height(ddl->ds)) {
|
2024-03-07 17:04:31 +03:00
|
|
|
return ddl_scanout(ddl);
|
2022-02-20 22:57:00 +03:00
|
|
|
}
|
|
|
|
|
2023-08-30 12:38:37 +03:00
|
|
|
dbus_gfx_update_sub(ddl, x, y, w, h);
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_OPENGL
|
2021-07-15 10:53:53 +03:00
|
|
|
static void dbus_gl_gfx_switch(DisplayChangeListener *dcl,
|
|
|
|
struct DisplaySurface *new_surface)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
|
2023-06-06 14:56:53 +03:00
|
|
|
trace_dbus_gl_gfx_switch(new_surface);
|
|
|
|
|
2021-07-15 10:53:53 +03:00
|
|
|
ddl->ds = new_surface;
|
2023-06-06 14:56:58 +03:00
|
|
|
ddl->ds_share = SHARE_KIND_NONE;
|
2021-07-15 10:53:53 +03:00
|
|
|
if (ddl->ds) {
|
|
|
|
int width = surface_width(ddl->ds);
|
|
|
|
int height = surface_height(ddl->ds);
|
|
|
|
|
|
|
|
/* TODO: lazy send dmabuf (there are unnecessary sent otherwise) */
|
|
|
|
dbus_scanout_texture(&ddl->dcl, ddl->ds->texture, false,
|
2023-06-06 14:56:56 +03:00
|
|
|
width, height, 0, 0, width, height, NULL);
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
|
|
|
}
|
2022-08-11 17:25:16 +03:00
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
|
|
|
|
static void dbus_gfx_switch(DisplayChangeListener *dcl,
|
|
|
|
struct DisplaySurface *new_surface)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
|
|
|
|
ddl->ds = new_surface;
|
2023-06-06 14:56:58 +03:00
|
|
|
ddl->ds_share = SHARE_KIND_NONE;
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dbus_mouse_set(DisplayChangeListener *dcl,
|
|
|
|
int x, int y, int on)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
|
|
|
|
qemu_dbus_display1_listener_call_mouse_set(
|
|
|
|
ddl->proxy, x, y, on, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dbus_cursor_define(DisplayChangeListener *dcl,
|
|
|
|
QEMUCursor *c)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
|
|
|
|
GVariant *v_data = NULL;
|
|
|
|
|
|
|
|
v_data = g_variant_new_from_data(
|
|
|
|
G_VARIANT_TYPE("ay"),
|
|
|
|
c->data,
|
|
|
|
c->width * c->height * 4,
|
|
|
|
TRUE,
|
2023-01-17 14:07:02 +03:00
|
|
|
(GDestroyNotify)cursor_unref,
|
2023-01-17 14:10:13 +03:00
|
|
|
cursor_ref(c));
|
2021-07-15 10:53:53 +03:00
|
|
|
|
|
|
|
qemu_dbus_display1_listener_call_cursor_define(
|
|
|
|
ddl->proxy,
|
|
|
|
c->width,
|
|
|
|
c->height,
|
|
|
|
c->hot_x,
|
|
|
|
c->hot_y,
|
|
|
|
v_data,
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_OPENGL
|
2021-07-15 10:53:53 +03:00
|
|
|
const DisplayChangeListenerOps dbus_gl_dcl_ops = {
|
|
|
|
.dpy_name = "dbus-gl",
|
|
|
|
.dpy_gfx_update = dbus_gl_gfx_update,
|
|
|
|
.dpy_gfx_switch = dbus_gl_gfx_switch,
|
|
|
|
.dpy_gfx_check_format = console_gl_check_format,
|
|
|
|
.dpy_refresh = dbus_gl_refresh,
|
|
|
|
.dpy_mouse_set = dbus_mouse_set,
|
|
|
|
.dpy_cursor_define = dbus_cursor_define,
|
|
|
|
|
|
|
|
.dpy_gl_scanout_disable = dbus_scanout_disable,
|
|
|
|
.dpy_gl_scanout_texture = dbus_scanout_texture,
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_GBM
|
2021-07-15 10:53:53 +03:00
|
|
|
.dpy_gl_scanout_dmabuf = dbus_scanout_dmabuf,
|
|
|
|
.dpy_gl_cursor_dmabuf = dbus_cursor_dmabuf,
|
|
|
|
.dpy_gl_release_dmabuf = dbus_release_dmabuf,
|
2023-06-06 14:56:52 +03:00
|
|
|
#endif
|
|
|
|
.dpy_gl_cursor_position = dbus_gl_cursor_position,
|
2021-07-15 10:53:53 +03:00
|
|
|
.dpy_gl_update = dbus_scanout_update,
|
|
|
|
};
|
2022-08-11 17:25:16 +03:00
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
|
|
|
|
const DisplayChangeListenerOps dbus_dcl_ops = {
|
|
|
|
.dpy_name = "dbus",
|
|
|
|
.dpy_gfx_update = dbus_gfx_update,
|
|
|
|
.dpy_gfx_switch = dbus_gfx_switch,
|
|
|
|
.dpy_refresh = dbus_refresh,
|
|
|
|
.dpy_mouse_set = dbus_mouse_set,
|
|
|
|
.dpy_cursor_define = dbus_cursor_define,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
dbus_display_listener_dispose(GObject *object)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = DBUS_DISPLAY_LISTENER(object);
|
|
|
|
|
|
|
|
unregister_displaychangelistener(&ddl->dcl);
|
|
|
|
g_clear_object(&ddl->conn);
|
|
|
|
g_clear_pointer(&ddl->bus_name, g_free);
|
|
|
|
g_clear_object(&ddl->proxy);
|
2023-06-06 14:56:48 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
g_clear_object(&ddl->map_proxy);
|
2023-06-06 14:56:58 +03:00
|
|
|
g_clear_object(&ddl->d3d11_proxy);
|
2023-06-06 14:56:48 +03:00
|
|
|
g_clear_pointer(&ddl->peer_process, CloseHandle);
|
2023-08-30 12:38:37 +03:00
|
|
|
#ifdef CONFIG_PIXMAN
|
2023-08-14 15:58:02 +03:00
|
|
|
pixman_region32_fini(&ddl->gl_damage);
|
2023-08-30 12:38:37 +03:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_OPENGL
|
2023-06-06 14:56:52 +03:00
|
|
|
egl_fb_destroy(&ddl->fb);
|
|
|
|
#endif
|
2023-06-06 14:56:48 +03:00
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
|
|
|
|
G_OBJECT_CLASS(dbus_display_listener_parent_class)->dispose(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dbus_display_listener_constructed(GObject *object)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = DBUS_DISPLAY_LISTENER(object);
|
|
|
|
|
2022-08-11 17:25:16 +03:00
|
|
|
ddl->dcl.ops = &dbus_dcl_ops;
|
2023-06-06 14:56:52 +03:00
|
|
|
#ifdef CONFIG_OPENGL
|
2021-07-15 10:53:53 +03:00
|
|
|
if (display_opengl) {
|
|
|
|
ddl->dcl.ops = &dbus_gl_dcl_ops;
|
|
|
|
}
|
2022-08-11 17:25:16 +03:00
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
|
|
|
|
G_OBJECT_CLASS(dbus_display_listener_parent_class)->constructed(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dbus_display_listener_class_init(DBusDisplayListenerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
|
|
|
|
|
|
|
object_class->dispose = dbus_display_listener_dispose;
|
|
|
|
object_class->constructed = dbus_display_listener_constructed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dbus_display_listener_init(DBusDisplayListener *ddl)
|
|
|
|
{
|
2023-08-30 12:38:37 +03:00
|
|
|
#ifdef CONFIG_PIXMAN
|
2023-08-14 15:58:02 +03:00
|
|
|
pixman_region32_init(&ddl->gl_damage);
|
|
|
|
#endif
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
dbus_display_listener_get_bus_name(DBusDisplayListener *ddl)
|
|
|
|
{
|
2021-10-09 23:16:57 +03:00
|
|
|
return ddl->bus_name ?: "p2p";
|
2021-07-15 10:53:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DBusDisplayConsole *
|
|
|
|
dbus_display_listener_get_console(DBusDisplayListener *ddl)
|
|
|
|
{
|
|
|
|
return ddl->console;
|
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:48 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
static bool
|
|
|
|
dbus_display_listener_implements(DBusDisplayListener *ddl, const char *iface)
|
|
|
|
{
|
|
|
|
QemuDBusDisplay1Listener *l = QEMU_DBUS_DISPLAY1_LISTENER(ddl->proxy);
|
|
|
|
bool implements;
|
|
|
|
|
|
|
|
implements = g_strv_contains(qemu_dbus_display1_listener_get_interfaces(l), iface);
|
|
|
|
if (!implements) {
|
|
|
|
g_debug("Display listener does not implement: `%s`", iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
return implements;
|
|
|
|
}
|
|
|
|
|
2023-06-06 14:56:58 +03:00
|
|
|
static bool
|
|
|
|
dbus_display_listener_setup_peer_process(DBusDisplayListener *ddl)
|
2023-06-06 14:56:48 +03:00
|
|
|
{
|
|
|
|
g_autoptr(GError) err = NULL;
|
|
|
|
GDBusConnection *conn;
|
|
|
|
GIOStream *stream;
|
|
|
|
GSocket *sock;
|
|
|
|
g_autoptr(GCredentials) creds = NULL;
|
|
|
|
DWORD *pid;
|
|
|
|
|
2023-06-06 14:56:58 +03:00
|
|
|
if (ddl->peer_process) {
|
|
|
|
return true;
|
2023-06-06 14:56:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
conn = g_dbus_proxy_get_connection(G_DBUS_PROXY(ddl->proxy));
|
|
|
|
stream = g_dbus_connection_get_stream(conn);
|
|
|
|
|
|
|
|
if (!G_IS_UNIX_CONNECTION(stream)) {
|
2023-06-06 14:56:58 +03:00
|
|
|
return false;
|
2023-06-06 14:56:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sock = g_socket_connection_get_socket(G_SOCKET_CONNECTION(stream));
|
|
|
|
creds = g_socket_get_credentials(sock, &err);
|
|
|
|
|
|
|
|
if (!creds) {
|
|
|
|
g_debug("Failed to get peer credentials: %s", err->message);
|
2023-06-06 14:56:58 +03:00
|
|
|
return false;
|
2023-06-06 14:56:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pid = g_credentials_get_native(creds, G_CREDENTIALS_TYPE_WIN32_PID);
|
|
|
|
|
|
|
|
if (pid == NULL) {
|
|
|
|
g_debug("Failed to get peer PID");
|
2023-06-06 14:56:58 +03:00
|
|
|
return false;
|
2023-06-06 14:56:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ddl->peer_process = OpenProcess(
|
|
|
|
PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION,
|
|
|
|
false, *pid);
|
|
|
|
|
|
|
|
if (!ddl->peer_process) {
|
|
|
|
g_autofree char *msg = g_win32_error_message(GetLastError());
|
|
|
|
g_debug("Failed to OpenProcess: %s", msg);
|
2023-06-06 14:56:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
dbus_display_listener_setup_d3d11(DBusDisplayListener *ddl)
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
g_autoptr(GError) err = NULL;
|
|
|
|
|
|
|
|
if (!dbus_display_listener_implements(ddl,
|
|
|
|
"org.qemu.Display1.Listener.Win32.D3d11")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dbus_display_listener_setup_peer_process(ddl)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ddl->d3d11_proxy =
|
|
|
|
qemu_dbus_display1_listener_win32_d3d11_proxy_new_sync(ddl->conn,
|
|
|
|
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
|
|
|
NULL,
|
|
|
|
"/org/qemu/Display1/Listener",
|
|
|
|
NULL,
|
|
|
|
&err);
|
|
|
|
if (!ddl->d3d11_proxy) {
|
|
|
|
g_debug("Failed to setup win32 d3d11 proxy: %s", err->message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dbus_display_listener_setup_shared_map(DBusDisplayListener *ddl)
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
g_autoptr(GError) err = NULL;
|
|
|
|
|
|
|
|
if (!dbus_display_listener_implements(ddl, "org.qemu.Display1.Listener.Win32.Map")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dbus_display_listener_setup_peer_process(ddl)) {
|
2023-06-06 14:56:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ddl->map_proxy =
|
2023-06-06 14:56:58 +03:00
|
|
|
qemu_dbus_display1_listener_win32_map_proxy_new_sync(ddl->conn,
|
2023-06-06 14:56:48 +03:00
|
|
|
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
|
|
|
NULL,
|
|
|
|
"/org/qemu/Display1/Listener",
|
|
|
|
NULL,
|
|
|
|
&err);
|
|
|
|
if (!ddl->map_proxy) {
|
|
|
|
g_debug("Failed to setup win32 map proxy: %s", err->message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ddl->can_share_map = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-03-07 17:21:13 +03:00
|
|
|
static GDBusMessage *
|
|
|
|
dbus_filter(GDBusConnection *connection,
|
|
|
|
GDBusMessage *message,
|
|
|
|
gboolean incoming,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl = DBUS_DISPLAY_LISTENER(user_data);
|
|
|
|
guint32 serial;
|
|
|
|
|
|
|
|
if (incoming) {
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
serial = g_dbus_message_get_serial(message);
|
|
|
|
if (serial <= ddl->out_serial_to_discard) {
|
|
|
|
trace_dbus_filter(serial, ddl->out_serial_to_discard);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2021-07-15 10:53:53 +03:00
|
|
|
DBusDisplayListener *
|
|
|
|
dbus_display_listener_new(const char *bus_name,
|
|
|
|
GDBusConnection *conn,
|
|
|
|
DBusDisplayConsole *console)
|
|
|
|
{
|
|
|
|
DBusDisplayListener *ddl;
|
|
|
|
QemuConsole *con;
|
|
|
|
g_autoptr(GError) err = NULL;
|
|
|
|
|
|
|
|
ddl = g_object_new(DBUS_DISPLAY_TYPE_LISTENER, NULL);
|
|
|
|
ddl->proxy =
|
|
|
|
qemu_dbus_display1_listener_proxy_new_sync(conn,
|
|
|
|
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
|
|
|
NULL,
|
|
|
|
"/org/qemu/Display1/Listener",
|
|
|
|
NULL,
|
|
|
|
&err);
|
|
|
|
if (!ddl->proxy) {
|
|
|
|
error_report("Failed to setup proxy: %s", err->message);
|
|
|
|
g_object_unref(conn);
|
|
|
|
g_object_unref(ddl);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-03-07 17:21:13 +03:00
|
|
|
ddl->dbus_filter = g_dbus_connection_add_filter(conn, dbus_filter, g_object_ref(ddl), g_object_unref);
|
2021-07-15 10:53:53 +03:00
|
|
|
ddl->bus_name = g_strdup(bus_name);
|
|
|
|
ddl->conn = conn;
|
|
|
|
ddl->console = console;
|
|
|
|
|
2023-06-06 14:56:48 +03:00
|
|
|
dbus_display_listener_setup_shared_map(ddl);
|
2023-06-06 14:56:58 +03:00
|
|
|
dbus_display_listener_setup_d3d11(ddl);
|
2023-06-06 14:56:48 +03:00
|
|
|
|
2021-07-15 10:53:53 +03:00
|
|
|
con = qemu_console_lookup_by_index(dbus_display_console_get_index(console));
|
|
|
|
assert(con);
|
|
|
|
ddl->dcl.con = con;
|
|
|
|
register_displaychangelistener(&ddl->dcl);
|
|
|
|
|
|
|
|
return ddl;
|
|
|
|
}
|