* [PATCH v3 0/4] ui/cocoa: Add cursor composition
@ 2024-07-15 5:25 Akihiko Odaki
2024-07-15 5:25 ` [PATCH v3 1/4] ui/cocoa: Release CGColorSpace Akihiko Odaki
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Akihiko Odaki @ 2024-07-15 5:25 UTC (permalink / raw)
To: Paolo Bonzini, Marc-André Lureau, Daniel P. Berrangé,
Thomas Huth, Philippe Mathieu-Daudé, Peter Maydell,
Gerd Hoffmann, Dmitry Fleytman, Phil Dennis-Jordan
Cc: qemu-devel, Akihiko Odaki
Add accelerated cursor composition to ui/cocoa. This does not only
improve performance for display devices that exposes the capability to
the guest according to dpy_cursor_define_supported(), but fixes the
cursor display for devices that unconditionally expects the availability
of the capability (e.g., virtio-gpu).
The common pattern to implement accelerated cursor composition is to
replace the cursor and warp it so that the replaced cursor is shown at
the correct position on the guest display for relative pointer devices.
Unfortunately, ui/cocoa cannot do the same because warping the cursor
position interfers with the mouse input so it uses CALayer instead;
although it is not specialized for cursor composition, it still can
compose images with hardware acceleration.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
Changes in v3:
- Incorporated changes from:
"[PATCH v3 1/4] ui/cocoa: Typo fix in based-on patches"
- Link to v2: https://lore.kernel.org/r/20240627-cursor-v2-0-c3cd3ee35616@daynix.com
Changes in v2:
- Incorporated changes from:
https://lore.kernel.org/r/20240625134931.92279-2-phil@philjordan.eu
("[PATCH v2 1/2] ui/cocoa: Minor fixes to CALayer based cursors")
- Added patch "ui/cocoa: Release CGColorSpace"
- Added patch "ui/console: Convert mouse visibility parameter into bool"
- Noted that the problem with warping is relevant only for relative
pointer devices.
- Link to v1: https://lore.kernel.org/r/20240318-cursor-v1-0-0bbe6c382217@daynix.com
---
Akihiko Odaki (4):
ui/cocoa: Release CGColorSpace
ui/console: Convert mouse visibility parameter into bool
ui/cocoa: Add cursor composition
ui/console: Remove dpy_cursor_define_supported()
meson.build | 3 +-
include/ui/console.h | 5 +--
hw/display/ati.c | 2 +-
hw/display/qxl-render.c | 4 --
hw/display/virtio-gpu.c | 3 +-
hw/display/vmware_vga.c | 8 ++--
ui/console.c | 18 ++-------
ui/dbus-listener.c | 2 +-
ui/gtk.c | 2 +-
ui/sdl2.c | 4 +-
ui/spice-display.c | 11 ++---
ui/vnc.c | 2 +-
ui/cocoa.m | 104 +++++++++++++++++++++++++++++++++++++++++++++++-
13 files changed, 126 insertions(+), 42 deletions(-)
---
base-commit: 74abb45dac6979e7ff76172b7f0a24e869405184
change-id: 20240318-cursor-3491b1806582
Best regards,
--
Akihiko Odaki <akihiko.odaki@daynix.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 1/4] ui/cocoa: Release CGColorSpace
2024-07-15 5:25 [PATCH v3 0/4] ui/cocoa: Add cursor composition Akihiko Odaki
@ 2024-07-15 5:25 ` Akihiko Odaki
2024-07-15 6:57 ` Philippe Mathieu-Daudé
2024-07-15 5:25 ` [PATCH v3 2/4] ui/console: Convert mouse visibility parameter into bool Akihiko Odaki
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Akihiko Odaki @ 2024-07-15 5:25 UTC (permalink / raw)
To: Paolo Bonzini, Marc-André Lureau, Daniel P. Berrangé,
Thomas Huth, Philippe Mathieu-Daudé, Peter Maydell,
Gerd Hoffmann, Dmitry Fleytman, Phil Dennis-Jordan
Cc: qemu-devel, Akihiko Odaki
CGImageCreate | Apple Developer Documentation
https://developer.apple.com/documentation/coregraphics/1455149-cgimagecreate
> The color space is retained; on return, you may safely release it.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Tested-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
ui/cocoa.m | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 981615a8b925..908454a434c5 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -299,6 +299,7 @@ @interface QemuCocoaView : NSView
BOOL isMouseGrabbed;
BOOL isAbsoluteEnabled;
CFMachPortRef eventsTap;
+ CGColorSpaceRef colorspace;
}
- (void) switchSurface:(pixman_image_t *)image;
- (void) grabMouse;
@@ -360,6 +361,7 @@ - (id)initWithFrame:(NSRect)frameRect
[trackingArea release];
screen.width = frameRect.size.width;
screen.height = frameRect.size.height;
+ colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_14_0
[self setClipsToBounds:YES];
#endif
@@ -380,6 +382,7 @@ - (void) dealloc
CFRelease(eventsTap);
}
+ CGColorSpaceRelease(colorspace);
[super dealloc];
}
@@ -456,7 +459,7 @@ - (void) drawRect:(NSRect) rect
DIV_ROUND_UP(bitsPerPixel, 8) * 2, //bitsPerComponent
bitsPerPixel, //bitsPerPixel
stride, //bytesPerRow
- CGColorSpaceCreateWithName(kCGColorSpaceSRGB), //colorspace
+ colorspace, //colorspace
kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, //bitmapInfo
dataProviderRef, //provider
NULL, //decode
--
2.45.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 2/4] ui/console: Convert mouse visibility parameter into bool
2024-07-15 5:25 [PATCH v3 0/4] ui/cocoa: Add cursor composition Akihiko Odaki
2024-07-15 5:25 ` [PATCH v3 1/4] ui/cocoa: Release CGColorSpace Akihiko Odaki
@ 2024-07-15 5:25 ` Akihiko Odaki
2024-07-15 6:56 ` Philippe Mathieu-Daudé
2024-07-15 5:25 ` [PATCH v3 3/4] ui/cocoa: Add cursor composition Akihiko Odaki
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Akihiko Odaki @ 2024-07-15 5:25 UTC (permalink / raw)
To: Paolo Bonzini, Marc-André Lureau, Daniel P. Berrangé,
Thomas Huth, Philippe Mathieu-Daudé, Peter Maydell,
Gerd Hoffmann, Dmitry Fleytman, Phil Dennis-Jordan
Cc: qemu-devel, Akihiko Odaki
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Phil Dennis-Jordan <phil@philjordan.eu>
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
include/ui/console.h | 4 ++--
hw/display/ati.c | 2 +-
hw/display/virtio-gpu.c | 3 +--
hw/display/vmware_vga.c | 2 +-
ui/console.c | 5 +++--
ui/dbus-listener.c | 2 +-
ui/gtk.c | 2 +-
ui/sdl2.c | 4 ++--
ui/spice-display.c | 11 ++++++-----
ui/vnc.c | 2 +-
10 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/include/ui/console.h b/include/ui/console.h
index a208a68b8886..82b573e68082 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -233,7 +233,7 @@ typedef struct DisplayChangeListenerOps {
/* optional */
void (*dpy_mouse_set)(DisplayChangeListener *dcl,
- int x, int y, int on);
+ int x, int y, bool on);
/* optional */
void (*dpy_cursor_define)(DisplayChangeListener *dcl,
QEMUCursor *cursor);
@@ -322,7 +322,7 @@ void dpy_gfx_replace_surface(QemuConsole *con,
void dpy_text_cursor(QemuConsole *con, int x, int y);
void dpy_text_update(QemuConsole *con, int x, int y, int w, int h);
void dpy_text_resize(QemuConsole *con, int w, int h);
-void dpy_mouse_set(QemuConsole *con, int x, int y, int on);
+void dpy_mouse_set(QemuConsole *con, int x, int y, bool on);
void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor);
bool dpy_cursor_define_supported(QemuConsole *con);
bool dpy_gfx_check_format(QemuConsole *con,
diff --git a/hw/display/ati.c b/hw/display/ati.c
index 8d2501bd8210..b1f94f5b767d 100644
--- a/hw/display/ati.c
+++ b/hw/display/ati.c
@@ -742,7 +742,7 @@ static void ati_mm_write(void *opaque, hwaddr addr,
if (!s->cursor_guest_mode &&
(s->regs.crtc_gen_cntl & CRTC2_CUR_EN) && !(t & BIT(31))) {
dpy_mouse_set(s->vga.con, s->regs.cur_hv_pos >> 16,
- s->regs.cur_hv_pos & 0xffff, 1);
+ s->regs.cur_hv_pos & 0xffff, true);
}
break;
}
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index d60b1b2973af..3281842bfe1b 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -109,8 +109,7 @@ static void update_cursor(VirtIOGPU *g, struct virtio_gpu_update_cursor *cursor)
s->cursor.pos.x = cursor->pos.x;
s->cursor.pos.y = cursor->pos.y;
}
- dpy_mouse_set(s->con, cursor->pos.x, cursor->pos.y,
- cursor->resource_id ? 1 : 0);
+ dpy_mouse_set(s->con, cursor->pos.x, cursor->pos.y, cursor->resource_id);
}
struct virtio_gpu_simple_resource *
diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c
index 1c0f9d9a991d..512f224b9f58 100644
--- a/hw/display/vmware_vga.c
+++ b/hw/display/vmware_vga.c
@@ -1167,7 +1167,7 @@ static void vmsvga_reset(DeviceState *dev)
s->enable = 0;
s->config = 0;
s->svgaid = SVGA_ID;
- s->cursor.on = 0;
+ s->cursor.on = false;
s->redraw_fifo_last = 0;
s->syncing = 0;
diff --git a/ui/console.c b/ui/console.c
index 1b2cd0c7365d..0ec70cb50ce6 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -49,7 +49,8 @@ typedef struct QemuGraphicConsole {
uint32_t head;
QEMUCursor *cursor;
- int cursor_x, cursor_y, cursor_on;
+ int cursor_x, cursor_y;
+ bool cursor_on;
} QemuGraphicConsole;
typedef QemuConsoleClass QemuGraphicConsoleClass;
@@ -957,7 +958,7 @@ void dpy_text_resize(QemuConsole *con, int w, int h)
}
}
-void dpy_mouse_set(QemuConsole *c, int x, int y, int on)
+void dpy_mouse_set(QemuConsole *c, int x, int y, bool on)
{
QemuGraphicConsole *con = QEMU_GRAPHIC_CONSOLE(c);
DisplayState *s = c->ds;
diff --git a/ui/dbus-listener.c b/ui/dbus-listener.c
index 54900880433e..a54123acea7d 100644
--- a/ui/dbus-listener.c
+++ b/ui/dbus-listener.c
@@ -726,7 +726,7 @@ static void dbus_gfx_switch(DisplayChangeListener *dcl,
}
static void dbus_mouse_set(DisplayChangeListener *dcl,
- int x, int y, int on)
+ int x, int y, bool on)
{
DBusDisplayListener *ddl = container_of(dcl, DBusDisplayListener, dcl);
diff --git a/ui/gtk.c b/ui/gtk.c
index 93b13b7a30ff..bc29f7a1b4f7 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -446,7 +446,7 @@ static GdkDevice *gd_get_pointer(GdkDisplay *dpy)
}
static void gd_mouse_set(DisplayChangeListener *dcl,
- int x, int y, int visible)
+ int x, int y, bool visible)
{
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
GdkDisplay *dpy;
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 0a0eb5a42d58..98ed97437171 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -49,7 +49,7 @@ static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
static SDL_Cursor *sdl_cursor_normal;
static SDL_Cursor *sdl_cursor_hidden;
static int absolute_enabled;
-static int guest_cursor;
+static bool guest_cursor;
static int guest_x, guest_y;
static SDL_Cursor *guest_sprite;
static Notifier mouse_mode_notifier;
@@ -729,7 +729,7 @@ void sdl2_poll_events(struct sdl2_console *scon)
}
static void sdl_mouse_warp(DisplayChangeListener *dcl,
- int x, int y, int on)
+ int x, int y, bool on)
{
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 8a8472d0294e..c794ae06498b 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -254,7 +254,7 @@ static void qemu_spice_create_update(SimpleSpiceDisplay *ssd)
static SimpleSpiceCursor*
qemu_spice_create_cursor_update(SimpleSpiceDisplay *ssd,
QEMUCursor *c,
- int on)
+ bool on)
{
size_t size = c ? c->width * c->height * 4 : 0;
SimpleSpiceCursor *update;
@@ -448,7 +448,8 @@ void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
qemu_mutex_lock(&ssd->lock);
if (ssd->cursor) {
g_free(ssd->ptr_define);
- ssd->ptr_define = qemu_spice_create_cursor_update(ssd, ssd->cursor, 0);
+ ssd->ptr_define =
+ qemu_spice_create_cursor_update(ssd, ssd->cursor, false);
}
qemu_mutex_unlock(&ssd->lock);
}
@@ -476,7 +477,7 @@ void qemu_spice_cursor_refresh_bh(void *opaque)
ssd->mouse_x = -1;
ssd->mouse_y = -1;
qemu_mutex_unlock(&ssd->lock);
- dpy_mouse_set(ssd->dcl.con, x, y, 1);
+ dpy_mouse_set(ssd->dcl.con, x, y, true);
} else {
qemu_mutex_unlock(&ssd->lock);
}
@@ -747,7 +748,7 @@ static void display_refresh(DisplayChangeListener *dcl)
}
static void display_mouse_set(DisplayChangeListener *dcl,
- int x, int y, int on)
+ int x, int y, bool on)
{
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
@@ -774,7 +775,7 @@ static void display_mouse_define(DisplayChangeListener *dcl,
g_free(ssd->ptr_move);
ssd->ptr_move = NULL;
g_free(ssd->ptr_define);
- ssd->ptr_define = qemu_spice_create_cursor_update(ssd, c, 0);
+ ssd->ptr_define = qemu_spice_create_cursor_update(ssd, c, false);
qemu_mutex_unlock(&ssd->lock);
qemu_spice_wakeup(ssd);
}
diff --git a/ui/vnc.c b/ui/vnc.c
index dd530f04e579..dae5d51210be 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -981,7 +981,7 @@ int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
}
static void vnc_mouse_set(DisplayChangeListener *dcl,
- int x, int y, int visible)
+ int x, int y, bool visible)
{
/* can we ask the client(s) to move the pointer ??? */
}
--
2.45.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 3/4] ui/cocoa: Add cursor composition
2024-07-15 5:25 [PATCH v3 0/4] ui/cocoa: Add cursor composition Akihiko Odaki
2024-07-15 5:25 ` [PATCH v3 1/4] ui/cocoa: Release CGColorSpace Akihiko Odaki
2024-07-15 5:25 ` [PATCH v3 2/4] ui/console: Convert mouse visibility parameter into bool Akihiko Odaki
@ 2024-07-15 5:25 ` Akihiko Odaki
2024-07-15 5:25 ` [PATCH v3 4/4] ui/console: Remove dpy_cursor_define_supported() Akihiko Odaki
2024-07-16 17:55 ` [PATCH v3 0/4] ui/cocoa: Add cursor composition Philippe Mathieu-Daudé
4 siblings, 0 replies; 8+ messages in thread
From: Akihiko Odaki @ 2024-07-15 5:25 UTC (permalink / raw)
To: Paolo Bonzini, Marc-André Lureau, Daniel P. Berrangé,
Thomas Huth, Philippe Mathieu-Daudé, Peter Maydell,
Gerd Hoffmann, Dmitry Fleytman, Phil Dennis-Jordan
Cc: qemu-devel, Akihiko Odaki
Add accelerated cursor composition to ui/cocoa. This does not only
improve performance for display devices that exposes the capability to
the guest according to dpy_cursor_define_supported(), but fixes the
cursor display for devices that unconditionally expects the availability
of the capability (e.g., virtio-gpu).
The common pattern to implement accelerated cursor composition is to
replace the cursor and warp it so that the replaced cursor is shown at
the correct position on the guest display for relative pointer devices.
Unfortunately, ui/cocoa cannot do the same because warping the cursor
position interfers with the mouse input so it uses CALayer instead;
although it is not specialized for cursor composition, it still can
compose images with hardware acceleration.
Co-authored-by: Phil Dennis-Jordan <phil@philjordan.eu>
Tested-by: Phil Dennis-Jordan <phil@philjordan.eu>
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
meson.build | 3 +-
ui/cocoa.m | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+), 1 deletion(-)
diff --git a/meson.build b/meson.build
index 638660714455..59cc1fb8bcfc 100644
--- a/meson.build
+++ b/meson.build
@@ -1041,7 +1041,8 @@ if get_option('attr').allowed()
endif
endif
-cocoa = dependency('appleframeworks', modules: ['Cocoa', 'CoreVideo'],
+cocoa = dependency('appleframeworks',
+ modules: ['Cocoa', 'CoreVideo', 'QuartzCore'],
required: get_option('cocoa'))
vmnet = dependency('appleframeworks', modules: 'vmnet', required: get_option('vmnet'))
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 908454a434c5..0f52cf0de934 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -25,6 +25,7 @@
#include "qemu/osdep.h"
#import <Cocoa/Cocoa.h>
+#import <QuartzCore/QuartzCore.h>
#include <crt_externs.h>
#include "qemu/help-texts.h"
@@ -79,12 +80,16 @@ static void cocoa_switch(DisplayChangeListener *dcl,
DisplaySurface *surface);
static void cocoa_refresh(DisplayChangeListener *dcl);
+static void cocoa_mouse_set(DisplayChangeListener *dcl, int x, int y, bool on);
+static void cocoa_cursor_define(DisplayChangeListener *dcl, QEMUCursor *cursor);
static const DisplayChangeListenerOps dcl_ops = {
.dpy_name = "cocoa",
.dpy_gfx_update = cocoa_update,
.dpy_gfx_switch = cocoa_switch,
.dpy_refresh = cocoa_refresh,
+ .dpy_mouse_set = cocoa_mouse_set,
+ .dpy_cursor_define = cocoa_cursor_define,
};
static DisplayChangeListener dcl = {
.ops = &dcl_ops,
@@ -300,6 +305,11 @@ @interface QemuCocoaView : NSView
BOOL isAbsoluteEnabled;
CFMachPortRef eventsTap;
CGColorSpaceRef colorspace;
+ CALayer *cursorLayer;
+ QEMUCursor *cursor;
+ int mouseX;
+ int mouseY;
+ bool mouseOn;
}
- (void) switchSurface:(pixman_image_t *)image;
- (void) grabMouse;
@@ -365,6 +375,12 @@ - (id)initWithFrame:(NSRect)frameRect
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_14_0
[self setClipsToBounds:YES];
#endif
+ [self setWantsLayer:YES];
+ cursorLayer = [[CALayer alloc] init];
+ [cursorLayer setAnchorPoint:CGPointMake(0, 1)];
+ [cursorLayer setAutoresizingMask:kCALayerMaxXMargin |
+ kCALayerMinYMargin];
+ [[self layer] addSublayer:cursorLayer];
}
return self;
@@ -383,6 +399,8 @@ - (void) dealloc
}
CGColorSpaceRelease(colorspace);
+ [cursorLayer release];
+ cursor_unref(cursor);
[super dealloc];
}
@@ -426,6 +444,72 @@ - (void) unhideCursor
[NSCursor unhide];
}
+- (void)setMouseX:(int)x y:(int)y on:(bool)on
+{
+ CGPoint position;
+
+ mouseX = x;
+ mouseY = y;
+ mouseOn = on;
+
+ position.x = mouseX;
+ position.y = screen.height - mouseY;
+
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+ [cursorLayer setPosition:position];
+ [cursorLayer setHidden:!mouseOn];
+ [CATransaction commit];
+}
+
+- (void)setCursor:(QEMUCursor *)given_cursor
+{
+ CGDataProviderRef provider;
+ CGImageRef image;
+ CGRect bounds = CGRectZero;
+
+ cursor_unref(cursor);
+ cursor = given_cursor;
+
+ if (!cursor) {
+ return;
+ }
+
+ cursor_ref(cursor);
+
+ bounds.size.width = cursor->width;
+ bounds.size.height = cursor->height;
+
+ provider = CGDataProviderCreateWithData(
+ NULL,
+ cursor->data,
+ cursor->width * cursor->height * 4,
+ NULL
+ );
+
+ image = CGImageCreate(
+ cursor->width, //width
+ cursor->height, //height
+ 8, //bitsPerComponent
+ 32, //bitsPerPixel
+ cursor->width * 4, //bytesPerRow
+ colorspace, //colorspace
+ kCGBitmapByteOrder32Little | kCGImageAlphaFirst, //bitmapInfo
+ provider, //provider
+ NULL, //decode
+ 0, //interpolate
+ kCGRenderingIntentDefault //intent
+ );
+
+ CGDataProviderRelease(provider);
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+ [cursorLayer setBounds:bounds];
+ [cursorLayer setContents:(id)image];
+ [CATransaction commit];
+ CGImageRelease(image);
+}
+
- (void) drawRect:(NSRect) rect
{
COCOA_DEBUG("QemuCocoaView: drawRect\n");
@@ -2003,6 +2087,21 @@ static void cocoa_refresh(DisplayChangeListener *dcl)
[pool release];
}
+static void cocoa_mouse_set(DisplayChangeListener *dcl, int x, int y, bool on)
+{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [cocoaView setMouseX:x y:y on:on];
+ });
+}
+
+static void cocoa_cursor_define(DisplayChangeListener *dcl, QEMUCursor *cursor)
+{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ BQL_LOCK_GUARD();
+ [cocoaView setCursor:qemu_console_get_cursor(dcl->con)];
+ });
+}
+
static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
--
2.45.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 4/4] ui/console: Remove dpy_cursor_define_supported()
2024-07-15 5:25 [PATCH v3 0/4] ui/cocoa: Add cursor composition Akihiko Odaki
` (2 preceding siblings ...)
2024-07-15 5:25 ` [PATCH v3 3/4] ui/cocoa: Add cursor composition Akihiko Odaki
@ 2024-07-15 5:25 ` Akihiko Odaki
2024-07-16 17:55 ` [PATCH v3 0/4] ui/cocoa: Add cursor composition Philippe Mathieu-Daudé
4 siblings, 0 replies; 8+ messages in thread
From: Akihiko Odaki @ 2024-07-15 5:25 UTC (permalink / raw)
To: Paolo Bonzini, Marc-André Lureau, Daniel P. Berrangé,
Thomas Huth, Philippe Mathieu-Daudé, Peter Maydell,
Gerd Hoffmann, Dmitry Fleytman, Phil Dennis-Jordan
Cc: qemu-devel, Akihiko Odaki
Remove dpy_cursor_define_supported() as it brings no benefit today and
it has a few inherent problems.
All graphical displays except egl-headless support cursor composition
without DMA-BUF, and egl-headless is meant to be used in conjunction
with another graphical display, so dpy_cursor_define_supported()
always returns true and meaningless.
Even if we add a new display without cursor composition in the future,
dpy_cursor_define_supported() will be problematic as a cursor display
fix for it because some display devices like virtio-gpu cannot tell the
lack of cursor composition capability to the guest and are unable to
utilize the value the function returns. Therefore, all non-headless
graphical displays must actually implement cursor composition for
correct cursor display.
Another problem with dpy_cursor_define_supported() is that it returns
true even if only some of the display listeners support cursor
composition, which is wrong unless all display listeners that lack
cursor composition is headless.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Phil Dennis-Jordan <phil@philjordan.eu>
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
include/ui/console.h | 1 -
hw/display/qxl-render.c | 4 ----
hw/display/vmware_vga.c | 6 ++----
ui/console.c | 13 -------------
4 files changed, 2 insertions(+), 22 deletions(-)
diff --git a/include/ui/console.h b/include/ui/console.h
index 82b573e68082..fa986ab97e3b 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -324,7 +324,6 @@ void dpy_text_update(QemuConsole *con, int x, int y, int w, int h);
void dpy_text_resize(QemuConsole *con, int w, int h);
void dpy_mouse_set(QemuConsole *con, int x, int y, bool on);
void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor);
-bool dpy_cursor_define_supported(QemuConsole *con);
bool dpy_gfx_check_format(QemuConsole *con,
pixman_format_code_t format);
diff --git a/hw/display/qxl-render.c b/hw/display/qxl-render.c
index ec99ec887a6e..837d2446cd52 100644
--- a/hw/display/qxl-render.c
+++ b/hw/display/qxl-render.c
@@ -307,10 +307,6 @@ int qxl_render_cursor(PCIQXLDevice *qxl, QXLCommandExt *ext)
return 1;
}
- if (!dpy_cursor_define_supported(qxl->vga.con)) {
- return 0;
- }
-
if (qxl->debug > 1 && cmd->type != QXL_CURSOR_MOVE) {
fprintf(stderr, "%s", __func__);
qxl_log_cmd_cursor(qxl, cmd, ext->group_id);
diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c
index 512f224b9f58..3db3ff98f763 100644
--- a/hw/display/vmware_vga.c
+++ b/hw/display/vmware_vga.c
@@ -904,10 +904,8 @@ static uint32_t vmsvga_value_read(void *opaque, uint32_t address)
caps |= SVGA_CAP_RECT_FILL;
#endif
#ifdef HW_MOUSE_ACCEL
- if (dpy_cursor_define_supported(s->vga.con)) {
- caps |= SVGA_CAP_CURSOR | SVGA_CAP_CURSOR_BYPASS_2 |
- SVGA_CAP_CURSOR_BYPASS;
- }
+ caps |= SVGA_CAP_CURSOR | SVGA_CAP_CURSOR_BYPASS_2 |
+ SVGA_CAP_CURSOR_BYPASS;
#endif
ret = caps;
break;
diff --git a/ui/console.c b/ui/console.c
index 0ec70cb50ce6..33976446425e 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1001,19 +1001,6 @@ void dpy_cursor_define(QemuConsole *c, QEMUCursor *cursor)
}
}
-bool dpy_cursor_define_supported(QemuConsole *con)
-{
- DisplayState *s = con->ds;
- DisplayChangeListener *dcl;
-
- QLIST_FOREACH(dcl, &s->listeners, next) {
- if (dcl->ops->dpy_cursor_define) {
- return true;
- }
- }
- return false;
-}
-
QEMUGLContext dpy_gl_ctx_create(QemuConsole *con,
struct QEMUGLParams *qparams)
{
--
2.45.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3 2/4] ui/console: Convert mouse visibility parameter into bool
2024-07-15 5:25 ` [PATCH v3 2/4] ui/console: Convert mouse visibility parameter into bool Akihiko Odaki
@ 2024-07-15 6:56 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-15 6:56 UTC (permalink / raw)
To: Akihiko Odaki, Paolo Bonzini, Marc-André Lureau,
Daniel P. Berrangé, Thomas Huth, Peter Maydell,
Gerd Hoffmann, Dmitry Fleytman, Phil Dennis-Jordan
Cc: qemu-devel
On 15/7/24 07:25, Akihiko Odaki wrote:
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Tested-by: Phil Dennis-Jordan <phil@philjordan.eu>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
> include/ui/console.h | 4 ++--
> hw/display/ati.c | 2 +-
> hw/display/virtio-gpu.c | 3 +--
> hw/display/vmware_vga.c | 2 +-
> ui/console.c | 5 +++--
> ui/dbus-listener.c | 2 +-
> ui/gtk.c | 2 +-
> ui/sdl2.c | 4 ++--
> ui/spice-display.c | 11 ++++++-----
> ui/vnc.c | 2 +-
> 10 files changed, 19 insertions(+), 18 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 1/4] ui/cocoa: Release CGColorSpace
2024-07-15 5:25 ` [PATCH v3 1/4] ui/cocoa: Release CGColorSpace Akihiko Odaki
@ 2024-07-15 6:57 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-15 6:57 UTC (permalink / raw)
To: Akihiko Odaki, Paolo Bonzini, Marc-André Lureau,
Daniel P. Berrangé, Thomas Huth, Peter Maydell,
Gerd Hoffmann, Dmitry Fleytman, Phil Dennis-Jordan
Cc: qemu-devel
On 15/7/24 07:25, Akihiko Odaki wrote:
> CGImageCreate | Apple Developer Documentation
> https://developer.apple.com/documentation/coregraphics/1455149-cgimagecreate
>> The color space is retained; on return, you may safely release it.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> Tested-by: Phil Dennis-Jordan <phil@philjordan.eu>
> ---
> ui/cocoa.m | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 0/4] ui/cocoa: Add cursor composition
2024-07-15 5:25 [PATCH v3 0/4] ui/cocoa: Add cursor composition Akihiko Odaki
` (3 preceding siblings ...)
2024-07-15 5:25 ` [PATCH v3 4/4] ui/console: Remove dpy_cursor_define_supported() Akihiko Odaki
@ 2024-07-16 17:55 ` Philippe Mathieu-Daudé
4 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-16 17:55 UTC (permalink / raw)
To: Akihiko Odaki, Paolo Bonzini, Marc-André Lureau,
Daniel P. Berrangé, Thomas Huth, Peter Maydell,
Gerd Hoffmann, Dmitry Fleytman, Phil Dennis-Jordan
Cc: qemu-devel
On 15/7/24 07:25, Akihiko Odaki wrote:
> Add accelerated cursor composition to ui/cocoa. This does not only
> improve performance for display devices that exposes the capability to
> the guest according to dpy_cursor_define_supported(), but fixes the
> cursor display for devices that unconditionally expects the availability
> of the capability (e.g., virtio-gpu).
>
> The common pattern to implement accelerated cursor composition is to
> replace the cursor and warp it so that the replaced cursor is shown at
> the correct position on the guest display for relative pointer devices.
> Unfortunately, ui/cocoa cannot do the same because warping the cursor
> position interfers with the mouse input so it uses CALayer instead;
> although it is not specialized for cursor composition, it still can
> compose images with hardware acceleration.
> Akihiko Odaki (4):
> ui/cocoa: Release CGColorSpace
> ui/console: Convert mouse visibility parameter into bool
> ui/cocoa: Add cursor composition
> ui/console: Remove dpy_cursor_define_supported()
No issue with rudimentary testing, so series queued, thanks!
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-07-16 17:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-15 5:25 [PATCH v3 0/4] ui/cocoa: Add cursor composition Akihiko Odaki
2024-07-15 5:25 ` [PATCH v3 1/4] ui/cocoa: Release CGColorSpace Akihiko Odaki
2024-07-15 6:57 ` Philippe Mathieu-Daudé
2024-07-15 5:25 ` [PATCH v3 2/4] ui/console: Convert mouse visibility parameter into bool Akihiko Odaki
2024-07-15 6:56 ` Philippe Mathieu-Daudé
2024-07-15 5:25 ` [PATCH v3 3/4] ui/cocoa: Add cursor composition Akihiko Odaki
2024-07-15 5:25 ` [PATCH v3 4/4] ui/console: Remove dpy_cursor_define_supported() Akihiko Odaki
2024-07-16 17:55 ` [PATCH v3 0/4] ui/cocoa: Add cursor composition Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).