2 * QEMU DBus display console
4 * Copyright (c) 2021 Marc-André Lureau <marcandre.lureau@redhat.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu/osdep.h"
25 #include "qemu/error-report.h"
26 #include "qapi/error.h"
27 #include "sysemu/sysemu.h"
33 #include <gio/gunixfdlist.h>
41 #include "ui/shader.h"
42 #include "ui/egl-helpers.h"
43 #include "ui/egl-context.h"
47 static void dbus_gfx_switch(DisplayChangeListener
*dcl
,
48 struct DisplaySurface
*new_surface
);
56 struct _DBusDisplayListener
{
60 DBusDisplayConsole
*console
;
61 GDBusConnection
*conn
;
63 QemuDBusDisplay1Listener
*proxy
;
66 /* Keep track of the damage region */
67 pixman_region32_t gl_damage
;
70 DisplayChangeListener dcl
;
72 enum share_kind ds_share
;
78 QemuDBusDisplay1ListenerWin32Map
*map_proxy
;
79 QemuDBusDisplay1ListenerWin32D3d11
*d3d11_proxy
;
81 ID3D11Texture2D
*d3d_texture
;
88 G_DEFINE_TYPE(DBusDisplayListener
, dbus_display_listener
, G_TYPE_OBJECT
)
90 static void dbus_gfx_update(DisplayChangeListener
*dcl
,
91 int x
, int y
, int w
, int h
);
94 static void dbus_scanout_disable(DisplayChangeListener
*dcl
)
96 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
98 qemu_dbus_display1_listener_call_disable(
99 ddl
->proxy
, G_DBUS_CALL_FLAGS_NONE
, -1, NULL
, NULL
, NULL
);
103 static bool d3d_texture2d_share(ID3D11Texture2D
*d3d_texture
,
104 HANDLE
*handle
, Error
**errp
)
106 IDXGIResource1
*dxgiResource
= NULL
;
109 hr
= d3d_texture
->lpVtbl
->QueryInterface(d3d_texture
,
111 (void **)&dxgiResource
);
116 hr
= dxgiResource
->lpVtbl
->CreateSharedHandle(
119 DXGI_SHARED_RESOURCE_READ
| DXGI_SHARED_RESOURCE_WRITE
,
124 dxgiResource
->lpVtbl
->Release(dxgiResource
);
131 error_setg_win32(errp
, GetLastError(), "failed to create shared handle");
135 static bool d3d_texture2d_acquire0(ID3D11Texture2D
*d3d_texture
, Error
**errp
)
137 IDXGIKeyedMutex
*dxgiMutex
= NULL
;
140 hr
= d3d_texture
->lpVtbl
->QueryInterface(d3d_texture
,
141 &IID_IDXGIKeyedMutex
,
142 (void **)&dxgiMutex
);
147 hr
= dxgiMutex
->lpVtbl
->AcquireSync(dxgiMutex
, 0, INFINITE
);
149 dxgiMutex
->lpVtbl
->Release(dxgiMutex
);
156 error_setg_win32(errp
, GetLastError(), "failed to acquire texture mutex");
160 static bool d3d_texture2d_release0(ID3D11Texture2D
*d3d_texture
, Error
**errp
)
162 IDXGIKeyedMutex
*dxgiMutex
= NULL
;
165 hr
= d3d_texture
->lpVtbl
->QueryInterface(d3d_texture
,
166 &IID_IDXGIKeyedMutex
,
167 (void **)&dxgiMutex
);
172 hr
= dxgiMutex
->lpVtbl
->ReleaseSync(dxgiMutex
, 0);
174 dxgiMutex
->lpVtbl
->Release(dxgiMutex
);
181 error_setg_win32(errp
, GetLastError(), "failed to release texture mutex");
186 #if defined(CONFIG_GBM) || defined(WIN32)
187 static void dbus_update_gl_cb(GObject
*source_object
,
191 g_autoptr(GError
) err
= NULL
;
192 DBusDisplayListener
*ddl
= user_data
;
196 success
= qemu_dbus_display1_listener_call_update_dmabuf_finish(
197 ddl
->proxy
, res
, &err
);
201 success
= qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d_finish(
202 ddl
->d3d11_proxy
, res
, &err
);
203 d3d_texture2d_acquire0(ddl
->d3d_texture
, &error_warn
);
207 error_report("Failed to call update: %s", err
->message
);
210 graphic_hw_gl_block(ddl
->dcl
.con
, false);
215 static void dbus_call_update_gl(DisplayChangeListener
*dcl
,
216 int x
, int y
, int w
, int h
)
218 #if defined(CONFIG_GBM) || defined(WIN32)
219 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
222 trace_dbus_update_gl(x
, y
, w
, h
);
226 graphic_hw_gl_block(ddl
->dcl
.con
, true);
227 qemu_dbus_display1_listener_call_update_dmabuf(ddl
->proxy
,
229 G_DBUS_CALL_FLAGS_NONE
,
230 DBUS_DEFAULT_TIMEOUT
, NULL
,
236 switch (ddl
->ds_share
) {
237 case SHARE_KIND_MAPPED
:
238 egl_fb_read_rect(ddl
->ds
, &ddl
->fb
, x
, y
, w
, h
);
239 dbus_gfx_update(dcl
, x
, y
, w
, h
);
241 case SHARE_KIND_D3DTEX
: {
243 assert(ddl
->d3d_texture
);
245 graphic_hw_gl_block(ddl
->dcl
.con
, true);
246 if (!d3d_texture2d_release0(ddl
->d3d_texture
, &err
)) {
247 error_report_err(err
);
250 qemu_dbus_display1_listener_win32_d3d11_call_update_texture2d(
253 G_DBUS_CALL_FLAGS_NONE
,
254 DBUS_DEFAULT_TIMEOUT
, NULL
,
266 static void dbus_scanout_dmabuf(DisplayChangeListener
*dcl
,
269 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
270 g_autoptr(GError
) err
= NULL
;
271 g_autoptr(GUnixFDList
) fd_list
= NULL
;
273 fd_list
= g_unix_fd_list_new();
274 if (g_unix_fd_list_append(fd_list
, dmabuf
->fd
, &err
) != 0) {
275 error_report("Failed to setup dmabuf fdlist: %s", err
->message
);
279 /* FIXME: add missing x/y/w/h support */
280 qemu_dbus_display1_listener_call_scanout_dmabuf(
282 g_variant_new_handle(0),
289 G_DBUS_CALL_FLAGS_NONE
,
298 static bool dbus_scanout_map(DBusDisplayListener
*ddl
)
300 g_autoptr(GError
) err
= NULL
;
302 HANDLE target_handle
;
304 if (ddl
->ds_share
== SHARE_KIND_MAPPED
) {
308 if (!ddl
->can_share_map
|| !ddl
->ds
->handle
) {
312 success
= DuplicateHandle(
317 FILE_MAP_READ
| SECTION_QUERY
,
320 g_autofree
char *msg
= g_win32_error_message(GetLastError());
321 g_debug("Failed to DuplicateHandle: %s", msg
);
322 ddl
->can_share_map
= false;
326 if (!qemu_dbus_display1_listener_win32_map_call_scanout_map_sync(
328 GPOINTER_TO_UINT(target_handle
),
329 ddl
->ds
->handle_offset
,
330 surface_width(ddl
->ds
),
331 surface_height(ddl
->ds
),
332 surface_stride(ddl
->ds
),
333 surface_format(ddl
->ds
),
334 G_DBUS_CALL_FLAGS_NONE
,
335 DBUS_DEFAULT_TIMEOUT
,
338 g_debug("Failed to call ScanoutMap: %s", err
->message
);
339 ddl
->can_share_map
= false;
343 ddl
->ds_share
= SHARE_KIND_MAPPED
;
350 dbus_scanout_share_d3d_texture(
351 DBusDisplayListener
*ddl
,
352 ID3D11Texture2D
*tex
,
353 bool backing_y_0_top
,
354 uint32_t backing_width
,
355 uint32_t backing_height
,
356 uint32_t x
, uint32_t y
,
357 uint32_t w
, uint32_t h
)
361 HANDLE share_handle
, target_handle
;
363 if (!d3d_texture2d_release0(tex
, &err
)) {
364 error_report_err(err
);
368 if (!d3d_texture2d_share(tex
, &share_handle
, &err
)) {
369 error_report_err(err
);
373 success
= DuplicateHandle(
379 FALSE
, DUPLICATE_SAME_ACCESS
);
381 g_autofree
char *msg
= g_win32_error_message(GetLastError());
382 g_debug("Failed to DuplicateHandle: %s", msg
);
383 CloseHandle(share_handle
);
387 qemu_dbus_display1_listener_win32_d3d11_call_scanout_texture2d(
389 GPOINTER_TO_INT(target_handle
),
394 G_DBUS_CALL_FLAGS_NONE
,
398 CloseHandle(share_handle
);
400 if (!d3d_texture2d_acquire0(tex
, &err
)) {
401 error_report_err(err
);
405 ddl
->d3d_texture
= tex
;
406 ddl
->ds_share
= SHARE_KIND_D3DTEX
;
410 #endif /* CONFIG_OPENGL */
414 static void dbus_scanout_texture(DisplayChangeListener
*dcl
,
416 bool backing_y_0_top
,
417 uint32_t backing_width
,
418 uint32_t backing_height
,
419 uint32_t x
, uint32_t y
,
420 uint32_t w
, uint32_t h
,
423 trace_dbus_scanout_texture(tex_id
, backing_y_0_top
,
424 backing_width
, backing_height
, x
, y
, w
, h
);
426 QemuDmaBuf dmabuf
= {
429 .y0_top
= backing_y_0_top
,
432 .backing_width
= backing_width
,
433 .backing_height
= backing_height
,
437 dmabuf
.fd
= egl_get_fd_for_texture(
438 tex_id
, (EGLint
*)&dmabuf
.stride
,
439 (EGLint
*)&dmabuf
.fourcc
,
442 error_report("%s: failed to get fd for texture", __func__
);
446 dbus_scanout_dmabuf(dcl
, &dmabuf
);
451 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
453 /* there must be a matching gfx_switch before */
454 assert(surface_width(ddl
->ds
) == w
);
455 assert(surface_height(ddl
->ds
) == h
);
458 dbus_scanout_share_d3d_texture(ddl
, d3d_tex2d
, backing_y_0_top
,
459 backing_width
, backing_height
, x
, y
, w
, h
);
461 dbus_scanout_map(ddl
);
462 egl_fb_setup_for_tex(&ddl
->fb
, backing_width
, backing_height
, tex_id
, false);
468 static void dbus_cursor_dmabuf(DisplayChangeListener
*dcl
,
469 QemuDmaBuf
*dmabuf
, bool have_hot
,
470 uint32_t hot_x
, uint32_t hot_y
)
472 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
474 GVariant
*v_data
= NULL
;
475 egl_fb cursor_fb
= EGL_FB_INIT
;
478 qemu_dbus_display1_listener_call_mouse_set(
479 ddl
->proxy
, 0, 0, false,
480 G_DBUS_CALL_FLAGS_NONE
, -1, NULL
, NULL
, NULL
);
484 egl_dmabuf_import_texture(dmabuf
);
485 if (!dmabuf
->texture
) {
488 egl_fb_setup_for_tex(&cursor_fb
, dmabuf
->width
, dmabuf
->height
,
489 dmabuf
->texture
, false);
490 ds
= qemu_create_displaysurface(dmabuf
->width
, dmabuf
->height
);
491 egl_fb_read(ds
, &cursor_fb
);
493 v_data
= g_variant_new_from_data(
494 G_VARIANT_TYPE("ay"),
496 surface_width(ds
) * surface_height(ds
) * 4,
498 (GDestroyNotify
)qemu_free_displaysurface
,
500 qemu_dbus_display1_listener_call_cursor_define(
507 G_DBUS_CALL_FLAGS_NONE
,
514 static void dbus_release_dmabuf(DisplayChangeListener
*dcl
,
517 dbus_scanout_disable(dcl
);
521 static void dbus_gl_cursor_position(DisplayChangeListener
*dcl
,
522 uint32_t pos_x
, uint32_t pos_y
)
524 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
526 qemu_dbus_display1_listener_call_mouse_set(
527 ddl
->proxy
, pos_x
, pos_y
, true,
528 G_DBUS_CALL_FLAGS_NONE
, -1, NULL
, NULL
, NULL
);
531 static void dbus_scanout_update(DisplayChangeListener
*dcl
,
532 uint32_t x
, uint32_t y
,
533 uint32_t w
, uint32_t h
)
535 dbus_call_update_gl(dcl
, x
, y
, w
, h
);
538 static void dbus_gl_refresh(DisplayChangeListener
*dcl
)
540 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
542 graphic_hw_update(dcl
->con
);
544 if (!ddl
->ds
|| qemu_console_is_gl_blocked(ddl
->dcl
.con
)) {
548 int n_rects
= pixman_region32_n_rects(&ddl
->gl_damage
);
550 for (int i
= 0; i
< n_rects
; i
++) {
552 box
= pixman_region32_rectangles(&ddl
->gl_damage
, NULL
) + i
;
553 /* TODO: Add a UpdateList call to send multiple updates at once */
554 dbus_call_update_gl(dcl
, box
->x1
, box
->y1
,
555 box
->x2
- box
->x1
, box
->y2
- box
->y1
);
557 pixman_region32_clear(&ddl
->gl_damage
);
561 static void dbus_refresh(DisplayChangeListener
*dcl
)
563 graphic_hw_update(dcl
->con
);
567 static void dbus_gl_gfx_update(DisplayChangeListener
*dcl
,
568 int x
, int y
, int w
, int h
)
570 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
572 pixman_region32_t rect_region
;
573 pixman_region32_init_rect(&rect_region
, x
, y
, w
, h
);
574 pixman_region32_union(&ddl
->gl_damage
, &ddl
->gl_damage
, &rect_region
);
575 pixman_region32_fini(&rect_region
);
579 static void dbus_gfx_update(DisplayChangeListener
*dcl
,
580 int x
, int y
, int w
, int h
)
582 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
589 trace_dbus_update(x
, y
, w
, h
);
592 if (dbus_scanout_map(ddl
)) {
593 qemu_dbus_display1_listener_win32_map_call_update_map(
596 G_DBUS_CALL_FLAGS_NONE
,
597 DBUS_DEFAULT_TIMEOUT
, NULL
, NULL
, NULL
);
602 if (x
== 0 && y
== 0 && w
== surface_width(ddl
->ds
) && h
== surface_height(ddl
->ds
)) {
603 v_data
= g_variant_new_from_data(
604 G_VARIANT_TYPE("ay"),
605 surface_data(ddl
->ds
),
606 surface_stride(ddl
->ds
) * surface_height(ddl
->ds
),
608 (GDestroyNotify
)pixman_image_unref
,
609 pixman_image_ref(ddl
->ds
->image
));
610 qemu_dbus_display1_listener_call_scanout(
612 surface_width(ddl
->ds
),
613 surface_height(ddl
->ds
),
614 surface_stride(ddl
->ds
),
615 surface_format(ddl
->ds
),
617 G_DBUS_CALL_FLAGS_NONE
,
618 DBUS_DEFAULT_TIMEOUT
, NULL
, NULL
, NULL
);
622 /* make a copy, since gvariant only handles linear data */
623 stride
= w
* DIV_ROUND_UP(PIXMAN_FORMAT_BPP(surface_format(ddl
->ds
)), 8);
624 img
= pixman_image_create_bits(surface_format(ddl
->ds
),
626 pixman_image_composite(PIXMAN_OP_SRC
, ddl
->ds
->image
, NULL
, img
,
627 x
, y
, 0, 0, 0, 0, w
, h
);
629 v_data
= g_variant_new_from_data(
630 G_VARIANT_TYPE("ay"),
631 pixman_image_get_data(img
),
632 pixman_image_get_stride(img
) * h
,
634 (GDestroyNotify
)pixman_image_unref
,
636 qemu_dbus_display1_listener_call_update(ddl
->proxy
,
637 x
, y
, w
, h
, pixman_image_get_stride(img
), pixman_image_get_format(img
),
639 G_DBUS_CALL_FLAGS_NONE
,
640 DBUS_DEFAULT_TIMEOUT
, NULL
, NULL
, NULL
);
644 static void dbus_gl_gfx_switch(DisplayChangeListener
*dcl
,
645 struct DisplaySurface
*new_surface
)
647 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
649 trace_dbus_gl_gfx_switch(new_surface
);
651 ddl
->ds
= new_surface
;
652 ddl
->ds_share
= SHARE_KIND_NONE
;
654 int width
= surface_width(ddl
->ds
);
655 int height
= surface_height(ddl
->ds
);
657 /* TODO: lazy send dmabuf (there are unnecessary sent otherwise) */
658 dbus_scanout_texture(&ddl
->dcl
, ddl
->ds
->texture
, false,
659 width
, height
, 0, 0, width
, height
, NULL
);
664 static void dbus_gfx_switch(DisplayChangeListener
*dcl
,
665 struct DisplaySurface
*new_surface
)
667 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
669 ddl
->ds
= new_surface
;
670 ddl
->ds_share
= SHARE_KIND_NONE
;
673 static void dbus_mouse_set(DisplayChangeListener
*dcl
,
674 int x
, int y
, int on
)
676 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
678 qemu_dbus_display1_listener_call_mouse_set(
679 ddl
->proxy
, x
, y
, on
, G_DBUS_CALL_FLAGS_NONE
, -1, NULL
, NULL
, NULL
);
682 static void dbus_cursor_define(DisplayChangeListener
*dcl
,
685 DBusDisplayListener
*ddl
= container_of(dcl
, DBusDisplayListener
, dcl
);
686 GVariant
*v_data
= NULL
;
688 v_data
= g_variant_new_from_data(
689 G_VARIANT_TYPE("ay"),
691 c
->width
* c
->height
* 4,
693 (GDestroyNotify
)cursor_unref
,
696 qemu_dbus_display1_listener_call_cursor_define(
703 G_DBUS_CALL_FLAGS_NONE
,
711 const DisplayChangeListenerOps dbus_gl_dcl_ops
= {
712 .dpy_name
= "dbus-gl",
713 .dpy_gfx_update
= dbus_gl_gfx_update
,
714 .dpy_gfx_switch
= dbus_gl_gfx_switch
,
715 .dpy_gfx_check_format
= console_gl_check_format
,
716 .dpy_refresh
= dbus_gl_refresh
,
717 .dpy_mouse_set
= dbus_mouse_set
,
718 .dpy_cursor_define
= dbus_cursor_define
,
720 .dpy_gl_scanout_disable
= dbus_scanout_disable
,
721 .dpy_gl_scanout_texture
= dbus_scanout_texture
,
723 .dpy_gl_scanout_dmabuf
= dbus_scanout_dmabuf
,
724 .dpy_gl_cursor_dmabuf
= dbus_cursor_dmabuf
,
725 .dpy_gl_release_dmabuf
= dbus_release_dmabuf
,
727 .dpy_gl_cursor_position
= dbus_gl_cursor_position
,
728 .dpy_gl_update
= dbus_scanout_update
,
732 const DisplayChangeListenerOps dbus_dcl_ops
= {
734 .dpy_gfx_update
= dbus_gfx_update
,
735 .dpy_gfx_switch
= dbus_gfx_switch
,
736 .dpy_refresh
= dbus_refresh
,
737 .dpy_mouse_set
= dbus_mouse_set
,
738 .dpy_cursor_define
= dbus_cursor_define
,
742 dbus_display_listener_dispose(GObject
*object
)
744 DBusDisplayListener
*ddl
= DBUS_DISPLAY_LISTENER(object
);
746 unregister_displaychangelistener(&ddl
->dcl
);
747 g_clear_object(&ddl
->conn
);
748 g_clear_pointer(&ddl
->bus_name
, g_free
);
749 g_clear_object(&ddl
->proxy
);
751 g_clear_object(&ddl
->map_proxy
);
752 g_clear_object(&ddl
->d3d11_proxy
);
753 g_clear_pointer(&ddl
->peer_process
, CloseHandle
);
755 pixman_region32_fini(&ddl
->gl_damage
);
756 egl_fb_destroy(&ddl
->fb
);
760 G_OBJECT_CLASS(dbus_display_listener_parent_class
)->dispose(object
);
764 dbus_display_listener_constructed(GObject
*object
)
766 DBusDisplayListener
*ddl
= DBUS_DISPLAY_LISTENER(object
);
768 ddl
->dcl
.ops
= &dbus_dcl_ops
;
770 if (display_opengl
) {
771 ddl
->dcl
.ops
= &dbus_gl_dcl_ops
;
775 G_OBJECT_CLASS(dbus_display_listener_parent_class
)->constructed(object
);
779 dbus_display_listener_class_init(DBusDisplayListenerClass
*klass
)
781 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
783 object_class
->dispose
= dbus_display_listener_dispose
;
784 object_class
->constructed
= dbus_display_listener_constructed
;
788 dbus_display_listener_init(DBusDisplayListener
*ddl
)
791 pixman_region32_init(&ddl
->gl_damage
);
796 dbus_display_listener_get_bus_name(DBusDisplayListener
*ddl
)
798 return ddl
->bus_name
?: "p2p";
802 dbus_display_listener_get_console(DBusDisplayListener
*ddl
)
809 dbus_display_listener_implements(DBusDisplayListener
*ddl
, const char *iface
)
811 QemuDBusDisplay1Listener
*l
= QEMU_DBUS_DISPLAY1_LISTENER(ddl
->proxy
);
814 implements
= g_strv_contains(qemu_dbus_display1_listener_get_interfaces(l
), iface
);
816 g_debug("Display listener does not implement: `%s`", iface
);
823 dbus_display_listener_setup_peer_process(DBusDisplayListener
*ddl
)
825 g_autoptr(GError
) err
= NULL
;
826 GDBusConnection
*conn
;
829 g_autoptr(GCredentials
) creds
= NULL
;
832 if (ddl
->peer_process
) {
836 conn
= g_dbus_proxy_get_connection(G_DBUS_PROXY(ddl
->proxy
));
837 stream
= g_dbus_connection_get_stream(conn
);
839 if (!G_IS_UNIX_CONNECTION(stream
)) {
843 sock
= g_socket_connection_get_socket(G_SOCKET_CONNECTION(stream
));
844 creds
= g_socket_get_credentials(sock
, &err
);
847 g_debug("Failed to get peer credentials: %s", err
->message
);
851 pid
= g_credentials_get_native(creds
, G_CREDENTIALS_TYPE_WIN32_PID
);
854 g_debug("Failed to get peer PID");
858 ddl
->peer_process
= OpenProcess(
859 PROCESS_DUP_HANDLE
| PROCESS_QUERY_INFORMATION
,
862 if (!ddl
->peer_process
) {
863 g_autofree
char *msg
= g_win32_error_message(GetLastError());
864 g_debug("Failed to OpenProcess: %s", msg
);
873 dbus_display_listener_setup_d3d11(DBusDisplayListener
*ddl
)
876 g_autoptr(GError
) err
= NULL
;
878 if (!dbus_display_listener_implements(ddl
,
879 "org.qemu.Display1.Listener.Win32.D3d11")) {
883 if (!dbus_display_listener_setup_peer_process(ddl
)) {
888 qemu_dbus_display1_listener_win32_d3d11_proxy_new_sync(ddl
->conn
,
889 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START
,
891 "/org/qemu/Display1/Listener",
894 if (!ddl
->d3d11_proxy
) {
895 g_debug("Failed to setup win32 d3d11 proxy: %s", err
->message
);
902 dbus_display_listener_setup_shared_map(DBusDisplayListener
*ddl
)
905 g_autoptr(GError
) err
= NULL
;
907 if (!dbus_display_listener_implements(ddl
, "org.qemu.Display1.Listener.Win32.Map")) {
911 if (!dbus_display_listener_setup_peer_process(ddl
)) {
916 qemu_dbus_display1_listener_win32_map_proxy_new_sync(ddl
->conn
,
917 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START
,
919 "/org/qemu/Display1/Listener",
922 if (!ddl
->map_proxy
) {
923 g_debug("Failed to setup win32 map proxy: %s", err
->message
);
927 ddl
->can_share_map
= true;
931 DBusDisplayListener
*
932 dbus_display_listener_new(const char *bus_name
,
933 GDBusConnection
*conn
,
934 DBusDisplayConsole
*console
)
936 DBusDisplayListener
*ddl
;
938 g_autoptr(GError
) err
= NULL
;
940 ddl
= g_object_new(DBUS_DISPLAY_TYPE_LISTENER
, NULL
);
942 qemu_dbus_display1_listener_proxy_new_sync(conn
,
943 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START
,
945 "/org/qemu/Display1/Listener",
949 error_report("Failed to setup proxy: %s", err
->message
);
950 g_object_unref(conn
);
955 ddl
->bus_name
= g_strdup(bus_name
);
957 ddl
->console
= console
;
959 dbus_display_listener_setup_shared_map(ddl
);
960 dbus_display_listener_setup_d3d11(ddl
);
962 con
= qemu_console_lookup_by_index(dbus_display_console_get_index(console
));
965 register_displaychangelistener(&ddl
->dcl
);