From patchwork Thu Feb 14 10:28:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 158342 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1175172jaa; Thu, 14 Feb 2019 02:28:19 -0800 (PST) X-Received: by 2002:adf:9d14:: with SMTP id k20mr2120246wre.97.1550140099229; Thu, 14 Feb 2019 02:28:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550140099; cv=none; d=google.com; s=arc-20160816; b=ZEB7s0F2/Ztl5HQ8HhjHz5G45Eb1blw+PRmUIJtNuQ9sfcVmo0DDg74c/8t8aA7G4u FeiU82OWuNuEQQLRQT9bwD85AV4ZeUOdUFU1l/nNlleW4km9gIe65j6qT4EcIupAQHKp /cY5uK8Et1vBDU02VNWMcYefct1+cKKDBkrLMsZkHCHmuIs0Yh6vpj51YIJEptfPmPvj O/sgNEsmi7+PXdhvXb/3vx8Wr29Yn42+2qy0u4Vx97qGLmXmf3+0EA9k0WOhfoGl75hT skOCI9stg2sicUWIVb95xn+APJqF5LMOODgFZjjb4JUnxOXRWXMpJRXRtKKX5Atak2n+ boYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=TU4Mr6IyF0B8jGRbPFWp4Ynak74+AR7Z2hPstZlGhWI=; b=ouztMxkA6VL1lAoQ9k1bFIiGDMJsiEDCzUvy2Hr/MMiVFk+Jy1Ai1+4qim17DWTB6s RB/us4YBSOaGxmUyVDavUfPl//VkCQRoqpEUvHgtY3PwZI86YpChhkTkw8+7+bCDVU6j 8H+llu8m0Dxb6tQkl2vwABonNVmaGYwW/2jJOzcTtJTJZ+kVLLci3v3VMkOrgQK6SAEC 1nFHP4CA3dICu3YIScLmpgGyh/XDTaEDSVVBcq3DlPXY8o1G4zfgNs3ydQsqDyUKSVPp hQAmdDkCb5F7ODPKh/JtOaIqpbWr2x6DRIKTrp7JjFDB/sUEzFQuEUqZs6RkuE8/LUEr gMow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZiD4Qdj4; 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 v18sor1354370wrd.4.2019.02.14.02.28.19 for (Google Transport Security); Thu, 14 Feb 2019 02:28:19 -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=ZiD4Qdj4; 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:mime-version :content-transfer-encoding; bh=TU4Mr6IyF0B8jGRbPFWp4Ynak74+AR7Z2hPstZlGhWI=; b=ZiD4Qdj4JnS1/IS664EmguUys8iReFmRG1QCawT8+Xs0THt5c6kgvNux73Wn/gmgu3 4/zROf97VpuvZJOU49XaLEiZ0sff7BR6L6dwlcq0jvT9AJifDe0PHPOlkJDlyT1/hVjU ZBjMlcNu4VtGf0yQSxzo2Dhun68+5wVpj7TYO7AWFniECAjQvU8Zn2Wi4TUbhn1aME+B GPPPgDi8rfIKKZ3eqw33Og5nLcQsw1f/W+oxdcBLlHohkJxNa7kc0HQZyILy6v1tEEQB PoacSsyPWwfxhP/c9IZmeo2V5lbtUREHGgyv8waPxVlxU8zn+leqgcobNVG2FH4KIG8L Brow== 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:mime-version :content-transfer-encoding; bh=TU4Mr6IyF0B8jGRbPFWp4Ynak74+AR7Z2hPstZlGhWI=; b=uQqzUOCA5nMvIpt7yT5WTzF/2WCwl3GeofRHxzrSl6HxfDig9tzTeo8RGpxIua6QtI ixXBX4Mva5xo2VTvREiNK35HFz0cNJv92ynI+ByQe1vK4UKiyDMrtOAMXv6mp0pm73F3 7T4Ei3NQC/QS1pyepXvBedzdJpIF/pOSHgC1B1g3VpBMlc508M9YKffgkpHV4id7XBsR OjR95PEi7LX+GQ9K+59xyIicUJBhVEfchcCZ2kv+r+eutcAnnduIcM4BxblBH0aECtxT Q7OhYZxIGc51tnoT0ToCH89lFFYXQQRjlywiaVKVQzEcNly7v6k2lesO+fjf5KbdkVkZ rfMQ== X-Gm-Message-State: AHQUAuY/SyTyP8Aqv9ul04YyVqd3cDMELII/8fk4pYcE3Z54MiRXlccq e3jMuedyNqIIscw4rKAEBqhgR/Bh X-Google-Smtp-Source: AHgI3IZf1mayEazw2RASEFb4ZN50h/7usOAxEau41bY8kQ1rKlD14QFj3kvlio8mzoGOwzBuELvGpQ== X-Received: by 2002:adf:ecc7:: with SMTP id s7mr2162354wro.255.1550140098663; Thu, 14 Feb 2019 02:28:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 02:28:17 -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 0/7] ui/cocoa: Use OSX's main loop Date: Thu, 14 Feb 2019 10:28:09 +0000 Message-Id: <20190214102816.3393-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 This set of patches rearranges how we handle events on the OSX Cocoa UI so that we use the main thread to run the OSX event loop, and we don't do a long blocking operation from the applicationDidFinishLaunching callback. Instead we create a second thread which runs qemu_main() and becomes the QEMU main-loop thread. The callbacks from QEMU into the cocoa code asynchronously dispatch their work to the main thread, and the main thread takes the iothread lock before calling into QEMU code. NB: the code to asynchronously run code blocks on the main thread uses dispatch_get_main_queue(), which is a 10.10-or-later function. I think the benefit in clarity-of-code is a worthwhile gain for dropping support for ancient OSX versions. The change from v1 is that we actually wire up input events from OSX to the handleEvent method. There are a couple of plausible ways we could do this: * most OSX apps do this by implementing event handling methods on their NSView. This won't work for us, because these only get called after OSX has dealt with some events like menu bar accelerator keystrokes, and we would like to send those to the guest instead in some situations. * we could use addLocalMonitorForEventsMatchingMask to add a "local event monitor", which gets to examine/filter events before the usual OSX event processing. I think this would work, but it's not what I chose * we can subclass NSApplication and implement a custom sendEvent method in our subclass. This gets all events first and can either handle them or call the superclass sendEvent to hand them to OSX as usual. This is what I ended up going for. * It is also possible to implement sendEvent on NSWindow, but I think this has the "only called after OSX has done menu keystroke processing" issue. I've tested this a bit better than the v1 RFC, and it seems to work OK for me. Patchset structure: * patch 1 does the "make sure we have the iothread lock for calls into QEMU" (which is effectively a no-op initially since we'll already be holding that lock when our refresh etc callbacks are called) * patch 2 makes switchSurface directly take the pixman image (which is refcounted) rather than the DisplaySurface (which is not), so we can make the calls to it asynchronous later * patches 3 and 4 are just trivial code motion * patch 5 (new in v2) restructures handleEvent so it doesn't directly call sendEvent but instead returns a flag indicating whether it consumed the event or not * patch 6 (new in v2) subclasses NSApplication * patch 7 (the old patch 5) does the bulk of the work (and can't really be split further without the UI being broken at the intermediate point) thanks -- PMM Peter Maydell (7): ui/cocoa: Ensure we have the iothread lock when calling into QEMU ui/cocoa: Use the pixman image directly in switchSurface ui/cocoa: Factor out initial menu creation ui/cocoa: Move console/device menu creation code up in file ui/cocoa: Don't call NSApp sendEvent directly from handleEvent ui/cocoa: Subclass NSApplication so we can implement sendEvent ui/cocoa: Perform UI operations only on the main thread ui/cocoa.m | 483 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 294 insertions(+), 189 deletions(-) -- 2.17.2 (Apple Git-113)