From 98b60450f7ce6b16464392747ab8721f30add15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 2 Feb 2021 17:12:57 +0100 Subject: [PATCH] rhi: metal: Present drawables via addScheduledHandler instead of presentDrawable The former API is the recommended way to present drawables -- avoiding WindowServer submission throttling and potential issues with lock-ups when window are not serviced, are being moved to other screens, or users mistakenly call waitUntilCompleted. The scheduled block captures the drawable and retains it until the block is done executing. Change-Id: I99dca2db3bcfbea67c686dd5d97ba5011598997e Reviewed-by: Timur Pocheptsov Reviewed-by: Laszlo Agocs --- src/gui/rhi/qrhimetal.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 7151741f2e..76d16b3e50 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -1453,10 +1453,14 @@ QRhi::FrameOpResult QRhiMetal::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame Q_ASSERT(currentSwapChain == swapChainD); const bool needsPresent = !flags.testFlag(QRhi::SkipPresent); - if (needsPresent) - [swapChainD->cbWrapper.d->cb presentDrawable: swapChainD->d->curDrawable]; + if (needsPresent) { + auto drawable = swapChainD->d->curDrawable; + [swapChainD->cbWrapper.d->cb addScheduledHandler:^(id) { + [drawable present]; + }]; + } - // Must not hold on to the drawable, regardless of needsPresent. + // Must not hold on to the drawable, regardless of needsPresent [swapChainD->d->curDrawable release]; swapChainD->d->curDrawable = nil;