From patchwork Thu Feb 14 10:28:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 158344 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1175218jaa; Thu, 14 Feb 2019 02:28:21 -0800 (PST) X-Received: by 2002:a7b:cc86:: with SMTP id p6mr2072249wma.32.1550140101797; Thu, 14 Feb 2019 02:28:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550140101; cv=none; d=google.com; s=arc-20160816; b=ONR586y+un2H3TG+5FT3CH1jER+GNGQUOnq5f12pFGzGPGtm2eSSNCGKm0hUBdsHAt CiM+sFAW/uM8wgckwQLyNTcVzzJRWSzvGtWvvbxTpoCCLayl/Zxh0gfNXMlbpjGNRngM xAT+Q3FaFfwqmkJpYh4IxvOaiZfpcdG3Rh/SaID2nuQRmWh9VIZyucYM77MT2pcBt4X0 ekd8PQaQKX1mlQv59QDcjGQsA2YK9dFcqIavr9yyD6RmIxXPQ8D/1OD44fi95uzY5Lb/ CD16XkGgPJ3VmTy+8p+ViMmNiL+zmJZptlxSDUo4h2i1DktuS64H8WZ+By7yxlD7tQ/0 1RgA== 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:dkim-signature; bh=tP5QNALKs/J9psBFnzNNUZlZbCP3Vurs9RTkFSAFnGA=; b=FnPNcwquO3Boq5jmci31YJgD2ti8A8imhg0TvhkAjJVlgY+HtdrfmlcM9tj6EqOpsT z/HsCRaQ2Q4yM50W/d+ccRnEJf/WR//r/u6x7tY+efxPM66nuen36RZckZuVgatk0T/+ OM0Ady0HUNPe6JkOh8yHbqkBU6NfRgk00nQyg5XrVaF5QPFb2HiVJ+MrRU+coQwov7TQ 4XUgJBEopVMOr/1ZZ679lD1jdFivdZMAkRjgihYfqJghlyqmC93cdx66ZW66sb2pSoM4 s18vH3jnbsqPrkGIiwlF9zIPg5nCcRimZabSLpO8jHXydWltPb+Hqml8W/GDNmTf9GUf vOWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=brJjVgnW; spf=pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b138sor1321533wmd.8.2019.02.14.02.28.21 for (Google Transport Security); Thu, 14 Feb 2019 02:28:21 -0800 (PST) Received-SPF: pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=brJjVgnW; spf=pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tP5QNALKs/J9psBFnzNNUZlZbCP3Vurs9RTkFSAFnGA=; b=brJjVgnW5v+jdufW6tWlOsaYPt0RO2mAKquLbcKC70Br66sXWVIroMrDd8HgJ1vEAn 668m7yo67xy8BPC7F5qSqTNGp8Tn+AQtvLhhPrYw3bEvwHwNpaF9DLoAEZAjKZesgxxZ bHp892rX+B+ZWtsIDCSPgtqfW8FAGjN3uUd5/buXomEAQLS+FrC8SL99+XufJa4FzGk9 7wZzmHbZC1cRl/PfAMW2NmTGDhXS1JyakTAUhvtMQtdHXrhGgKV8I6A7XUuCMW865424 KS2YjETh24/6TWCJh9cfmAtr/3BsyZ/W5R5HrLcSqW75Tlmkg1I6pzUOC2fU0vLx/UGv h2yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tP5QNALKs/J9psBFnzNNUZlZbCP3Vurs9RTkFSAFnGA=; b=QKMN1tCkwQ4znmjPv0aBTjcxSQV/BYVbmMc909fQZ+uu5ZhbNxDm2ydijD1jWIxX0Y 3uuzNkq6SRgzQ2hyE736KTJqurWOjyQxZQALqaDPjIz48Pu2leFZ1W/cLCBwSSvpYtpH caIrAVkn254aeq4s6HTC0ETWES5lCAWhy8d7sQKmlPUzoX+Jxnmv/1+XUiO7XUvJlziC 9qmaf054Ptv7jKK4NQi1owi2OclKW7LHMCgOLCzD41WBSQsBhw+6bF8AAU+XD2IX37Mw TfHbIZFuMdPxK7OFMx10sncGcXBJwsGKg2MBE+n/kIO0kFNhx6kgerlfKoTn5IlI7eK+ Jo6A== X-Gm-Message-State: AHQUAuYgjuUsckFLFEIJtnqioO7KNfSrgdkiOS7uhak4LYOAjzTKfR4h +3/sJZiIy2tqjvb+t6kjS0H2iolW X-Google-Smtp-Source: AHgI3IbSf4S0P9nY4OFmeU/s5IRm6Ul93I/cyyHrzzFsTQoMVOQZQDSB1O7eqrO888bVRi8kbROxvw== X-Received: by 2002:a1c:a185:: with SMTP id k127mr2100127wme.134.1550140101371; Thu, 14 Feb 2019 02:28:21 -0800 (PST) Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id o5sm6473817wrh.34.2019.02.14.02.28.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 02:28:20 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, John Arbuckle , Roman Bolshakov , Berkus Decker , Gerd Hoffmann , Ben Hekster , BALATON Zoltan Subject: [PATCH v2 2/7] ui/cocoa: Use the pixman image directly in switchSurface Date: Thu, 14 Feb 2019 10:28:11 +0000 Message-Id: <20190214102816.3393-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214102816.3393-1-peter.maydell@linaro.org> References: <20190214102816.3393-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.17.2 (Apple Git-113) Reviewed-by: BALATON Zoltan Reviewed-by: Roman Bolshakov Tested-by: Roman Bolshakov diff --git a/ui/cocoa.m b/ui/cocoa.m index 2931c751fd..9d23732ff9 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -315,7 +315,7 @@ @interface QemuCocoaView : NSView BOOL isAbsoluteEnabled; BOOL isMouseDeassociated; } -- (void) switchSurface:(DisplaySurface *)surface; +- (void) switchSurface:(pixman_image_t *)image; - (void) grabMouse; - (void) ungrabMouse; - (void) toggleFullScreen:(id)sender; @@ -495,12 +495,13 @@ - (void) setContentDimensions } } -- (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. @@ -522,10 +523,10 @@ - (void) switchSurface:(DisplaySurface *)surface 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) { @@ -1625,7 +1626,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]; }