diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2024-10-08 16:50:27 +0400 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2024-10-14 17:34:09 +0400 |
commit | 1ff788db9781615be745671ebdb2eb82c137c5b8 (patch) | |
tree | 85b092cc9ac20e344f99259a81bc2741740317f3 /include | |
parent | 5f899c34af1dbb0f621287faf9bcfb60fa237543 (diff) | |
download | qemu-1ff788db9781615be745671ebdb2eb82c137c5b8.zip qemu-1ff788db9781615be745671ebdb2eb82c137c5b8.tar.gz qemu-1ff788db9781615be745671ebdb2eb82c137c5b8.tar.bz2 |
ui: refactor using a common qemu_pixman_shareable
Use a common shareable type for win32 & unix, and helper functions.
This simplify the code as it avoids a lot of #ifdef'ery.
Note: if it helps review, commits could be reordered to introduce the
common type before introducing shareable memory for unix.
Suggested-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-ID: <20241008125028.1177932-19-marcandre.lureau@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/hw/virtio/virtio-gpu.h | 6 | ||||
-rw-r--r-- | include/ui/qemu-pixman.h | 24 | ||||
-rw-r--r-- | include/ui/surface.h | 20 |
3 files changed, 30 insertions, 20 deletions
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 7509d13..e343110 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -51,11 +51,7 @@ struct virtio_gpu_simple_resource { unsigned int iov_cnt; uint32_t scanout_bitmask; pixman_image_t *image; -#ifdef WIN32 - HANDLE handle; -#else - int shmfd; -#endif + qemu_pixman_shareable share_handle; uint64_t hostmem; uint64_t blob_size; diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h index a97f56d..193bc04 100644 --- a/include/ui/qemu-pixman.h +++ b/include/ui/qemu-pixman.h @@ -12,6 +12,8 @@ #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 @@ -97,7 +99,27 @@ void qemu_pixman_glyph_render(pixman_image_t *glyph, void qemu_pixman_image_unref(pixman_image_t *image); -void qemu_pixman_shared_image_destroy(pixman_image_t *image, void *data); +#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) diff --git a/include/ui/surface.h b/include/ui/surface.h index 37d03be..f16f7be 100644 --- a/include/ui/surface.h +++ b/include/ui/surface.h @@ -23,13 +23,8 @@ typedef struct DisplaySurface { GLenum gltype; GLuint texture; #endif -#ifdef WIN32 - HANDLE handle; - uint32_t handle_offset; -#else - int shmfd; - uint32_t shmfd_offset; -#endif + qemu_pixman_shareable share_handle; + uint32_t share_handle_offset; } DisplaySurface; PixelFormat qemu_default_pixelformat(int bpp); @@ -40,13 +35,10 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height, DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image); DisplaySurface *qemu_create_placeholder_surface(int w, int h, const char *msg); -#ifdef WIN32 -void qemu_displaysurface_win32_set_handle(DisplaySurface *surface, - HANDLE h, uint32_t offset); -#else -void qemu_displaysurface_set_shmfd(DisplaySurface *surface, - int shmfd, uint32_t offset); -#endif + +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); |