ui/cocoa: Add cursor composition
v2 cover ui/cocoa: Add cursor composition
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.
---
Changes in v2:
- Incorporated changes from:
https://lore.kernel.org/r/[email protected]
("[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/[email protected]
---
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,
Signature · 1 line
Akihiko Odaki <[email protected]>
PATCH v2 1/4 ui/cocoa: Release CGColorSpace
CGImageCreate | Apple Developer Documentation
https://developer.apple.com/documentation/coregraphics/1455149-cgimagecreate
Quoted 1 line
The color space is retained; on return, you may safely release it.
--- ui/cocoa.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
ui/cocoa.m +4 -1
@@ -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
Signature · 1 line
2.45.2
Re: [PATCH v2 1/4] ui/cocoa: Release CGColorSpace
Good catch! I hadn't spotted the existing, shipping instance of this issue.
Quoted 6 lines · Akihiko Odaki
CGImageCreate | Apple Developer Documentation
https://developer.apple.com/documentation/coregraphics/1455149-cgimagecreate
Quoted 1 line
The color space is retained; on return, you may safely release it.
Signed-off-by Akihiko Odaki <[email protected]>
PATCH v2 2/4 ui/console: Convert mouse visibility parameter into bool
In reply to Akihiko Odaki--- 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(-)
include/ui/console.h +2 -2
@@ -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,
hw/display/ati.c +1 -1
@@ -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 ; }
hw/display/virtio-gpu.c +1 -2
@@ -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 *
hw/display/vmware_vga.c +1 -1
@@ -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 ;
ui/console.c +3 -2
@@ -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;
ui/dbus-listener.c +1 -1
@@ -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);
ui/gtk.c +1 -1
@@ -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;
ui/sdl2.c +2 -2
@@ -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);
ui/spice-display.c +6 -5
@@ -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); }
ui/vnc.c +1 -1
@@ -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 ??? */ }
Signature · 1 line
2.45.2
Re: [PATCH v2 2/4] ui/console: Convert mouse visibility parameter into bool
Quoted 2 lines · Akihiko Odaki
Signed-off-by Akihiko Odaki <[email protected]>
Quoted 223 lines
--- 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(-)include/ui/console.h +2
-2@@ -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,hw/display/ati.c +1
-1@@ -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 ; }hw/display/virtio-gpu.c +1
-2@@ -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*hw/display/vmware_vga.c +1
-1@@ -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 ;ui/console.c +3
-2@@ -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;ui/dbus-listener.c +1
-1@@ -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);ui/gtk.c +1
-1@@ -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;ui/sdl2.c +2
-2@@ -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);ui/spice-display.c +1
-1@@ -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;ui/spice-display.c +2
-1@@ -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);}
ui/spice-display.c +3
-3@@ -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);}
ui/vnc.c +1
-1@@ -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
Signature · 1 line
Marc-André Lureau
Phil Dennis-Jordan
Reviewed-byRe: [PATCH v2 2/4] ui/console: Convert mouse visibility parameter into bool
Quoted 10 lines · Marc-André Lureau
Quoted 2 lines · Akihiko Odaki
Signed-off-by Akihiko Odaki <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>
PATCH v2 3/4 ui/cocoa: Add cursor composition
In reply to Akihiko OdakiAdd 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.
--- meson.build | 3 +- ui/cocoa.m | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-)
meson.build +2 -1
@@ -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'))
ui/cocoa.m +99 -0
147 lines not on this page · raw message
Signature · 1 line
2.45.2
Quoted 18 lines · Akihiko Odaki
Co-authored-by Phil Dennis-Jordan <[email protected]>Signed-off-by Akihiko Odaki <[email protected]>+- (void)setCursor:(QEMUCursor *)given_cursor
ui/cocoa.m +13
-0+{ + […] + + provider = CGDataProviderCreateWithData( + NULL, + cursor->data, + cursor->width * cursor->height * 4, + NULL + ); + + image = CGImageCreate( + cursor->width, //width + cursor->height, //height
ui/cocoa.m - (void) unhideCursor · line 502
Quoted 10 lines
ui/cocoa.m +10
-0+ 8, //bitsPerComponent + 32, //bitsPerPixel + cursor->width * 4, //bytesPerRow + colorspace, //colorspace + kCGBitmapByteOrder32Little | kCGImageAlphaFirst, //bitmapInfo + provider, //provider + NULL, //decode + 0, //interpolate + kCGRenderingIntentDefault //intent + );
I still think this is an awkward amount of boilerplate that could be outsourced to a helper function - especially as you've now reminded me in patch 1/4 that drawRect: does essentially the same thing and could probably share that helper.
I'm still keen on NSCursor support for absolute pointing mode though, so I can experiment with doing a better job of cleaning it up as part v3 of that patch series. So:
Hi Phil,
Quoted 1 line · Phil Dennis-Jordan
I'm still keen on NSCursor support for absolute pointing mode though, so I can experiment with doing a better job of cleaning it up as part v3 of that patch series.
Do we need a v3, or can you clean on top?
Regards,
Phil :)
Quoted 10 lines · Philippe Mathieu-Daudé
Hi Phil,
Quoted 3 lines · Phil Dennis-Jordan
I'm still keen on NSCursor support for absolute pointing mode though, so I can experiment with doing a better job of cleaning it up as part v3 of that patch series.
Do we need a v3, or can you clean on top?
Sorry, I meant v3 of my NSCursor patch, not this series.
https://patchew.org/QEMU/[email protected]/
(That in turn uses the CGImage for the NSCursor as well)
So from my point of view, this series can be merged, and I'll submit v3 of my series, which will aim to clean up the CGImage code as well as implementing NSCursor support in absolute pointing mode.
Thanks!
Phil
Quoted 14 lines · Phil Dennis-Jordan
On Tue, 2 Jul 2024 at 16:20, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
Hi Phil,
On 2/7/24 15:19, Phil Dennis-Jordan wrote:
> I'm still keen on NSCursor support for absolute pointing mode
though, so
> I can experiment with doing a better job of cleaning it up as
part v3 of
> that patch series.
Quoted 8 lines
Do we need a v3, or can you clean on top?
Sorry, I meant v3 of my NSCursor patch, not this series.
https://patchew.org/QEMU/[email protected]/ <https://patchew.org/QEMU/[email protected]/>
(That in turn uses the CGImage for the NSCursor as well)
Ah OK, thanks for clarifying :)
Quoted 5 lines
So from my point of view, this series can be merged, and I'll submit v3 of my series, which will aim to clean up the CGImage code as well as implementing NSCursor support in absolute pointing mode.
Thanks!
Phil
I've just tried to rebase my own patches on top of this work and noticed the following typo:
Quoted 3 lines · Akihiko Odaki
static void
cocoa_refresh(DisplayChangeListener *dcl);
+static voidcocoa_mouse_set(DisplayChangeListener *dcl, int x, int y, int on);
The above prototype does not match the below definition - note the type mismatch on the last parameter:
+static void cocoa_mouse_set(DisplayChangeListener *dcl, int x, int y, bool
Quoted 7 lines
on)
ui/cocoa.m +5
-0+{ + dispatch_async(dispatch_get_main_queue(), ^{ + [cocoaView setMouseX:x y:y on:on]; + }); +}
PATCH v2 4/4 ui/console: Remove dpy_cursor_define_supported()
In reply to Akihiko OdakiRemove 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.
--- 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(-)
include/ui/console.h +0 -1
@@ -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);
hw/display/qxl-render.c +0 -4
@@ -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);
hw/display/vmware_vga.c +2 -4
@@ -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 ;
ui/console.c +0 -13
@@ -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) {
Signature · 1 line
2.45.2
Re: [PATCH v2 4/4] ui/console: Remove dpy_cursor_define_supported()
Quoted 16 lines · 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.
Quoted 7 lines
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.Signed-off-by Akihiko Odaki <[email protected]>
Agreed,
Quoted 85 lines
--- 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(-)include/ui/console.h +0
-1@@ -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);hw/display/qxl-render.c +0
-4@@ -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);hw/display/vmware_vga.c +2
-4@@ -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;ui/console.c +0
-13@@ -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
Signature · 1 line
Marc-André Lureau
Phil Dennis-Jordan
Reviewed-byRe: [PATCH v2 4/4] ui/console: Remove dpy_cursor_define_supported()
Quoted 7 lines · Marc-André Lureau
Quoted 3 lines
Signed-off-by Akihiko Odaki <[email protected]>Agreed,
Reviewed-by Marc-André Lureau <[email protected]>
Quoted 14 lines · 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.
Quoted 2 lines
Signed-off-by Akihiko Odaki <[email protected]>
After fixing the typo in patch 3/4, the code appears to work as intended. (Tested on macOS 13 & 14, virtio-gpu with Cocoa UI.)
So, for the whole patch set: