From patchwork Sat Dec 1 12:30:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 152630 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4762437ljp; Sat, 1 Dec 2018 04:31:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/VHOo0ACMxRyCp626YVOuIAUsK2580Bt89uo1ZO12GHBp/UAMVC0msCxhdEofpJH1QzUpHR X-Received: by 2002:a63:111c:: with SMTP id g28mr7731079pgl.85.1543667463424; Sat, 01 Dec 2018 04:31:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543667463; cv=none; d=google.com; s=arc-20160816; b=pRAzH48BXE1KysODM46koH7Hp+LkXHqYdxw64GpG+Q3wBSaw18h95MogK0JZHIl6m4 EmLg7drncrr6YR2K9e89lzIFwoCKvyT3StvwL2IzpbGWfXWA95B1nfne1xTPLL8B+nRi 24g9+nleVV1xT0fFaCFfG/NLe9JiQTEwXtUxxgLFITcuV9F4mbo75MzhwI1J73uF09RR 72+msxW65c06MXZR8glkxzMCdUCAVKXTaJSgsAa2CC6HNvcAowPy+DKawtUtO1uJTHxt hWzP7M5Nn9tUk96DIFs3gKvhzKknsCyWMm6806xoAuXxyK1h/k/b3IeE2Rjmm8UgtTxu AkfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=tUCoK2+FxP7AGAVFFg2Bu5MbSW+hd5jAZdPtiktQsBw=; b=ak9uGwTzl5q9DO81lel1t4x1FKhHo1j1o+xv8jcXZkctt7ppnBu4dGRw/EBrWpaaFD pohiUKs9+uiv/hiObypiO4Jgs/2JNQ4O2IqKk0ies/grA/nseKLrCqXn5h3XMwhV8SPH yiUSCR8W0o2qmLeYpUKNDj/m+/M3iDu6QvpLT9gtjHUuWCJMSYAeb6jPLnoKqmHd7tVl VNHLGeDYKist6Nrs23C7FKZRIdmnlZNBjhXuH+kFSdo+80+2bu1FVqeFrkGrmEP3OAbZ ZHqGnmY0ME1t9Pu7Gt9jeUdwPNMkBO3XIpW8HNg/s/+4izyvQ23p5ZmRvqsfkVbSk0pe 2qIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id q8si7712758pgc.580.2018.12.01.04.31.02 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Dec 2018 04:31:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gT4QE-0008N7-FT; Sat, 01 Dec 2018 12:30:58 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, John Arbuckle , Berkus Decker , Gerd Hoffmann , Roman Bolshakov Subject: [RFC 2/5] ui/cocoa: Use the pixman image directly in switchSurface Date: Sat, 1 Dec 2018 12:30:53 +0000 Message-Id: <20181201123056.432-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181201123056.432-1-peter.maydell@linaro.org> References: <20181201123056.432-1-peter.maydell@linaro.org> MIME-Version: 1.0 Currently the switchSurface method takes a DisplaySurface. We want to change our DisplayChangeListener's dpy_gfx_switch callback to do this work asynchronously on a different thread. The caller of the switch callback will free the old DisplaySurface immediately the callback returns, so to ensure that the other thread doesn't access freed data we need to switch to using the underlying pixman image instead. The pixman image is reference counted, so we will be able to take a reference to it to avoid it vanishing too early. In this commit we only change the switchSurface method to take a pixman image, and keep the flow of control synchronous for now. Signed-off-by: Peter Maydell --- ui/cocoa.m | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) -- 2.19.2 diff --git a/ui/cocoa.m b/ui/cocoa.m index 9148ecdeb4c..997b0199c6c 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -303,7 +303,7 @@ static void handleAnyDeviceErrors(Error * err) BOOL isAbsoluteEnabled; BOOL isMouseDeassociated; } -- (void) switchSurface:(DisplaySurface *)surface; +- (void) switchSurface:(pixman_image_t *)image; - (void) grabMouse; - (void) ungrabMouse; - (void) toggleFullScreen:(id)sender; @@ -478,12 +478,13 @@ QemuCocoaView *cocoaView; } } -- (void) switchSurface:(DisplaySurface *)surface +- (void) switchSurface:(pixman_image_t *)image { COCOA_DEBUG("QemuCocoaView: switchSurface\n"); - int w = surface_width(surface); - int h = surface_height(surface); + int w = pixman_image_get_width(image); + int h = pixman_image_get_height(image); + pixman_format_code_t image_format = pixman_image_get_format(image); /* cdx == 0 means this is our very first surface, in which case we need * to recalculate the content dimensions even if it happens to be the size * of the initial empty window. @@ -505,10 +506,10 @@ QemuCocoaView *cocoaView; CGDataProviderRelease(dataProviderRef); //sync host window color space with guests - screen.bitsPerPixel = surface_bits_per_pixel(surface); - screen.bitsPerComponent = surface_bytes_per_pixel(surface) * 2; + screen.bitsPerPixel = PIXMAN_FORMAT_BPP(image_format); + screen.bitsPerComponent = DIV_ROUND_UP(screen.bitsPerPixel, 8) * 2; - dataProviderRef = CGDataProviderCreateWithData(NULL, surface_data(surface), w * 4 * h, NULL); + dataProviderRef = CGDataProviderCreateWithData(NULL, pixman_image_get_data(image), w * 4 * h, NULL); // update windows if (isFullscreen) { @@ -1608,7 +1609,7 @@ static void cocoa_switch(DisplayChangeListener *dcl, NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; COCOA_DEBUG("qemu_cocoa: cocoa_switch\n"); - [cocoaView switchSurface:surface]; + [cocoaView switchSurface:surface->image]; [pool release]; }