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 <timur.pocheptsov@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
bb10
Tor Arne Vestbø 2021-02-02 17:12:57 +01:00
parent 0cba6a27e2
commit 98b60450f7
1 changed files with 7 additions and 3 deletions

View File

@ -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<MTLCommandBuffer>) {
[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;