From nobody Sun May 5 20:12:46 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552355707709332.8058405768619; Mon, 11 Mar 2019 18:55:07 -0700 (PDT) Received: from localhost ([127.0.0.1]:43425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3Wd0-0001hO-RD for importer@patchew.org; Mon, 11 Mar 2019 21:54:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3Wc3-0001Am-PB for qemu-devel@nongnu.org; Mon, 11 Mar 2019 21:53:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3WVc-0007fC-GX for qemu-devel@nongnu.org; Mon, 11 Mar 2019 21:47:13 -0400 Received: from pv50p00im-ztdg10021801.me.com ([17.58.6.56]:37999) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h3WVc-0007du-7E for qemu-devel@nongnu.org; Mon, 11 Mar 2019 21:47:12 -0400 Received: from [172.18.2.102] (unknown [36.106.167.59]) by pv50p00im-ztdg10021801.me.com (Postfix) with ESMTPSA id 1EE023600E7; Tue, 12 Mar 2019 01:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=04042017; t=1552355229; bh=jukihZyppPcHN5u7HpS4A8WJwqoNngw1KiswHfEdIEQ=; h=From:Content-Type:Mime-Version:Subject:Message-Id:Date:To; b=YgQF1DG5AXMt69T1LT7u1JLJqciqiFDgtmDWOJmLG0X9XDyWIpO9w3DzV/t2W28J8 GVPwodap5FGMkMaFKGkg+f+o8U7YlkUyFSas80+IuG9CYxOs8OfWijLWZnmhwOHmi9 sqTuCoceSf1QWMiIk9JKj7Taf3bBPjuxNy8k8Eg7ffUQ0vi8vCy1/evJvDx8LpUWeW P5FrETwr1gazfiQOmPub4/+K+q/bC2C/GiD6C7PBxuY0uhD7is6HAvop4osJNp5W4K UePXV2fBsLAt/EwmbwUQ6D/8rQQe5NCZFghdNZzrIwtPJhR7lINcPP4AaqdD+cAMrH TukXqmbsz/7LA== Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Message-Id: Date: Tue, 12 Mar 2019 09:47:02 +0800 To: Peter Maydell , Gerd Hoffmann X-Mailer: Apple Mail (2.3445.102.3) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-12_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1812120000 definitions=main-1903120011 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 17.58.6.56 Subject: [Qemu-devel] [PATCH] ui/cocoa: Adding cursor support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Chen Zhang via Qemu-devel Reply-To: Chen Zhang Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch added cocoa_mouse_set() and cocoa_cursor_define(), supporting virtio-gpu simple rendering on macOS host. Image content, rect and visibility of the cursor buffer were added as ivars in QemuCocoaView class. Corresponding accessors were added. Note that the rect of the cursor was in coordinates of the QEMU screen, not the NSScreen or the NSView, for convenience of blending. Signed-off-by: Chen Zhang --- ui/cocoa.m | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/ui/cocoa.m b/ui/cocoa.m index 420b2411c1..8beed6e514 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -334,6 +334,9 @@ static void handleAnyDeviceErrors(Error * err) BOOL isFullscreen; BOOL isAbsoluteEnabled; BOOL isMouseDeassociated; + CGRect cursorRect; + CGImageRef cursorImage; + BOOL cursorVisible; } - (void) switchSurface:(pixman_image_t *)image; - (void) grabMouse; @@ -362,6 +365,12 @@ static void handleAnyDeviceErrors(Error * err) - (float) cdy; - (QEMUScreen) gscreen; - (void) raiseAllKeys; +- (CGRect) cursorRect; +- (void) setCursorRect:(CGRect)rect; +- (CGImageRef) cursorImage; +- (void) setCursorImage:(CGImageRef)image; +- (BOOL) isCursorVisible; +- (void) setCursorVisible:(BOOL)visible; @end =20 QemuCocoaView *cocoaView; @@ -392,6 +401,10 @@ QemuCocoaView *cocoaView; pixman_image_unref(pixman_image); } =20 + if (cursorImage) { + CGImageRelease(cursorImage); + } + [super dealloc]; } =20 @@ -479,6 +492,10 @@ QemuCocoaView *cocoaView; ); CGContextDrawImage (viewContextRef, cgrect(rectList[i]), clipI= mageRef); CGImageRelease (clipImageRef); + + } + if (cursorVisible && cursorImage && NSIntersectsRect(rect, cursorR= ect)) { + CGContextDrawImage (viewContextRef, cursorRect, cursorImage); } CGImageRelease (imageRef); } @@ -987,6 +1004,19 @@ QemuCocoaView *cocoaView; - (float) cdy {return cdy;} - (QEMUScreen) gscreen {return screen;} =20 +- (CGRect) cursorRect {return cursorRect;} +- (void) setCursorRect:(CGRect)rect {cursorRect =3D rect;} +- (CGImageRef) cursorImage {return cursorImage;} +- (void) setCursorImage:(CGImageRef)image +{ + if (cursorImage && cursorImage !=3D image) { + CGImageRelease(cursorImage); + } + cursorImage =3D image; +} +- (BOOL) isCursorVisible {return cursorVisible;} +- (void) setCursorVisible:(BOOL)visible {cursorVisible =3D visible;} + /* * Makes the target think all down keys are being released. * This prevents a stuck key problem, since we will not see @@ -1830,6 +1860,53 @@ static void cocoa_refresh(DisplayChangeListener *dcl) [pool release]; } =20 +static void cocoa_cursor_define(DisplayChangeListener *dcl, QEMUCursor *c) +{ + NSAutoreleasePool * pool =3D [[NSAutoreleasePool alloc] init]; + int bitsPerComponent =3D [cocoaView gscreen].bitsPerComponent; + int bitsPerPixel =3D [cocoaView gscreen].bitsPerPixel; + CGDataProviderRef provider =3D CGDataProviderCreateWithData(NULL, c->d= ata, c->width * 4 * c->height, NULL); + + CGImageRef img =3D CGImageCreate(c->width, c->height, + bitsPerComponent, bitsPerPixel, c->widt= h * bitsPerComponent / 2, +#ifdef __LITTLE_ENDIAN__ + CGColorSpaceCreateWithName(kCGColorSpac= eGenericRGB), //colorspace for OS X >=3D 10.4 + kCGBitmapByteOrder32Little | kCGImageAl= phaFirst, +#else + CGColorSpaceCreateDeviceRGB(), //colors= pace for OS X < 10.4 (actually ppc) + kCGImageAlphaFirst, //bitmapInfo +#endif + provider, NULL, 0, kCGRenderingIntentDe= fault); + + CGDataProviderRelease(provider); + CGFloat width =3D c->width; + CGFloat height =3D c->height; + dispatch_async(dispatch_get_main_queue(), ^{ + [cocoaView setCursorImage:img]; + CGRect rect =3D [cocoaView cursorRect]; + rect.size =3D CGSizeMake(width, height); + [cocoaView setCursorRect:rect]; + }); + [pool release]; +} +static void cocoa_mouse_set(DisplayChangeListener *dcl, + int x, int y, int visible) +{ + NSAutoreleasePool * pool =3D [[NSAutoreleasePool alloc] init]; + dispatch_async(dispatch_get_main_queue(), ^{ + QEMUScreen screen =3D [cocoaView gscreen]; + CGRect rect =3D [cocoaView cursorRect]; + // Mark old cursor rect as dirty + [cocoaView setNeedsDisplayInRect:rect]; + rect.origin =3D CGPointMake(x, screen.height - (y + rect.size.heig= ht)); + [cocoaView setCursorRect:rect]; + [cocoaView setCursorVisible:visible ? YES : NO]; + // Mark new cursor rect as dirty + [cocoaView setNeedsDisplayInRect:rect]; + }); + [pool release]; +} + static void cocoa_cleanup(void) { COCOA_DEBUG("qemu_cocoa: cocoa_cleanup\n"); @@ -1841,6 +1918,8 @@ static const DisplayChangeListenerOps dcl_ops =3D { .dpy_gfx_update =3D cocoa_update, .dpy_gfx_switch =3D cocoa_switch, .dpy_refresh =3D cocoa_refresh, + .dpy_mouse_set =3D cocoa_mouse_set, + .dpy_cursor_define =3D cocoa_cursor_define, }; =20 static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) --=20 2.19.2