Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions impeller/renderer/backend/metal/surface_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@
return IRect::MakeSize(resolve_texture_->GetSize());
}

static bool ShouldWaitForCommandBuffer() {
#if ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR)
// If a transaction is present, `presentDrawable` will present too early. And
// so we wait on an empty command buffer to get scheduled instead, which
// forces us to also wait for all of the previous command buffers in the queue
// to get scheduled.
return true;
#else
// On Physical iOS devices we still need to wait if we're taking a frame
// capture.
return [[MTLCaptureManager sharedCaptureManager] isCapturing];
#endif // ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR)
}

// |Surface|
bool SurfaceMTL::Present() const {
if (drawable_ == nil) {
Expand All @@ -179,17 +193,12 @@
}
}

#if ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR)
// If a transaction is present, `presentDrawable` will present too early. And
// so we wait on an empty command buffer to get scheduled instead, which
// forces us to also wait for all of the previous command buffers in the queue
// to get scheduled.
id<MTLCommandBuffer> command_buffer =
ContextMTL::Cast(context.get())->CreateMTLCommandBuffer();
[command_buffer commit];
[command_buffer waitUntilScheduled];
#endif // ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR)

if (ShouldWaitForCommandBuffer()) {
id<MTLCommandBuffer> command_buffer =
ContextMTL::Cast(context.get())->CreateMTLCommandBuffer();
[command_buffer commit];
[command_buffer waitUntilScheduled];
}
[drawable_ present];

return true;
Expand Down